2022-10-11 12:34:32 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-10-31 02:20:58 +00:00
|
|
|
|
2022-10-11 12:34:32 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpctest/rpctest"
|
|
|
|
)
|
|
|
|
|
2023-03-30 21:49:28 +00:00
|
|
|
func TxpoolContent(reqId int) (int, int, int, error) {
|
2022-11-03 02:45:36 +00:00
|
|
|
var (
|
|
|
|
b rpctest.EthTxPool
|
|
|
|
pending map[string]interface{}
|
|
|
|
queued map[string]interface{}
|
2023-03-30 21:49:28 +00:00
|
|
|
baseFee map[string]interface{}
|
2022-11-03 02:45:36 +00:00
|
|
|
)
|
|
|
|
|
2022-10-11 12:34:32 +00:00
|
|
|
reqGen := initialiseRequestGenerator(reqId)
|
|
|
|
|
2022-10-30 12:54:09 +00:00
|
|
|
if res := reqGen.Erigon("txpool_content", reqGen.TxpoolContent(), &b); res.Err != nil {
|
2023-03-30 21:49:28 +00:00
|
|
|
return len(pending), len(queued), len(baseFee), fmt.Errorf("failed to fetch txpool content: %v", res.Err)
|
2022-10-11 12:34:32 +00:00
|
|
|
}
|
|
|
|
|
2022-11-03 02:45:36 +00:00
|
|
|
resp := b.Result.(map[string]interface{})
|
|
|
|
|
2023-03-30 21:49:28 +00:00
|
|
|
pendingLen := 0
|
|
|
|
queuedLen := 0
|
|
|
|
baseFeeLen := 0
|
2022-11-03 02:45:36 +00:00
|
|
|
|
|
|
|
if resp["pending"] != nil {
|
|
|
|
pending = resp["pending"].(map[string]interface{})
|
2023-03-30 21:49:28 +00:00
|
|
|
for _, txs := range pending { // iterate over senders
|
|
|
|
pendingLen += len(txs.(map[string]interface{}))
|
|
|
|
}
|
2022-11-03 02:45:36 +00:00
|
|
|
}
|
2023-03-30 21:49:28 +00:00
|
|
|
|
2022-11-03 02:45:36 +00:00
|
|
|
if resp["queue"] != nil {
|
|
|
|
queued = resp["queue"].(map[string]interface{})
|
2023-03-30 21:49:28 +00:00
|
|
|
for _, txs := range pending {
|
|
|
|
queuedLen += len(txs.(map[string]interface{}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp["baseFee"] != nil {
|
|
|
|
baseFee = resp["baseFee"].(map[string]interface{})
|
|
|
|
for _, txs := range baseFee {
|
|
|
|
baseFeeLen += len(txs.(map[string]interface{}))
|
|
|
|
}
|
2022-10-11 12:34:32 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 21:49:28 +00:00
|
|
|
return pendingLen, queuedLen, baseFeeLen, nil
|
2022-10-11 12:34:32 +00:00
|
|
|
}
|