Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions examples/node-custom-rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,31 @@ pub struct TxpoolExt<Pool> {
pool: Pool,
}

impl<Pool> TxpoolExt<Pool>
where
Pool: TransactionPool + Clone + 'static,
{
fn transaction_count_inner(&self) -> usize {
self.pool.pool_size().total
}

fn clear_txpool_inner(&self) {
let all_tx_hashes = self.pool.all_transaction_hashes();
self.pool.remove_transactions(all_tx_hashes);
}
}

#[cfg(not(test))]
impl<Pool> TxpoolExtApiServer for TxpoolExt<Pool>
where
Pool: TransactionPool + Clone + 'static,
{
fn transaction_count(&self) -> RpcResult<usize> {
Ok(self.pool.pool_size().total)
Ok(self.transaction_count_inner())
}

fn clear_txpool(&self) -> RpcResult<()> {
let all_tx_hashes = self.pool.all_transaction_hashes();
self.pool.remove_transactions(all_tx_hashes);
self.clear_txpool_inner();
Ok(())
}

Expand Down Expand Up @@ -155,12 +168,11 @@ mod tests {
Pool: TransactionPool + Clone + 'static,
{
fn transaction_count(&self) -> RpcResult<usize> {
Ok(self.pool.pool_size().total)
Ok(self.transaction_count_inner())
}

fn clear_txpool(&self) -> RpcResult<()> {
let all_tx_hashes = self.pool.all_transaction_hashes();
self.pool.remove_transactions(all_tx_hashes);
self.clear_txpool_inner();
Ok(())
}

Expand Down
Loading