Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

feat: add txpool namespace RPC methods #146

Merged
merged 9 commits into from
Jun 21, 2021
7 changes: 7 additions & 0 deletions ethereum/rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
EthNamespace = "eth"
PersonalNamespace = "personal"
NetNamespace = "net"
TxPoolNamespace = "txpool"

apiVersion = "1.0"
)
Expand Down Expand Up @@ -57,5 +58,11 @@ func GetRPCAPIs(clientCtx client.Context, tmWSClient *rpcclient.WSClient) []rpc.
Service: NewPersonalAPI(ethAPI),
Public: true,
},
{
Namespace: TxPoolNamespace,
Version: apiVersion,
Service: NewPublicTxPoolAPI(backend),
Public: true,
},
}
}
12 changes: 12 additions & 0 deletions ethereum/rpc/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type Backend interface {
// Used by pending transaction filter
PendingTransactions() ([]*types.RPCTransaction, error)

// Used by txpool content
TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error)

// Used by log filter
GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error)
BloomStatus() (uint64, uint64)
Expand Down Expand Up @@ -274,6 +277,15 @@ func (e *EVMBackend) PendingTransactions() ([]*types.RPCTransaction, error) {
return []*types.RPCTransaction{}, nil
}

// TxPoolContent returns the transactions contained within the transaction pool
func (e *EVMBackend) TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) {
content := map[string]map[string]map[string]*types.RPCTransaction{
"pending": make(map[string]map[string]*types.RPCTransaction),
"queued": make(map[string]map[string]*types.RPCTransaction),
}
return content, nil
}

// GetLogs returns all the logs from all the ethereum transactions in a block.
func (e *EVMBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error) {
// NOTE: we query the state in case the tx result logs are not persisted after an upgrade.
Expand Down
25 changes: 25 additions & 0 deletions ethereum/rpc/txpool_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package rpc

import (
"github.com/cosmos/ethermint/ethereum/rpc/types"
log "github.com/xlab/suplog"
)

type PublicTxPoolAPI struct {
crypto-facs marked this conversation as resolved.
Show resolved Hide resolved
logger log.Logger
backend Backend
}

func NewPublicTxPoolAPI(backend Backend) *PublicTxPoolAPI {
crypto-facs marked this conversation as resolved.
Show resolved Hide resolved
return &PublicTxPoolAPI{
logger: log.WithField("module", "txpool"),
backend: backend,
}
}

// Content returns the transactions contained within the transaction pool
// NOTE: For more info about the current status of this endpoint https://github.com/tharsis/ethermint/issues/124
func (api *PublicTxPoolAPI) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) {
api.logger.Debug("txpool_content")
return api.backend.TxPoolContent()
}