aboutsummaryrefslogtreecommitdiffstats
path: root/core/state
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-11-09 17:24:54 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commita44c684f29ecdbfdf91338002f62efe87316e453 (patch)
tree9258e70c3e4d9e74c6056207855beb72efb20ca3 /core/state
parente508bf0a8074e803cbcdaa162fd3289de2afda94 (diff)
downloaddexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.gz
dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.zst
dexon-a44c684f29ecdbfdf91338002f62efe87316e453.zip
core: support extracting governance state from state trie
Diffstat (limited to 'core/state')
-rw-r--r--core/state/gov.go31
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
+}