aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-11-09 17:24:54 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 13:49:57 +0800
commit4aff23bb432263840f858f4700649f87a19694b4 (patch)
tree0874f94fd786673bb1188b221e4baadb9f670e28 /core/blockchain.go
parent67f05cdf8531b54592255fb9a19619d8bd8e28bb (diff)
downloaddexon-4aff23bb432263840f858f4700649f87a19694b4.tar.gz
dexon-4aff23bb432263840f858f4700649f87a19694b4.tar.zst
dexon-4aff23bb432263840f858f4700649f87a19694b4.zip
core: support extracting governance state from state trie
Diffstat (limited to 'core/blockchain.go')
-rw-r--r--core/blockchain.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index e7b1c846f..8bf680c38 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1740,6 +1740,33 @@ func (bc *BlockChain) GetPending() (*types.Block, *state.StateDB) {
return block, s
}
+// GetGovStateByHash extracts the governance contract's state from state trie
+// (the merkle proof of governance contract address and the whole storage)
+// at the given block hash.
+func (bc *BlockChain) GetGovStateByHash(hash common.Hash) (*types.GovState, error) {
+ header := bc.GetHeaderByHash(hash)
+ if header == nil {
+ return nil, fmt.Errorf("header not found")
+ }
+ statedb, err := bc.StateAt(header.Root)
+ if err != nil {
+ return nil, err
+ }
+ return state.GetGovState(statedb, header, vm.GovernanceContractAddress)
+}
+
+func (bc *BlockChain) GetGovStateByNumber(number uint64) (*types.GovState, error) {
+ header := bc.GetHeaderByNumber(number)
+ if header == nil {
+ return nil, fmt.Errorf("header not found")
+ }
+ statedb, err := bc.StateAt(header.Root)
+ if err != nil {
+ return nil, err
+ }
+ return state.GetGovState(statedb, header, vm.GovernanceContractAddress)
+}
+
// reorg takes two blocks, an old chain and a new chain and will reconstruct the
// blocks and inserts them to be part of the new canonical chain and accumulates
// potential missing transactions and post an event about them.