diff --git a/trie/trienode/witness.go b/trie/trienode/witness.go index ac328a3f15..bbd0c71475 100644 --- a/trie/trienode/witness.go +++ b/trie/trienode/witness.go @@ -16,7 +16,12 @@ package trienode -import "github.com/ethereum/go-ethereum/common" +import ( + "encoding/hex" + "encoding/json" + + "github.com/ethereum/go-ethereum/common" +) // Witness is the set of nodes retrieved from the database for executing a state // transition. It can be considered as the previous state for the state transition, @@ -26,6 +31,20 @@ type Witness struct { Nodes map[string][]byte } +func (u *Witness) MarshalJSON() ([]byte, error) { + nodes := make(map[string]string) + for key, node := range u.Nodes { + nodes[key] = hex.EncodeToString(node) + } + return json.Marshal(&struct { + Owner common.Hash + Nodes map[string]string + }{ + Owner: u.Owner, + Nodes: nodes, + }) +} + // NewWitness constructs a witness structure. func NewWitness(owner common.Hash) *Witness { return &Witness{Owner: owner, Nodes: make(map[string][]byte)}