aboutsummaryrefslogtreecommitdiffstats
path: root/eth/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'eth/api.go')
-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 {