forked from cerc-io/plugeth
core/state: simplify proof methods (#17965)
This fixes the import cycle build error in core/vm tests. There is no need to refer to core/vm for a type definition.
This commit is contained in:
parent
4c0883e20d
commit
7f22b59f87
@ -26,7 +26,6 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"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/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
@ -46,6 +45,13 @@ var (
|
|||||||
emptyCode = crypto.Keccak256Hash(nil)
|
emptyCode = crypto.Keccak256Hash(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type proofList [][]byte
|
||||||
|
|
||||||
|
func (n *proofList) Put(key []byte, value []byte) error {
|
||||||
|
*n = append(*n, value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// StateDBs within the ethereum protocol are used to store anything
|
// StateDBs within the ethereum protocol are used to store anything
|
||||||
// within the merkle trie. StateDBs take care of caching and storing
|
// within the merkle trie. StateDBs take care of caching and storing
|
||||||
// nested states. It's the general query interface to retrieve:
|
// nested states. It's the general query interface to retrieve:
|
||||||
@ -259,21 +265,21 @@ func (self *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetProof returns the MerkleProof for a given Account
|
// GetProof returns the MerkleProof for a given Account
|
||||||
func (self *StateDB) GetProof(a common.Address) (vm.ProofList, error) {
|
func (self *StateDB) GetProof(a common.Address) ([][]byte, error) {
|
||||||
var proof vm.ProofList
|
var proof proofList
|
||||||
err := self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof)
|
err := self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof)
|
||||||
return proof, err
|
return [][]byte(proof), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProof returns the StorageProof for given key
|
// GetProof returns the StorageProof for given key
|
||||||
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) (vm.ProofList, error) {
|
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error) {
|
||||||
var proof vm.ProofList
|
var proof proofList
|
||||||
trie := self.StorageTrie(a)
|
trie := self.StorageTrie(a)
|
||||||
if trie == nil {
|
if trie == nil {
|
||||||
return proof, errors.New("storage trie for requested address does not exist")
|
return proof, errors.New("storage trie for requested address does not exist")
|
||||||
}
|
}
|
||||||
err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
|
err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
|
||||||
return proof, err
|
return [][]byte(proof), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCommittedState retrieves a value from the given account's committed storage trie.
|
// GetCommittedState retrieves a value from the given account's committed storage trie.
|
||||||
|
@ -35,8 +35,6 @@ type StateDB interface {
|
|||||||
SetNonce(common.Address, uint64)
|
SetNonce(common.Address, uint64)
|
||||||
|
|
||||||
GetCodeHash(common.Address) common.Hash
|
GetCodeHash(common.Address) common.Hash
|
||||||
GetProof(common.Address) (ProofList, error)
|
|
||||||
GetStorageProof(common.Address, common.Hash) (ProofList, error)
|
|
||||||
GetCode(common.Address) []byte
|
GetCode(common.Address) []byte
|
||||||
SetCode(common.Address, []byte)
|
SetCode(common.Address, []byte)
|
||||||
GetCodeSize(common.Address) int
|
GetCodeSize(common.Address) int
|
||||||
@ -80,11 +78,3 @@ type CallContext interface {
|
|||||||
// Create a new contract
|
// Create a new contract
|
||||||
Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user