mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth: accountRangeAt: only allow enumerating accounts in latest block. make use of preimage db.
This commit is contained in:
parent
6d85892579
commit
89940c09c1
2 changed files with 15 additions and 15 deletions
28
eth/api.go
28
eth/api.go
|
|
@ -28,6 +28,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
|
|
@ -334,28 +335,29 @@ func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs,
|
|||
return results, nil
|
||||
}
|
||||
|
||||
type addressMap map[common.Hash]common.Address
|
||||
|
||||
type AccountRangeResult struct {
|
||||
AddressMap addressMap `json:"addressMap"`
|
||||
Addresses []common.Address `json:"addresses"`
|
||||
Next common.Address `json:"next"`
|
||||
}
|
||||
|
||||
func accountRange(st state.Trie, start *common.Hash, maxResult int) (AccountRangeResult, error) {
|
||||
it := trie.NewIterator(st.NodeIterator(start[:]))
|
||||
result := AccountRangeResult{AddressMap: addressMap{}}
|
||||
func accountRange(st state.Trie, start *common.Address, maxResult int) (AccountRangeResult, error) {
|
||||
it := trie.NewIterator(st.NodeIterator(crypto.Keccak256(start[:])))
|
||||
result := AccountRangeResult{Addresses: []common.Address{}, Next: common.Address{}}
|
||||
for i := 0; i < maxResult && it.Next(); i++ {
|
||||
key := st.GetKey(it.Key)
|
||||
// If key is nil, that means it wasn't found in the preimage database.
|
||||
// This is not a problem, because we still return the hash of the key together with
|
||||
// address zero and the client can very easily determine that the hash of the addres zero
|
||||
// is not matching, which means it wasn't found.
|
||||
result.AddressMap[common.BytesToHash(it.Key)] = common.BytesToAddress(key)
|
||||
if preimage := st.GetKey(it.Key); preimage != nil {
|
||||
result.Addresses = append(result.Addresses, common.BytesToAddress(preimage))
|
||||
}
|
||||
}
|
||||
|
||||
if it.Next() {
|
||||
result.Next = common.BytesToAddress(st.GetKey(it.Key))
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
//block hash or number, tx index, start address hash, max results
|
||||
func (api *PrivateDebugAPI) AccountRangeAt(ctx context.Context, blockNr rpc.BlockNumber, txIndex int, startAddr *common.Hash, maxResults int) (AccountRangeResult, error) {
|
||||
func (api *PrivateDebugAPI) AccountRangeAt(ctx context.Context, txIndex int, startAddr *common.Address, maxResults int) (AccountRangeResult, error) {
|
||||
var statedb *state.StateDB = nil
|
||||
var err error = nil
|
||||
var block = api.eth.blockchain.CurrentBlock()
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ package eth
|
|||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
|
|
|
|||
Loading…
Reference in a new issue