mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
add custom marshaler for witness
This commit is contained in:
parent
2530c4a3e6
commit
3ef9c7fbe1
1 changed files with 20 additions and 1 deletions
|
|
@ -16,7 +16,12 @@
|
||||||
|
|
||||||
package trienode
|
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
|
// 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,
|
// transition. It can be considered as the previous state for the state transition,
|
||||||
|
|
@ -26,6 +31,20 @@ type Witness struct {
|
||||||
Nodes map[string][]byte
|
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.
|
// NewWitness constructs a witness structure.
|
||||||
func NewWitness(owner common.Hash) *Witness {
|
func NewWitness(owner common.Hash) *Witness {
|
||||||
return &Witness{Owner: owner, Nodes: make(map[string][]byte)}
|
return &Witness{Owner: owner, Nodes: make(map[string][]byte)}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue