From c97f4def55643ba82b64305f790455b3fe5f5064 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 15 Jun 2026 10:45:49 +0100 Subject: [PATCH] fix: add space to allocate and accept args --- commands/blob/cbor_gen.go | 57 ++++++++++++++++++++++++++++++++++++--- commands/blob/json_gen.go | 55 +++++++++++++++++++++++++++++++++++++ commands/blob/types.go | 7 +++-- 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/commands/blob/cbor_gen.go b/commands/blob/cbor_gen.go index 95bd7b6..b9e4a28 100644 --- a/commands/blob/cbor_gen.go +++ b/commands/blob/cbor_gen.go @@ -29,7 +29,7 @@ func (t *AllocateArguments) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{162}); err != nil { + if _, err := cw.Write([]byte{163}); err != nil { return err } @@ -65,6 +65,21 @@ func (t *AllocateArguments) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("failed to write cid field t.Cause: %w", err) } + // t.Space (did.DID) (struct) + if len("space") > 8192 { + return xerrors.Errorf("Value in field \"space\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("space"))); err != nil { + return err + } + if _, err := cw.WriteString(string("space")); err != nil { + return err + } + + if err := t.Space.MarshalCBOR(cw); err != nil { + return err + } return nil } @@ -132,6 +147,16 @@ func (t *AllocateArguments) UnmarshalCBOR(r io.Reader) (err error) { t.Cause = c } + // t.Space (did.DID) (struct) + case "space": + + { + + if err := t.Space.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Space: %w", err) + } + + } default: // Field doesn't exist on this type, so ignore it @@ -673,7 +698,7 @@ func (t *AcceptArguments) MarshalCBOR(w io.Writer) error { cw := cbg.NewCborWriter(w) - if _, err := cw.Write([]byte{162}); err != nil { + if _, err := cw.Write([]byte{163}); err != nil { return err } @@ -708,6 +733,22 @@ func (t *AcceptArguments) MarshalCBOR(w io.Writer) error { if err := t.Blob.MarshalCBOR(cw); err != nil { return err } + + // t.Space (did.DID) (struct) + if len("space") > 8192 { + return xerrors.Errorf("Value in field \"space\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("space"))); err != nil { + return err + } + if _, err := cw.WriteString(string("space")); err != nil { + return err + } + + if err := t.Space.MarshalCBOR(cw); err != nil { + return err + } return nil } @@ -736,7 +777,7 @@ func (t *AcceptArguments) UnmarshalCBOR(r io.Reader) (err error) { n := extra - nameBuf := make([]byte, 4) + nameBuf := make([]byte, 5) for i := uint64(0); i < n; i++ { nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) if err != nil { @@ -772,6 +813,16 @@ func (t *AcceptArguments) UnmarshalCBOR(r io.Reader) (err error) { } } + // t.Space (did.DID) (struct) + case "space": + + { + + if err := t.Space.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Space: %w", err) + } + + } default: // Field doesn't exist on this type, so ignore it diff --git a/commands/blob/json_gen.go b/commands/blob/json_gen.go index 6535c6f..72f003b 100644 --- a/commands/blob/json_gen.go +++ b/commands/blob/json_gen.go @@ -67,6 +67,26 @@ func (t *AllocateArguments) MarshalDagJSON(w io.Writer) error { return fmt.Errorf("writing CID for field t.Cause: %w", err) } + written++ + if written > 0 { + if err := jw.WriteComma(); err != nil { + return err + } + } + + // t.Space (did.DID) (struct) + if len("space") > 8192 { + return fmt.Errorf("string in field \"space\" was too long") + } + if err := jw.WriteString(string("space")); err != nil { + return fmt.Errorf("writing string for field \"space\": %w", err) + } + if err := jw.WriteObjectColon(); err != nil { + return err + } + if err := t.Space.MarshalDagJSON(jw); err != nil { + return fmt.Errorf("marshaling field t.Space: %w", err) + } written++ if err := jw.WriteObjectClose(); err != nil { return err @@ -125,6 +145,14 @@ func (t *AllocateArguments) UnmarshalDagJSON(r io.Reader) (err error) { t.Cause = c } + + // t.Space (did.DID) (struct) + case "space": + + if err := t.Space.UnmarshalDagJSON(jr); err != nil { + return fmt.Errorf("unmarshaling t.Space: %w", err) + } + default: // Field doesn't exist on this type, so ignore it if err := jr.DiscardType(); err != nil { @@ -714,6 +742,26 @@ func (t *AcceptArguments) MarshalDagJSON(w io.Writer) error { return fmt.Errorf("marshaling field t.Blob: %w", err) } written++ + if written > 0 { + if err := jw.WriteComma(); err != nil { + return err + } + } + + // t.Space (did.DID) (struct) + if len("space") > 8192 { + return fmt.Errorf("string in field \"space\" was too long") + } + if err := jw.WriteString(string("space")); err != nil { + return fmt.Errorf("writing string for field \"space\": %w", err) + } + if err := jw.WriteObjectColon(); err != nil { + return err + } + if err := t.Space.MarshalDagJSON(jw); err != nil { + return fmt.Errorf("marshaling field t.Space: %w", err) + } + written++ if err := jw.WriteObjectClose(); err != nil { return err } @@ -767,6 +815,13 @@ func (t *AcceptArguments) UnmarshalDagJSON(r io.Reader) (err error) { return fmt.Errorf("unmarshaling t.Blob: %w", err) } + // t.Space (did.DID) (struct) + case "space": + + if err := t.Space.UnmarshalDagJSON(jr); err != nil { + return fmt.Errorf("unmarshaling t.Space: %w", err) + } + default: // Field doesn't exist on this type, so ignore it if err := jr.DiscardType(); err != nil { diff --git a/commands/blob/types.go b/commands/blob/types.go index cbb8be5..f9cc290 100644 --- a/commands/blob/types.go +++ b/commands/blob/types.go @@ -2,6 +2,7 @@ package blob import ( "github.com/fil-forge/libforge/commands" + "github.com/fil-forge/ucantone/did" "github.com/fil-forge/ucantone/ucan/promise" "github.com/ipfs/go-cid" "github.com/multiformats/go-multihash" @@ -23,8 +24,9 @@ type AddOK struct { } type AcceptArguments struct { - Blob Blob `cborgen:"blob" dagjsongen:"blob"` - Put promise.AwaitOK `cborgen:"_put" dagjsongen:"_put"` + Space did.DID `cborgen:"space" dagjsongen:"space"` + Blob Blob `cborgen:"blob" dagjsongen:"blob"` + Put promise.AwaitOK `cborgen:"_put" dagjsongen:"_put"` } type AcceptOK struct { @@ -35,6 +37,7 @@ type AcceptOK struct { } type AllocateArguments struct { + Space did.DID `cborgen:"space" dagjsongen:"space"` Blob Blob `cborgen:"blob" dagjsongen:"blob"` Cause cid.Cid `cborgen:"cause" dagjsongen:"cause"` }