diff options
author | Sonic <sonic@dexon.org> | 2018-11-09 17:24:54 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:18 +0800 |
commit | 638816ae9be2dab6f48a367689563121c85d7786 (patch) | |
tree | bb0179cf42b998e5aea51f66fd9f80e7c33bec20 /core/state/gov.go | |
parent | 5aaccf466773e60c93ab150d89abd950bd43ca28 (diff) | |
download | go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.tar go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.tar.gz go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.tar.bz2 go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.tar.lz go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.tar.xz go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.tar.zst go-tangerine-638816ae9be2dab6f48a367689563121c85d7786.zip |
core: support extracting governance state from state trie
Diffstat (limited to 'core/state/gov.go')
-rw-r--r-- | core/state/gov.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/state/gov.go b/core/state/gov.go new file mode 100644 index 000000000..8b94cfab2 --- /dev/null +++ b/core/state/gov.go @@ -0,0 +1,31 @@ +package state + +import ( + "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/core/types" + "github.com/dexon-foundation/dexon/trie" +) + +func GetGovState(statedb *StateDB, header *types.Header, + addr common.Address) (*types.GovState, error) { + proof, err := statedb.GetProof(addr) + if err != nil { + return nil, err + } + + govState := &types.GovState{ + BlockHash: header.Hash(), + Number: header.Number, + Root: header.Root, + Proof: proof, + } + + if t := statedb.StorageTrie(addr); t != nil { + it := trie.NewIterator(t.NodeIterator(nil)) + for it.Next() { + govState.Storage = append(govState.Storage, + [2][]byte{it.Key, it.Value}) + } + } + return govState, nil +} |