mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth: accountRangeAt, return preimages if they can't be resolved to addresses
This commit is contained in:
parent
4168854f09
commit
a823ef26df
1 changed files with 11 additions and 2 deletions
13
eth/api.go
13
eth/api.go
|
|
@ -338,19 +338,28 @@ func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs,
|
||||||
type AccountRangeResult struct {
|
type AccountRangeResult struct {
|
||||||
Addresses []common.Address `json:"addresses"`
|
Addresses []common.Address `json:"addresses"`
|
||||||
Next common.Address `json:"next"`
|
Next common.Address `json:"next"`
|
||||||
|
Preimages []common.Hash `json:"preimages"`
|
||||||
|
NextPreimage common.Hash `json:"nextPreimage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountRange(st state.Trie, start *common.Address, maxResult int) (AccountRangeResult, error) {
|
func accountRange(st state.Trie, start *common.Address, maxResult 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{}, Preimages: []common.Hash{}, NextPreimage: common.Hash{}}
|
||||||
for i := 0; i < maxResult && it.Next(); i++ {
|
for i := 0; i < maxResult && 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 {
|
||||||
|
result.Preimages = append(result.Preimages, common.BytesToHash(preimage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if it.Next() {
|
if it.Next() {
|
||||||
result.Next = common.BytesToAddress(st.GetKey(it.Key))
|
if preimage := st.GetKey(it.Key); preimage != nil {
|
||||||
|
result.Next = common.BytesToAddress(st.GetKey(preimage))
|
||||||
|
} else {
|
||||||
|
result.NextPreimage = common.BytesToHash(preimage)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue