diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/state/statedb.go | 20 | ||||
-rw-r--r-- | core/vm/interface.go | 10 |
2 files changed, 30 insertions, 0 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go index 216667ce9..b1bb53ed0 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -18,6 +18,7 @@ package state import ( + "errors" "fmt" "math/big" "sort" @@ -25,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" @@ -256,6 +258,24 @@ func (self *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash return common.Hash{} } +// GetProof returns the MerkleProof for a given Account +func (self *StateDB) GetProof(a common.Address) (vm.ProofList, error) { + var proof vm.ProofList + err := self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof) + return proof, err +} + +// GetProof returns the StorageProof for given key +func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) (vm.ProofList, error) { + var proof vm.ProofList + trie := self.StorageTrie(a) + if trie == nil { + return proof, errors.New("storage trie for requested address does not exist") + } + err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof) + return proof, err +} + // GetCommittedState retrieves a value from the given account's committed storage trie. func (self *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash { stateObject := self.getStateObject(addr) diff --git a/core/vm/interface.go b/core/vm/interface.go index fc15082f1..1ae98cf7a 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -35,6 +35,8 @@ type StateDB interface { SetNonce(common.Address, uint64) GetCodeHash(common.Address) common.Hash + GetProof(common.Address) (ProofList, error) + GetStorageProof(common.Address, common.Hash) (ProofList, error) GetCode(common.Address) []byte SetCode(common.Address, []byte) GetCodeSize(common.Address) int @@ -78,3 +80,11 @@ type CallContext interface { // Create a new contract Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) } + +// MerkleProof +type ProofList [][]byte + +func (n *ProofList) Put(key []byte, value []byte) error { + *n = append(*n, value) + return nil +} |