Skip to content

Commit 8ca9196

Browse files
committed
Fix optional field handling in IPLD typed representation
1 parent 53330aa commit 8ca9196

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

federation/federation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (f *Federation) snapshot(ctx context.Context, t time.Time) error {
139139
newSnapshot.Providers.Put(key, value)
140140
}
141141

142-
node := bindnode.Wrap(newSnapshot, Prototypes.Snapshot.Type())
142+
node := bindnode.Wrap(newSnapshot, Prototypes.Snapshot.Type()).Representation()
143143
headSnapshotLink, err := f.linkSystem.Store(ipld.LinkContext{Ctx: ctx}, Prototypes.link, node)
144144
if err != nil {
145145
f.vc.untick(f.host.ID())
@@ -186,7 +186,7 @@ func (f *Federation) getHeadNode(ctx context.Context) (ipld.Node, error) {
186186
logger.Errorw("Failed to sign head", "err", err)
187187
return nil, err
188188
}
189-
f.headNodeCache = bindnode.Wrap(head, Prototypes.Head.Type())
189+
f.headNodeCache = bindnode.Wrap(head, Prototypes.Head.Type()).Representation()
190190
return f.headNodeCache, nil
191191
}
192192

federation/federation_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ func TestFederationStandalone(t *testing.T) {
122122
if recorder.Code != http.StatusOK {
123123
return false
124124
}
125-
t.Log(recorder.Body.String())
126125
builder := federation.Prototypes.Head.NewBuilder()
127126
err := dagjson.Decode(builder, recorder.Body)
128127
if err != nil {

federation/handlers.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/ipld/go-ipld-prime/codec/dagjson"
1212
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1313
"github.com/ipld/go-ipld-prime/multicodec"
14-
"github.com/ipld/go-ipld-prime/node/basicnode"
14+
"github.com/ipld/go-ipld-prime/schema"
1515
)
1616

1717
func (f *Federation) handleV1FedHead(w http.ResponseWriter, r *http.Request) {
@@ -58,7 +58,7 @@ func (f *Federation) handleV1FedSubtree(w http.ResponseWriter, r *http.Request)
5858

5959
ctx := ipld.LinkContext{Ctx: r.Context()}
6060
lnk := cidlink.Link{Cid: c}
61-
node, err := f.linkSystem.Load(ctx, lnk, basicnode.Prototype.Any)
61+
node, err := f.linkSystem.Load(ctx, lnk, Prototypes.Snapshot)
6262
if err != nil {
6363
if errors.Is(err, datastore.ErrNotFound) || errors.Is(err, ipld.ErrNotExists{}) {
6464
http.Error(w, "", http.StatusNotFound)
@@ -68,7 +68,7 @@ func (f *Federation) handleV1FedSubtree(w http.ResponseWriter, r *http.Request)
6868
http.Error(w, "", http.StatusInternalServerError)
6969
return
7070
}
71-
if err := encoder(node, w); err != nil {
71+
if err := encoder(node.(schema.TypedNode).Representation(), w); err != nil {
7272
logger.Errorw("Failed to encode node", "err", err)
7373
}
7474
}

0 commit comments

Comments
 (0)