Browse Source

Fix getRoot

Signed-off-by: p4u <p4u@dabax.net>
feature_chain_module
p4u 5 years ago
parent
commit
b8dccadfaa
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      tree/tree.go

+ 7
- 3
tree/tree.go

@ -101,7 +101,7 @@ func (t *Tree) CheckProof(data []byte, mpHex string) (bool, error) {
} }
func (t *Tree) GetRoot() string { func (t *Tree) GetRoot() string {
return t.Tree.RootKey().String()
return common3.HexEncode(t.Tree.RootKey().Bytes())
} }
func (t *Tree) GetIndex(data []byte) (string, error) { func (t *Tree) GetIndex(data []byte) (string, error) {
@ -126,9 +126,13 @@ func (t *Tree) Dump() ([]string, error) {
func (t *Tree) Snapshot(root string) (*Tree, error) { func (t *Tree) Snapshot(root string) (*Tree, error) {
var rootHash merkletree.Hash var rootHash merkletree.Hash
copy(rootHash[:32], root)
mt, err := t.Tree.Snapshot(&rootHash)
snapshotTree := new(Tree) snapshotTree := new(Tree)
rootBytes, err := common3.HexDecode(root)
if err != nil {
return snapshotTree, err
}
copy(rootHash[:32], rootBytes)
mt, err := t.Tree.Snapshot(&rootHash)
snapshotTree.Tree = mt snapshotTree.Tree = mt
return snapshotTree, err return snapshotTree, err
} }

Loading…
Cancel
Save