mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
added comments and refactored based on comments from holiman
This commit is contained in:
parent
54498456c1
commit
65c4bb2caf
2 changed files with 11 additions and 7 deletions
|
|
@ -268,7 +268,7 @@ func (n *ProofList) Put(key []byte, value []byte) error {
|
||||||
func (self *StateDB) GetProof(a common.Address) [][]byte {
|
func (self *StateDB) GetProof(a common.Address) [][]byte {
|
||||||
var proof ProofList
|
var proof ProofList
|
||||||
self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof)
|
self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof)
|
||||||
return [][]byte(proof)
|
return proof
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the StorageProof for given key
|
// returns the StorageProof for given key
|
||||||
|
|
@ -279,7 +279,7 @@ func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) [][]byte
|
||||||
}
|
}
|
||||||
var proof ProofList
|
var proof ProofList
|
||||||
trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
|
trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
|
||||||
return [][]byte(proof)
|
return proof
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCommittedState retrieves a value from the given account's committed storage trie.
|
// GetCommittedState retrieves a value from the given account's committed storage trie.
|
||||||
|
|
|
||||||
|
|
@ -514,28 +514,32 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre
|
||||||
codeHash := state.GetCodeHash(address)
|
codeHash := state.GetCodeHash(address)
|
||||||
storageProof := make([]map[string]interface{}, len(storageKeys))
|
storageProof := make([]map[string]interface{}, len(storageKeys))
|
||||||
|
|
||||||
|
// if we have a storageTrie, (which means the account exists), we can update the storagehash
|
||||||
if storageTrie != nil {
|
if storageTrie != nil {
|
||||||
storageHash = storageTrie.Hash()
|
storageHash = storageTrie.Hash()
|
||||||
} else {
|
} else {
|
||||||
|
// no storageTrie means the account does not exist, so the codeHash is the hash of an empty bytearray.
|
||||||
codeHash = crypto.Keccak256Hash(nil)
|
codeHash = crypto.Keccak256Hash(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range storageKeys {
|
// create the proof for the storageKeys
|
||||||
|
for i, key := range storageKeys {
|
||||||
if storageTrie != nil {
|
if storageTrie != nil {
|
||||||
storageProof[i] = map[string]interface{}{
|
storageProof[i] = map[string]interface{}{
|
||||||
"key": storageKeys[i],
|
"key": key,
|
||||||
"value": state.GetState(address, common.HexToHash(storageKeys[i])),
|
"value": state.GetState(address, common.HexToHash(key)),
|
||||||
"proof": common.ToHexArray(state.GetStorageProof(address, common.HexToHash(storageKeys[i]))),
|
"proof": common.ToHexArray(state.GetStorageProof(address, common.HexToHash(key))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
storageProof[i] = map[string]interface{}{
|
storageProof[i] = map[string]interface{}{
|
||||||
"key": storageKeys[i],
|
"key": key,
|
||||||
"value": common.Hash{},
|
"value": common.Hash{},
|
||||||
"proof": []string{},
|
"proof": []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fill results for the account
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"address": address,
|
"address": address,
|
||||||
"accountProof": common.ToHexArray(state.GetProof(address)),
|
"accountProof": common.ToHexArray(state.GetProof(address)),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue