mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/api: add debug_listAccounts API
This commit is contained in:
parent
86e77900c5
commit
488948c7cd
3 changed files with 57 additions and 1 deletions
|
|
@ -609,6 +609,11 @@ func (self *StateDB) GetRefund() uint64 {
|
||||||
return self.refund
|
return self.refund
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTrie returns the current value of the trie.
|
||||||
|
func (self *StateDB) GetTrie() Trie {
|
||||||
|
return self.trie
|
||||||
|
}
|
||||||
|
|
||||||
// Finalise finalises the state by removing the self destructed objects
|
// Finalise finalises the state by removing the self destructed objects
|
||||||
// and clears the journal as well as the refunds.
|
// and clears the journal as well as the refunds.
|
||||||
func (s *StateDB) Finalise(deleteEmptyObjects bool) {
|
func (s *StateDB) Finalise(deleteEmptyObjects bool) {
|
||||||
|
|
|
||||||
45
eth/api.go
45
eth/api.go
|
|
@ -34,6 +34,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
@ -284,6 +285,50 @@ func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error
|
||||||
return stateDb.RawDump(), nil
|
return stateDb.RawDump(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListAccounts retrieves accounts of the database at a given block.
|
||||||
|
func (api *PublicDebugAPI) ListAccounts(count uint64, offset *common.Address, blockNr *rpc.BlockNumber) ([]common.Address, error) {
|
||||||
|
var block *types.Block = nil
|
||||||
|
var tr state.Trie
|
||||||
|
|
||||||
|
if blockNr == nil || *blockNr == rpc.LatestBlockNumber {
|
||||||
|
block = api.eth.blockchain.CurrentBlock()
|
||||||
|
} else if *blockNr != rpc.PendingBlockNumber {
|
||||||
|
block = api.eth.blockchain.GetBlockByNumber(uint64(*blockNr))
|
||||||
|
}
|
||||||
|
if block != nil {
|
||||||
|
stateDb, err := api.eth.BlockChain().StateAt(block.Root())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tr, err = stateDb.Database().OpenTrie(block.Root())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else if *blockNr != rpc.PendingBlockNumber {
|
||||||
|
return nil, fmt.Errorf("block #%d not found", *blockNr)
|
||||||
|
} else {
|
||||||
|
// Get the pending state
|
||||||
|
_, stateDb := api.eth.miner.Pending()
|
||||||
|
tr = stateDb.GetTrie()
|
||||||
|
}
|
||||||
|
|
||||||
|
var accounts []common.Address
|
||||||
|
var it *trie.Iterator
|
||||||
|
|
||||||
|
if offset != nil && *offset != (common.Address{}) {
|
||||||
|
it = trie.NewIterator(tr.NodeIterator(crypto.Keccak256(offset[:])))
|
||||||
|
it.Next()
|
||||||
|
} else {
|
||||||
|
it = trie.NewIterator(tr.NodeIterator(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
for ; count > 0 && it.Next(); count-- {
|
||||||
|
addr := tr.GetKey(it.Key)
|
||||||
|
accounts = append(accounts, common.BytesToAddress(addr))
|
||||||
|
}
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PrivateDebugAPI is the collection of Ethereum full node APIs exposed over
|
// PrivateDebugAPI is the collection of Ethereum full node APIs exposed over
|
||||||
// the private debugging endpoint.
|
// the private debugging endpoint.
|
||||||
type PrivateDebugAPI struct {
|
type PrivateDebugAPI struct {
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,12 @@ web3._extend({
|
||||||
call: 'debug_dumpBlock',
|
call: 'debug_dumpBlock',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'listAccounts',
|
||||||
|
call: 'debug_listAccounts',
|
||||||
|
params: 3,
|
||||||
|
inputFormatter: [null, null, web3._extend.formatters.inputDefaultBlockNumberFormatter],
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'chaindbProperty',
|
name: 'chaindbProperty',
|
||||||
call: 'debug_chaindbProperty',
|
call: 'debug_chaindbProperty',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue