rpc: allow nil as a start hash param

This commit is contained in:
Guillaume Ballet 2019-07-10 12:29:43 +02:00
parent 8efbf2134d
commit 0e5dcefc0e
2 changed files with 6 additions and 0 deletions

View file

@ -344,6 +344,9 @@ type AccountRangeResult struct {
} }
func accountRange(st state.Trie, start *common.Hash, maxResults int) (AccountRangeResult, error) { func accountRange(st state.Trie, start *common.Hash, maxResults int) (AccountRangeResult, error) {
if start == nil {
start = &common.Hash{0}
}
it := trie.NewIterator(st.NodeIterator(start.Bytes())) it := trie.NewIterator(st.NodeIterator(start.Bytes()))
result := AccountRangeResult{Accounts: make(map[common.Hash]*common.Address), Next: common.Hash{}} result := AccountRangeResult{Accounts: make(map[common.Hash]*common.Address), Next: common.Hash{}}

View file

@ -88,6 +88,9 @@ func TestAccountRange(t *testing.T) {
t.Logf("test getting number of results greater than max %d", AccountRangeMaxResults) t.Logf("test getting number of results greater than max %d", AccountRangeMaxResults)
accountRangeTest(t, &trie, state, &common.Hash{0x0}, AccountRangeMaxResults*2, AccountRangeMaxResults) accountRangeTest(t, &trie, state, &common.Hash{0x0}, AccountRangeMaxResults*2, AccountRangeMaxResults)
t.Logf("test with empty 'start' hash")
accountRangeTest(t, &trie, state, nil, AccountRangeMaxResults, AccountRangeMaxResults)
t.Logf("test pagination") t.Logf("test pagination")
// test pagination // test pagination