File tree 1 file changed +4
-18
lines changed
1 file changed +4
-18
lines changed Original file line number Diff line number Diff line change @@ -406,19 +406,12 @@ func (n *ProtoNode) MarshalJSON() ([]byte, error) {
406
406
// Cid returns the node's Cid, calculated according to its prefix
407
407
// and raw data contents.
408
408
func (n * ProtoNode ) Cid () cid.Cid {
409
- if n .encoded != nil && n .cached .Defined () {
410
- return n .cached
411
- }
412
-
413
- c , err := n .CidBuilder ().Sum (n .RawData ())
414
- if err != nil {
415
- // programmer error
416
- err = fmt .Errorf ("invalid CID of length %d: %x: %v" , len (n .RawData ()), n .RawData (), err )
409
+ // re-encode if necessary and we'll get a new cached CID
410
+ if _ , err := n .EncodeProtobuf (false ); err != nil {
417
411
panic (err )
418
412
}
419
413
420
- n .cached = c
421
- return c
414
+ return n .cached
422
415
}
423
416
424
417
// String prints the node's Cid.
@@ -428,14 +421,7 @@ func (n *ProtoNode) String() string {
428
421
429
422
// Multihash hashes the encoded data of this node.
430
423
func (n * ProtoNode ) Multihash () mh.Multihash {
431
- // NOTE: EncodeProtobuf generates the hash and puts it in n.cached.
432
- _ , err := n .EncodeProtobuf (false )
433
- if err != nil {
434
- // Note: no possibility exists for an error to be returned through here
435
- panic (err )
436
- }
437
-
438
- return n .cached .Hash ()
424
+ return n .Cid ().Hash ()
439
425
}
440
426
441
427
// Links returns a copy of the node's links.
You can’t perform that action at this time.
0 commit comments