client/rpc/impls/cfx/
pool.rs

1// Copyright 2020 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use crate::{
6    common::delegate_convert,
7    rpc::{
8        impls::common::RpcImpl as CommonImpl,
9        traits::pool::TransactionPool,
10        types::{
11            AccountPendingInfo, AccountPendingTransactions, RpcAddress,
12            Transaction as RpcTransaction, TxPoolPendingNonceRange,
13            TxPoolStatus, TxWithPoolInfo,
14        },
15    },
16};
17use cfx_types::{H256, U256, U64};
18use delegate::delegate;
19use jsonrpc_core::{BoxFuture, Result as JsonRpcResult};
20use std::sync::Arc;
21
22pub struct TransactionPoolHandler {
23    common: Arc<CommonImpl>,
24}
25
26impl TransactionPoolHandler {
27    pub fn new(common: Arc<CommonImpl>) -> Self {
28        TransactionPoolHandler { common }
29    }
30}
31
32impl TransactionPool for TransactionPoolHandler {
33    delegate! {
34        to self.common {
35            fn txpool_status(&self) -> JsonRpcResult<TxPoolStatus>;
36            fn txpool_next_nonce(&self, address: RpcAddress) -> JsonRpcResult<U256>;
37            fn txpool_pending_nonce_range(&self, address: RpcAddress) -> JsonRpcResult<TxPoolPendingNonceRange>;
38            fn txpool_tx_with_pool_info(&self, hash: H256) -> JsonRpcResult<TxWithPoolInfo>;
39            fn txpool_transaction_by_address_and_nonce(&self, address: RpcAddress, nonce: U256) -> JsonRpcResult<Option<RpcTransaction>>;
40            fn account_pending_info(&self, addr: RpcAddress) -> BoxFuture<JsonRpcResult<Option<AccountPendingInfo>>>;
41            fn account_pending_transactions(&self, address: RpcAddress, maybe_start_nonce: Option<U256>, maybe_limit: Option<U64>) -> BoxFuture<JsonRpcResult<AccountPendingTransactions>>;
42        }
43    }
44}