Skip to content

Commit

Permalink
eth: return rlp-decoded values from debug_storageRangeAt (#15476)
Browse files Browse the repository at this point in the history
Fixes #15196
  • Loading branch information
mexskican authored and fjl committed Dec 6, 2017
1 parent e85b68e commit eab2201
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,18 @@ func (api *PrivateDebugAPI) StorageRangeAt(ctx context.Context, blockHash common
if st == nil {
return StorageRangeResult{}, fmt.Errorf("account %x doesn't exist", contractAddress)
}
return storageRangeAt(st, keyStart, maxResult), nil
return storageRangeAt(st, keyStart, maxResult)
}

func storageRangeAt(st state.Trie, start []byte, maxResult int) StorageRangeResult {
func storageRangeAt(st state.Trie, start []byte, maxResult int) (StorageRangeResult, error) {
it := trie.NewIterator(st.NodeIterator(start))
result := StorageRangeResult{Storage: storageMap{}}
for i := 0; i < maxResult && it.Next(); i++ {
e := storageEntry{Value: common.BytesToHash(it.Value)}
_, content, _, err := rlp.Split(it.Value)
if err != nil {
return StorageRangeResult{}, err
}
e := storageEntry{Value: common.BytesToHash(content)}
if preimage := st.GetKey(it.Key); preimage != nil {
preimage := common.BytesToHash(preimage)
e.Key = &preimage
Expand All @@ -634,7 +638,7 @@ func storageRangeAt(st state.Trie, start []byte, maxResult int) StorageRangeResu
next := common.BytesToHash(it.Key)
result.NextKey = &next
}
return result
return result, nil
}

// GetModifiedAccountsByumber returns all accounts that have changed between the
Expand Down
5 changes: 4 additions & 1 deletion eth/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func TestStorageRangeAt(t *testing.T) {
},
}
for _, test := range tests {
result := storageRangeAt(state.StorageTrie(addr), test.start, test.limit)
result, err := storageRangeAt(state.StorageTrie(addr), test.start, test.limit)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(result, test.want) {
t.Fatalf("wrong result for range 0x%x.., limit %d:\ngot %s\nwant %s",
test.start, test.limit, dumper.Sdump(result), dumper.Sdump(&test.want))
Expand Down

0 comments on commit eab2201

Please sign in to comment.