Browse Source

Fix dump function

feature_chain_module
p4u 5 years ago
parent
commit
6d3bf7c18d
2 changed files with 6 additions and 22 deletions
  1. +1
    -1
      service/censusmanager.go
  2. +5
    -21
      tree/tree.go

+ 1
- 1
service/censusmanager.go

@ -189,7 +189,7 @@ func claimHandler(w http.ResponseWriter, req *http.Request, op string) {
resp.Error = true resp.Error = true
resp.Response = err.Error() resp.Response = err.Error()
} else { } else {
resp.Response = string(jValues)
resp.Response = fmt.Sprintf("%s", jValues)
} }
} }
} }

+ 5
- 21
tree/tree.go

@ -3,6 +3,7 @@ package tree
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"os/user" "os/user"
common3 "github.com/iden3/go-iden3/common" common3 "github.com/iden3/go-iden3/common"
@ -51,7 +52,7 @@ func (t *Tree) GetClaim(data []byte) (*mkcore.ClaimBasic, error) {
return nil, errors.New("claim data too large") return nil, errors.New("claim data too large")
} }
for i := len(data); i <= 496/8; i++ { for i := len(data); i <= 496/8; i++ {
data = append(data, byte('.'))
data = append(data, '\x00')
} }
var indexSlot [400 / 8]byte var indexSlot [400 / 8]byte
var dataSlot [496 / 8]byte var dataSlot [496 / 8]byte
@ -112,33 +113,16 @@ func (t *Tree) GetIndex(data []byte) (string, error) {
return index.String(), err return index.String(), err
} }
/*
func (t *Tree) Dump() ([]string, error) { func (t *Tree) Dump() ([]string, error) {
var response []string var response []string
err := t.Tree.Walk(t.Tree.RootKey(), func(n *merkletree.Node) {
err := t.Tree.Walk(nil, func(n *merkletree.Node) {
if n.Type == merkletree.NodeTypeLeaf { if n.Type == merkletree.NodeTypeLeaf {
rawValue := n.Value()
var cleanValue []byte
for i := 0; i < len(rawValue); i++ {
if rawValue[i] == byte('.') {
break
}
cleanValue = append(cleanValue, rawValue[i])
}
response = append(response, fmt.Sprintf("%s", cleanValue))
data := bytes.Trim(n.Value()[65:], "\x00")
response = append(response, fmt.Sprintf("%s", data))
} }
}) })
return response, err return response, err
} }
*/
func (t *Tree) Dump() (string, error) {
w := bytes.NewBufferString("")
err := t.Tree.DumpClaims(w, nil) // as rootKey we can pass a nil pointer, and it will use the current RootKey
return w.String(), err
}
func (t *Tree) Snapshot(root string) (*Tree, error) { func (t *Tree) Snapshot(root string) (*Tree, error) {
var rootHash merkletree.Hash var rootHash merkletree.Hash

Loading…
Cancel
Save