optimize GetStorageAt; GetStorageAt unit tests

This commit is contained in:
Ian Norden
2020-10-30 12:06:41 -05:00
parent b664aee621
commit b208281ad6
6 changed files with 334 additions and 116 deletions
+3 -7
View File
@@ -619,13 +619,9 @@ func (pea *PublicEthAPI) localGetBalance(ctx context.Context, address common.Add
// block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta block
// numbers are also allowed.
func (pea *PublicEthAPI) GetStorageAt(ctx context.Context, address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) {
state, _, err := pea.B.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state != nil && err == nil {
res := state.GetState(address, common.HexToHash(key))
err = state.Error()
if err == nil {
return res[:], nil
}
storageVal, err := pea.B.GetStorageByNumberOrHash(ctx, address, common.HexToHash(key), blockNrOrHash)
if storageVal != nil && err == nil {
return storageVal, nil
}
if pea.rpc != nil {
var res hexutil.Bytes