mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 23:13:45 +00:00
created new api ContentByAccount in txpool namespace
This commit is contained in:
parent
8479f28b0b
commit
23cf9324cc
5 changed files with 56 additions and 0 deletions
|
|
@ -482,6 +482,27 @@ func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common
|
||||||
return pending, queued
|
return pending, queued
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContentByAccount retrieves the data content of the transaction pool with a specific account,
|
||||||
|
// returning the pending as well as queued transaction.
|
||||||
|
func (pool *TxPool) ContentByAccount(addr common.Address) (pending, queued types.Transactions) {
|
||||||
|
pool.mu.Lock()
|
||||||
|
defer pool.mu.Unlock()
|
||||||
|
|
||||||
|
list, ok := pool.pending[addr]
|
||||||
|
if !ok {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
pending = list.Flatten()
|
||||||
|
|
||||||
|
list, ok = pool.queue[addr]
|
||||||
|
if !ok {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
queued = list.Flatten()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Pending retrieves all currently processable transactions, grouped by origin
|
// Pending retrieves all currently processable transactions, grouped by origin
|
||||||
// account and sorted by nonce. The returned transaction set is a copy and can be
|
// account and sorted by nonce. The returned transaction set is a copy and can be
|
||||||
// freely modified by calling code.
|
// freely modified by calling code.
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,10 @@ func (b *EthAPIBackend) TxPoolContent() (map[common.Address]types.Transactions,
|
||||||
return b.eth.TxPool().Content()
|
return b.eth.TxPool().Content()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *EthAPIBackend) TxPoolContentByAccount(addr common.Address) (pending, queued types.Transactions) {
|
||||||
|
return b.eth.TxPool().ContentByAccount(addr)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *EthAPIBackend) TxPool() *core.TxPool {
|
func (b *EthAPIBackend) TxPool() *core.TxPool {
|
||||||
return b.eth.TxPool()
|
return b.eth.TxPool()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,31 @@ func NewPublicTxPoolAPI(b Backend) *PublicTxPoolAPI {
|
||||||
return &PublicTxPoolAPI{b}
|
return &PublicTxPoolAPI{b}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContentByAccount returns the transactions contained within the tx pool by given account address.
|
||||||
|
func (s *PublicTxPoolAPI) ContentByAccount(addr common.Address) map[string]map[string]*RPCTransaction {
|
||||||
|
// map[(queued|pending)]map[tx.Nonce()]tx
|
||||||
|
content := map[string]map[string]*RPCTransaction{
|
||||||
|
"pending": make(map[string]*RPCTransaction),
|
||||||
|
"queued": make(map[string]*RPCTransaction),
|
||||||
|
}
|
||||||
|
|
||||||
|
pending, queued := s.b.TxPoolContentByAccount(addr)
|
||||||
|
|
||||||
|
dump := make(map[string]*RPCTransaction)
|
||||||
|
for _, tx := range pending {
|
||||||
|
dump[fmt.Sprintf("%d", tx.Nonce())] = newRPCPendingTransaction(tx)
|
||||||
|
}
|
||||||
|
content["pending"] = dump
|
||||||
|
|
||||||
|
dump = make(map[string]*RPCTransaction)
|
||||||
|
for _, tx := range queued {
|
||||||
|
dump[fmt.Sprintf("%d", tx.Nonce())] = newRPCPendingTransaction(tx)
|
||||||
|
}
|
||||||
|
content["queued"] = dump
|
||||||
|
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
// Content returns the transactions contained within the transaction pool.
|
// Content returns the transactions contained within the transaction pool.
|
||||||
func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction {
|
func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string]*RPCTransaction {
|
||||||
content := map[string]map[string]map[string]*RPCTransaction{
|
content := map[string]map[string]map[string]*RPCTransaction{
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ type Backend interface {
|
||||||
GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
|
GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
|
||||||
Stats() (pending int, queued int)
|
Stats() (pending int, queued int)
|
||||||
TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
|
TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
|
||||||
|
TxPoolContentByAccount(address common.Address) (pending, queued types.Transactions)
|
||||||
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
|
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
|
||||||
|
|
||||||
// Filter API
|
// Filter API
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,11 @@ func (b *LesApiBackend) TxPoolContent() (map[common.Address]types.Transactions,
|
||||||
return b.eth.txPool.Content()
|
return b.eth.txPool.Content()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *LesApiBackend) TxPoolContentByAccount(addr common.Address) (pending, queued types.Transactions) {
|
||||||
|
// TODO(barryz) not implement for light node.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *LesApiBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
|
func (b *LesApiBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
|
||||||
return b.eth.txPool.SubscribeNewTxsEvent(ch)
|
return b.eth.txPool.SubscribeNewTxsEvent(ch)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue