forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added batch call for StoragesAt as well as tests
- Loading branch information
Showing
7 changed files
with
92 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"Name": "L1SLOAD FAIL: input contains only address", | ||
"Input": "a83114A443dA1CecEFC50368531cACE9F37fCCcb", | ||
"ExpectedError": "L1SLOAD input too short", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
}, | ||
{ | ||
"Name": "L1SLOAD FAIL: input key not 32 bytes", | ||
"Input": "a83114A443dA1CecEFC50368531cACE9F37fCCcb112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7122", | ||
"ExpectedError": "L1SLOAD input is malformed", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"Name": "L1SLOAD: 1 key", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e864", | ||
"Expected": "abab", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
}, | ||
{ | ||
"Name": "L1SLOAD: 2 keys", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e8640112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a", | ||
"Expected": "abababab", | ||
"Gas": 6000, | ||
"NoBenchmark": true | ||
}, | ||
|
||
{ | ||
"Name": "L1SLOAD: 5 keys", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e8640112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a", | ||
"Expected": "abababababababababab", | ||
"Gas": 12000, | ||
"NoBenchmark": true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ethclient | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
// StoragesAt returns the values of keys in the contract storage of the given account. | ||
// The block number can be nil, in which case the value is taken from the latest known block. | ||
func (ec *Client) StoragesAt(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) ([]byte, error) { | ||
results := make([]hexutil.Bytes, len(keys)) | ||
reqs := make([]rpc.BatchElem, len(keys)) | ||
|
||
for i := range reqs { | ||
reqs[i] = rpc.BatchElem{ | ||
Method: "eth_getStorageAt", | ||
Args: []interface{}{account, keys[i], toBlockNumArg(blockNumber)}, | ||
Result: &results[i], | ||
} | ||
} | ||
if err := ec.c.BatchCallContext(ctx, reqs); err != nil { | ||
return nil, err | ||
} | ||
|
||
output := make([]byte, common.HashLength*len(keys)) | ||
for i := range reqs { | ||
if reqs[i].Error != nil { | ||
return nil, reqs[i].Error | ||
} | ||
copy(output[i*common.HashLength:], results[i]) | ||
} | ||
|
||
return output, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters