mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth: squash this
This commit is contained in:
parent
a37395332c
commit
23f47b77a0
2 changed files with 34 additions and 5 deletions
12
eth/api.go
12
eth/api.go
|
|
@ -341,10 +341,15 @@ type AccountRangeResult struct {
|
||||||
Next common.Address `json:"next"`
|
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[:])))
|
it := trie.NewIterator(st.NodeIterator(crypto.Keccak256(start[:])))
|
||||||
result := AccountRangeResult{Addresses: []common.Address{}, Next: common.Address{}}
|
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 {
|
if preimage := st.GetKey(it.Key); preimage != nil {
|
||||||
result.Addresses = append(result.Addresses, common.BytesToAddress(preimage))
|
result.Addresses = append(result.Addresses, common.BytesToAddress(preimage))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -373,9 +378,6 @@ func (api *PrivateDebugAPI) AccountRangeAt(ctx context.Context, startAddr *commo
|
||||||
var err error
|
var err error
|
||||||
block := api.eth.blockchain.CurrentBlock()
|
block := api.eth.blockchain.CurrentBlock()
|
||||||
|
|
||||||
if maxResults > AccountRangeAtMaxResults {
|
|
||||||
maxResults = AccountRangeAtMaxResults
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(block.Transactions()) == 0 {
|
if len(block.Transactions()) == 0 {
|
||||||
parent := api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
|
parent := api.eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -28,6 +30,31 @@ import (
|
||||||
|
|
||||||
var dumper = spew.ConfigState{Indent: " "}
|
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) {
|
func TestStorageRangeAt(t *testing.T) {
|
||||||
// Create a state where account 0x010000... has a few storage entries.
|
// Create a state where account 0x010000... has a few storage entries.
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue