Inspect retrieves the content of the transaction pool and flattens it into an easily inspectable list.
()
| 138 | // Inspect retrieves the content of the transaction pool and flattens it into an |
| 139 | // easily inspectable list. |
| 140 | func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string { |
| 141 | content := map[string]map[string]map[string]string{ |
| 142 | "pending": make(map[string]map[string]string), |
| 143 | "queued": make(map[string]map[string]string), |
| 144 | } |
| 145 | pending, queue := s.b.TxPoolContent() |
| 146 | |
| 147 | // Define a formatter to flatten a transaction into a string |
| 148 | var format = func(tx *types.Transaction) string { |
| 149 | if to := tx.To(); to != nil { |
| 150 | return fmt.Sprintf("%s: %v wei + %v gas × %v wei", tx.To().Hex(), tx.Value(), tx.Gas(), tx.GasPrice()) |
| 151 | } |
| 152 | return fmt.Sprintf("contract creation: %v wei + %v gas × %v wei", tx.Value(), tx.Gas(), tx.GasPrice()) |
| 153 | } |
| 154 | // Flatten the pending transactions |
| 155 | for account, txs := range pending { |
| 156 | dump := make(map[string]string) |
| 157 | for _, tx := range txs { |
| 158 | dump[fmt.Sprintf("%d", tx.Nonce())] = format(tx) |
| 159 | } |
| 160 | content["pending"][account.Hex()] = dump |
| 161 | } |
| 162 | // Flatten the queued transactions |
| 163 | for account, txs := range queue { |
| 164 | dump := make(map[string]string) |
| 165 | for _, tx := range txs { |
| 166 | dump[fmt.Sprintf("%d", tx.Nonce())] = format(tx) |
| 167 | } |
| 168 | content["queued"][account.Hex()] = dump |
| 169 | } |
| 170 | return content |
| 171 | } |
| 172 | |
| 173 | // PublicAccountAPI provides an API to access accounts managed by this node. |
| 174 | // It offers only methods that can retrieve accounts. |