diff options
author | Sonic <sonic@dexon.org> | 2018-11-09 17:24:54 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | a44c684f29ecdbfdf91338002f62efe87316e453 (patch) | |
tree | 9258e70c3e4d9e74c6056207855beb72efb20ca3 /core/blockchain.go | |
parent | e508bf0a8074e803cbcdaa162fd3289de2afda94 (diff) | |
download | dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.gz dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.bz2 dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.lz dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.xz dexon-a44c684f29ecdbfdf91338002f62efe87316e453.tar.zst dexon-a44c684f29ecdbfdf91338002f62efe87316e453.zip |
core: support extracting governance state from state trie
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 1c3de3c4f..5295b6939 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) +} + // reorgs 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 |