mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22: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 {
|
||||
var proof ProofList
|
||||
self.trie.Prove(crypto.Keccak256(a.Bytes()), 0, &proof)
|
||||
return [][]byte(proof)
|
||||
return proof
|
||||
}
|
||||
|
||||
// returns the StorageProof for given key
|
||||
|
|
@ -279,7 +279,7 @@ func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) [][]byte
|
|||
}
|
||||
var proof ProofList
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -514,28 +514,32 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre
|
|||
codeHash := state.GetCodeHash(address)
|
||||
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 {
|
||||
storageHash = storageTrie.Hash()
|
||||
} else {
|
||||
// no storageTrie means the account does not exist, so the codeHash is the hash of an empty bytearray.
|
||||
codeHash = crypto.Keccak256Hash(nil)
|
||||
}
|
||||
|
||||
for i := range storageKeys {
|
||||
// create the proof for the storageKeys
|
||||
for i, key := range storageKeys {
|
||||
if storageTrie != nil {
|
||||
storageProof[i] = map[string]interface{}{
|
||||
"key": storageKeys[i],
|
||||
"value": state.GetState(address, common.HexToHash(storageKeys[i])),
|
||||
"proof": common.ToHexArray(state.GetStorageProof(address, common.HexToHash(storageKeys[i]))),
|
||||
"key": key,
|
||||
"value": state.GetState(address, common.HexToHash(key)),
|
||||
"proof": common.ToHexArray(state.GetStorageProof(address, common.HexToHash(key))),
|
||||
}
|
||||
} else {
|
||||
storageProof[i] = map[string]interface{}{
|
||||
"key": storageKeys[i],
|
||||
"key": key,
|
||||
"value": common.Hash{},
|
||||
"proof": []string{},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fill results for the account
|
||||
fields := map[string]interface{}{
|
||||
"address": address,
|
||||
"accountProof": common.ToHexArray(state.GetProof(address)),
|
||||
|
|
|
|||
Loading…
Reference in a new issue