MCPcopy Create free account
hub / github.com/CPChain/chain / Inspect

Method Inspect

internal/cpcapi/api.go:140–171  ·  view source on GitHub ↗

Inspect retrieves the content of the transaction pool and flattens it into an easily inspectable list.

()

Source from the content-addressed store, hash-verified

138// Inspect retrieves the content of the transaction pool and flattens it into an
139// easily inspectable list.
140func (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.

Callers

nothing calls this directly

Calls 6

TxPoolContentMethod · 0.65
ToMethod · 0.65
ValueMethod · 0.65
GasMethod · 0.65
GasPriceMethod · 0.65
NonceMethod · 0.65

Tested by

no test coverage detected