Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
e5a1a075
Commit
e5a1a075
authored
Nov 29, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merkledag: retain cid types when roundtripping through a ProtoNode
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
119ca42b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
2 deletions
+17
-2
coding.go
coding.go
+13
-2
merkledag.go
merkledag.go
+1
-0
node.go
node.go
+3
-0
No files found.
coding.go
View file @
e5a1a075
...
...
@@ -7,7 +7,7 @@ import (
pb
"github.com/ipfs/go-ipfs/merkledag/pb"
node
"gx/ipfs/QmRSU5EqqWVZSNdbU51yXmVoF1uNw3JgTNB6RaiL7DZM16/go-ipld-node"
u
"gx/ipfs/Qm
b912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util
"
mh
"gx/ipfs/Qm
YDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash
"
cid
"gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
)
...
...
@@ -84,7 +84,18 @@ func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
}
if
n
.
cached
==
nil
{
n
.
cached
=
cid
.
NewCidV0
(
u
.
Hash
(
n
.
encoded
))
if
n
.
prefix
.
MhType
==
0
{
// unset
n
.
prefix
.
Codec
=
cid
.
DagProtobuf
n
.
prefix
.
MhLength
=
-
1
n
.
prefix
.
MhType
=
mh
.
SHA2_256
n
.
prefix
.
Version
=
0
}
c
,
err
:=
n
.
prefix
.
Sum
(
n
.
encoded
)
if
err
!=
nil
{
return
nil
,
err
}
n
.
cached
=
c
}
return
n
.
encoded
,
nil
...
...
merkledag.go
View file @
e5a1a075
...
...
@@ -103,6 +103,7 @@ func decodeBlock(b blocks.Block) (node.Node, error) {
}
decnd
.
cached
=
b
.
Cid
()
decnd
.
prefix
=
b
.
Cid
()
.
Prefix
()
return
decnd
,
nil
case
cid
.
Raw
:
return
NewRawNode
(
b
.
RawData
()),
nil
...
...
node.go
View file @
e5a1a075
...
...
@@ -22,6 +22,9 @@ type ProtoNode struct {
encoded
[]
byte
cached
*
cid
.
Cid
// prefix specifies cid version and hashing function
prefix
cid
.
Prefix
}
type
LinkSlice
[]
*
node
.
Link
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment