-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
242 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
package doc | ||
|
||
import ( | ||
"fmt" | ||
|
||
cbor "github.com/ipfs/go-ipld-cbor" | ||
"github.com/ipfs/go-cid" | ||
ipldcbor "github.com/ipfs/go-ipld-cbor" | ||
format "github.com/ipfs/go-ipld-format" | ||
mc "github.com/multiformats/go-multicodec" | ||
mh "github.com/multiformats/go-multihash" | ||
) | ||
|
||
// IPFSDagAddCBOR takes a CBOR encoded byte array and adds it to IPFS. | ||
func (d *Document) Node() (*cbor.Node, error) { | ||
func (d *Document) Node() (format.Node, cid.Cid, error) { | ||
|
||
dCBOR, err := d.MarshalToCBOR() | ||
// Hash the CBOR data to create a CID | ||
data, err := d.MarshalToCBOR() | ||
if err != nil { | ||
return nil, fmt.Errorf("doc/Node: failed to marshal document to CBOR: %w", err) | ||
return nil, cid.Cid{}, err | ||
} | ||
|
||
n, err := cbor.WrapObject(dCBOR, mh.SHA2_256, -1) | ||
hash, err := mh.Sum(data, mh.SHA2_256, -1) | ||
if err != nil { | ||
return nil, cid.Cid{}, err | ||
} | ||
|
||
// Create a CID with the DagCBOR codec | ||
codecType := uint64(mc.DagCbor) | ||
c := cid.NewCidV1(codecType, hash) | ||
|
||
// Use go-ipld-cbor to decode the CBOR data into an IPLD node | ||
node, err := ipldcbor.Decode(data, mh.SHA2_256, -1) | ||
if err != nil { | ||
return nil, fmt.Errorf("doc/Node: failed to wrap object: %w", err) | ||
return nil, cid.Cid{}, err | ||
} | ||
|
||
return n, nil | ||
return node, c, nil | ||
} |
Oops, something went wrong.