mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
use ProofList as return type
This commit is contained in:
parent
17ac3721f2
commit
7dbe3a8b88
3 changed files with 17 additions and 16 deletions
|
|
@ -31,7 +31,7 @@ func ToHex(b []byte) string {
|
||||||
return "0x" + hex
|
return "0x" + hex
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a array of hex-string based on []byte
|
// ToHexArray creates a array of hex-string based on []byte
|
||||||
func ToHexArray(b [][]byte) []string {
|
func ToHexArray(b [][]byte) []string {
|
||||||
r := make([]string, len(b))
|
r := make([]string, len(b))
|
||||||
for i := range b {
|
for i := range b {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ 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"
|
||||||
|
|
@ -257,28 +258,20 @@ func (self *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MerkleProof
|
|
||||||
type ProofList [][]byte
|
|
||||||
|
|
||||||
func (n *ProofList) Put(key []byte, value []byte) error {
|
|
||||||
*n = append(*n, value)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetProof returns the MerkleProof for a given Account
|
// GetProof returns the MerkleProof for a given Account
|
||||||
func (self *StateDB) GetProof(a common.Address) ([][]byte, error) {
|
func (self *StateDB) GetProof(a common.Address) (vm.ProofList, error) {
|
||||||
var proof ProofList
|
var proof vm.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 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) ([][]byte, error) {
|
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) (vm.ProofList, error) {
|
||||||
|
var proof vm.ProofList
|
||||||
trie := self.StorageTrie(a)
|
trie := self.StorageTrie(a)
|
||||||
if trie == nil {
|
if trie == nil {
|
||||||
return [][]byte{}, errors.New("storage trie for requested address does not exist")
|
return proof, errors.New("storage trie for requested address does not exist")
|
||||||
}
|
}
|
||||||
var proof ProofList
|
|
||||||
err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
|
err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
|
||||||
return proof, err
|
return proof, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ type StateDB interface {
|
||||||
SetNonce(common.Address, uint64)
|
SetNonce(common.Address, uint64)
|
||||||
|
|
||||||
GetCodeHash(common.Address) common.Hash
|
GetCodeHash(common.Address) common.Hash
|
||||||
GetProof(common.Address) ([][]byte, error)
|
GetProof(common.Address) (ProofList, error)
|
||||||
GetStorageProof(common.Address, common.Hash) ([][]byte, 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,3 +80,11 @@ 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 a new issue