diff --git a/examples/node-custom-rpc/src/main.rs b/examples/node-custom-rpc/src/main.rs index 7ab271b4cc5..2e2768c9f16 100644 --- a/examples/node-custom-rpc/src/main.rs +++ b/examples/node-custom-rpc/src/main.rs @@ -96,18 +96,31 @@ pub struct TxpoolExt { pool: Pool, } +impl TxpoolExt +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 TxpoolExtApiServer for TxpoolExt where Pool: TransactionPool + Clone + 'static, { fn transaction_count(&self) -> RpcResult { - 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(()) } @@ -155,12 +168,11 @@ mod tests { Pool: TransactionPool + Clone + 'static, { fn transaction_count(&self) -> RpcResult { - 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(()) }