eth: squash this

This commit is contained in:
Jared Wasinger 2019-03-18 13:21:56 -07:00 committed by Guillaume Ballet
parent a37395332c
commit 23f47b77a0
2 changed files with 34 additions and 5 deletions

View file

@ -341,10 +341,15 @@ type AccountRangeResult struct {
Next common.Address `json:"next"`
}
func accountRange(st state.Trie, start *common.Address, maxResult int) (AccountRangeResult, error) {
func accountRange(st state.Trie, start *common.Address, maxResults 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++ {
if maxResults > AccountRangeAtMaxResults {
maxResults = AccountRangeAtMaxResults
}
for i := 0; i < maxResults && it.Next(); i++ {
if preimage := st.GetKey(it.Key); preimage != nil {
result.Addresses = append(result.Addresses, common.BytesToAddress(preimage))
} else {
@ -373,9 +378,6 @@ func (api *PrivateDebugAPI) AccountRangeAt(ctx context.Context, startAddr *commo
var err error
block := api.eth.blockchain.CurrentBlock()
if maxResults > AccountRangeAtMaxResults {
maxResults = AccountRangeAtMaxResults
}
if len(block.Transactions()) == 0 {
parent := api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)

View file

@ -17,6 +17,8 @@
package eth
import (
"math/big"
"fmt"
"reflect"
"testing"
@ -28,6 +30,31 @@ import (
var dumper = spew.ConfigState{Indent: " "}
func TestAccountRangeAt(t *testing.T) {
var (
state, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
addrs = [512]common.Address{}
)
for i := 0; i < 512; i++ {
addr := fmt.Sprintf("%x", i)
addrs[i] = common.HexToAddress(addr)
}
for i := range addrs {
state.SetBalance(addrs[i], big.NewInt(1))
}
// test retrieving less than max results
/*
result := accountRangeAt(state.Trie(), common.Address{0x0}, 128)
if len(result.Addresses) != 128 {
t.Fatalf("expected 128 results. Got %d", len(result.Addresses))
}
*/
}
func TestStorageRangeAt(t *testing.T) {
// Create a state where account 0x010000... has a few storage entries.
var (