File tree 1 file changed +22
-5
lines changed 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -518,12 +518,29 @@ func (c Cid) Loggable() map[string]interface{} {
518
518
519
519
// Prefix builds and returns a Prefix out of a Cid.
520
520
func (c Cid ) Prefix () Prefix {
521
- dec , _ := mh .Decode (c .Hash ()) // assuming we got a valid multiaddr, this will not error
521
+ if c .Version () == 0 {
522
+ return Prefix {
523
+ MhType : mh .SHA2_256 ,
524
+ MhLength : 32 ,
525
+ Version : 0 ,
526
+ Codec : DagProtobuf ,
527
+ }
528
+ }
529
+
530
+ offset := 0
531
+ version , n , _ := uvarint (c .str [offset :])
532
+ offset += n
533
+ codec , n , _ := uvarint (c .str [offset :])
534
+ offset += n
535
+ mhtype , n , _ := uvarint (c .str [offset :])
536
+ offset += n
537
+ mhlen , _ , _ := uvarint (c .str [offset :])
538
+
522
539
return Prefix {
523
- MhType : dec . Code ,
524
- MhLength : dec . Length ,
525
- Version : c . Version () ,
526
- Codec : c . Type () ,
540
+ MhType : mhtype ,
541
+ MhLength : int ( mhlen ) ,
542
+ Version : version ,
543
+ Codec : codec ,
527
544
}
528
545
}
529
546
You can’t perform that action at this time.
0 commit comments