Commit d95bc83c authored by Kevin Atkinson's avatar Kevin Atkinson

merkeldag: change SetPrefix param to a pointer and reset the prefix on nil

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent f8a265e7
...@@ -53,10 +53,17 @@ func PrefixForCidVersion(version int) (cid.Prefix, error) { ...@@ -53,10 +53,17 @@ func PrefixForCidVersion(version int) (cid.Prefix, error) {
} }
} }
func (n *ProtoNode) SetPrefix(prefix cid.Prefix) { // SetPrefix sets the prefix if it is non nil, if prefix is nil then
n.Prefix = prefix // it resets it the default value
n.encoded = nil func (n *ProtoNode) SetPrefix(prefix *cid.Prefix) {
n.cached = nil if prefix == nil {
n.Prefix = v0CidPrefix
} else {
n.Prefix = *prefix
n.Prefix.Codec = cid.DagProtobuf
n.encoded = nil
n.cached = nil
}
} }
type LinkSlice []*node.Link type LinkSlice []*node.Link
...@@ -287,7 +294,7 @@ func (n *ProtoNode) Cid() *cid.Cid { ...@@ -287,7 +294,7 @@ func (n *ProtoNode) Cid() *cid.Cid {
} }
if n.Prefix.Codec == 0 { if n.Prefix.Codec == 0 {
n.Prefix = v0CidPrefix n.SetPrefix(nil)
} }
c, err := n.Prefix.Sum(n.RawData()) c, err := n.Prefix.Sum(n.RawData())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment