@@ -227,6 +227,39 @@ func NewPublicTxPoolAPI(e *Ethereum) *PublicTxPoolAPI {
227227 return & PublicTxPoolAPI {e }
228228}
229229
230+ // Content returns the transactions contained within the transaction pool.
231+ func (s * PublicTxPoolAPI ) Content () map [string ]map [string ]map [string ][]* RPCTransaction {
232+ content := map [string ]map [string ]map [string ][]* RPCTransaction {
233+ "pending" : make (map [string ]map [string ][]* RPCTransaction ),
234+ "queued" : make (map [string ]map [string ][]* RPCTransaction ),
235+ }
236+ pending , queue := s .e .TxPool ().Content ()
237+
238+ // Flatten the pending transactions
239+ for account , batches := range pending {
240+ dump := make (map [string ][]* RPCTransaction )
241+ for nonce , txs := range batches {
242+ nonce := fmt .Sprintf ("%d" , nonce )
243+ for _ , tx := range txs {
244+ dump [nonce ] = append (dump [nonce ], newRPCPendingTransaction (tx ))
245+ }
246+ }
247+ content ["pending" ][account .Hex ()] = dump
248+ }
249+ // Flatten the queued transactions
250+ for account , batches := range queue {
251+ dump := make (map [string ][]* RPCTransaction )
252+ for nonce , txs := range batches {
253+ nonce := fmt .Sprintf ("%d" , nonce )
254+ for _ , tx := range txs {
255+ dump [nonce ] = append (dump [nonce ], newRPCPendingTransaction (tx ))
256+ }
257+ }
258+ content ["queued" ][account .Hex ()] = dump
259+ }
260+ return content
261+ }
262+
230263// Status returns the number of pending and queued transaction in the pool.
231264func (s * PublicTxPoolAPI ) Status () map [string ]* rpc.HexNumber {
232265 pending , queue := s .e .TxPool ().Stats ()
@@ -236,6 +269,47 @@ func (s *PublicTxPoolAPI) Status() map[string]*rpc.HexNumber {
236269 }
237270}
238271
272+ // Inspect retrieves the content of the transaction pool and flattens it into an
273+ // easily inspectable list.
274+ func (s * PublicTxPoolAPI ) Inspect () map [string ]map [string ]map [string ][]string {
275+ content := map [string ]map [string ]map [string ][]string {
276+ "pending" : make (map [string ]map [string ][]string ),
277+ "queued" : make (map [string ]map [string ][]string ),
278+ }
279+ pending , queue := s .e .TxPool ().Content ()
280+
281+ // Define a formatter to flatten a transaction into a string
282+ var format = func (tx * types.Transaction ) string {
283+ if to := tx .To (); to != nil {
284+ return fmt .Sprintf ("%s: %v wei + %v × %v gas" , tx .To ().Hex (), tx .Value (), tx .Gas (), tx .GasPrice ())
285+ }
286+ return fmt .Sprintf ("contract creation: %v wei + %v × %v gas" , tx .Value (), tx .Gas (), tx .GasPrice ())
287+ }
288+ // Flatten the pending transactions
289+ for account , batches := range pending {
290+ dump := make (map [string ][]string )
291+ for nonce , txs := range batches {
292+ nonce := fmt .Sprintf ("%d" , nonce )
293+ for _ , tx := range txs {
294+ dump [nonce ] = append (dump [nonce ], format (tx ))
295+ }
296+ }
297+ content ["pending" ][account .Hex ()] = dump
298+ }
299+ // Flatten the queued transactions
300+ for account , batches := range queue {
301+ dump := make (map [string ][]string )
302+ for nonce , txs := range batches {
303+ nonce := fmt .Sprintf ("%d" , nonce )
304+ for _ , tx := range txs {
305+ dump [nonce ] = append (dump [nonce ], format (tx ))
306+ }
307+ }
308+ content ["queued" ][account .Hex ()] = dump
309+ }
310+ return content
311+ }
312+
239313// PublicAccountAPI provides an API to access accounts managed by this node.
240314// It offers only methods that can retrieve accounts.
241315type PublicAccountAPI struct {
0 commit comments