aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-12-30 19:32:15 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-01 20:58:14 +0800
commitd3642b0715f9168ee523f2cd8414f7fc4fc4ea33 (patch)
treecf975b43e4ccb23416207f2263ca2efca2eecfb0 /eth
parentf85212aa86c8feac17f582ac14f6b15260015261 (diff)
downloadgo-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.tar
go-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.tar.gz
go-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.tar.bz2
go-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.tar.lz
go-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.tar.xz
go-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.tar.zst
go-tangerine-d3642b0715f9168ee523f2cd8414f7fc4fc4ea33.zip
core, eth, rpc/api: rpc method to inspect the txpool queue
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/eth/api.go b/eth/api.go
index 08b103a4c..0f55c60a9 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -227,6 +227,39 @@ func NewPublicTxPoolAPI(e *Ethereum) *PublicTxPoolAPI {
return &PublicTxPoolAPI{e}
}
+// Content returns the transactions contained within the transaction pool.
+func (s *PublicTxPoolAPI) Content() map[string]map[string]map[string][]*RPCTransaction {
+ content := map[string]map[string]map[string][]*RPCTransaction{
+ "pending": make(map[string]map[string][]*RPCTransaction),
+ "queued": make(map[string]map[string][]*RPCTransaction),
+ }
+ pending, queue := s.e.TxPool().Content()
+
+ // Flatten the pending transactions
+ for account, batches := range pending {
+ dump := make(map[string][]*RPCTransaction)
+ for nonce, txs := range batches {
+ nonce := fmt.Sprintf("%d", nonce)
+ for _, tx := range txs {
+ dump[nonce] = append(dump[nonce], newRPCPendingTransaction(tx))
+ }
+ }
+ content["pending"][account.Hex()] = dump
+ }
+ // Flatten the queued transactions
+ for account, batches := range queue {
+ dump := make(map[string][]*RPCTransaction)
+ for nonce, txs := range batches {
+ nonce := fmt.Sprintf("%d", nonce)
+ for _, tx := range txs {
+ dump[nonce] = append(dump[nonce], newRPCPendingTransaction(tx))
+ }
+ }
+ content["queued"][account.Hex()] = dump
+ }
+ return content
+}
+
// Status returns the number of pending and queued transaction in the pool.
func (s *PublicTxPoolAPI) Status() map[string]*rpc.HexNumber {
pending, queue := s.e.TxPool().Stats()
@@ -236,6 +269,47 @@ func (s *PublicTxPoolAPI) Status() map[string]*rpc.HexNumber {
}
}
+// Inspect retrieves the content of the transaction pool and flattens it into an
+// easily inspectable list.
+func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string][]string {
+ content := map[string]map[string]map[string][]string{
+ "pending": make(map[string]map[string][]string),
+ "queued": make(map[string]map[string][]string),
+ }
+ pending, queue := s.e.TxPool().Content()
+
+ // Define a formatter to flatten a transaction into a string
+ var format = func(tx *types.Transaction) string {
+ if to := tx.To(); to != nil {
+ return fmt.Sprintf("%s: %v wei + %v × %v gas", tx.To().Hex(), tx.Value(), tx.Gas(), tx.GasPrice())
+ }
+ return fmt.Sprintf("contract creation: %v wei + %v × %v gas", tx.Value(), tx.Gas(), tx.GasPrice())
+ }
+ // Flatten the pending transactions
+ for account, batches := range pending {
+ dump := make(map[string][]string)
+ for nonce, txs := range batches {
+ nonce := fmt.Sprintf("%d", nonce)
+ for _, tx := range txs {
+ dump[nonce] = append(dump[nonce], format(tx))
+ }
+ }
+ content["pending"][account.Hex()] = dump
+ }
+ // Flatten the queued transactions
+ for account, batches := range queue {
+ dump := make(map[string][]string)
+ for nonce, txs := range batches {
+ nonce := fmt.Sprintf("%d", nonce)
+ for _, tx := range txs {
+ dump[nonce] = append(dump[nonce], format(tx))
+ }
+ }
+ content["queued"][account.Hex()] = dump
+ }
+ return content
+}
+
// PublicAccountAPI provides an API to access accounts managed by this node.
// It offers only methods that can retrieve accounts.
type PublicAccountAPI struct {