Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement get_pendingTransactions #1540

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions client/rpc-core/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ pub trait EthApi {
number_or_hash: Option<BlockNumberOrHash>,
) -> RpcResult<U256>;

/// Returns all pending transactions.
#[method(name = "eth_pendingTransactions")]
async fn pending_transactions(&self) -> RpcResult<Vec<Transaction>>;

// ########################################################################
// Fee
// ########################################################################
Expand Down
4 changes: 4 additions & 0 deletions client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ where
self.transaction_count(address, number_or_hash).await
}

async fn pending_transactions(&self) -> RpcResult<Vec<Transaction>> {
self.pending_transactions().await
}

async fn code_at(
&self,
address: H160,
Expand Down
45 changes: 45 additions & 0 deletions client/rpc/src/eth/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,51 @@ where
.await
}

pub async fn pending_transactions(&self) -> RpcResult<Vec<Transaction>> {
let ready = self
.graph
.validated_pool()
.ready()
.map(|in_pool_tx| in_pool_tx.clone())
.collect();

let future = self
.graph
.validated_pool()
.futures()
.iter()
.map(|(_, extrinsic)| extrinsic.clone())
.collect();

let mut all_extrinsics = Vec::new();
all_extrinsics.extend(ready);
all_extrinsics.extend(future);

let best_block = self.client.info().best_hash;
let api = self.client.runtime_api();

let api_version = api
.api_version::<dyn EthereumRuntimeRPCApi<B>>(best_block)
.map_err(|err| internal_err(format!("Failed to get API version: {}", err)))?
.ok_or_else(|| internal_err("Failed to get API version"))?;

let ethereum_txs = if api_version > 1 {
api.extrinsic_filter(best_block, all_extrinsics)
.map_err(|err| internal_err(format!("Runtime call failed: {}", err)))?
} else {
#[allow(deprecated)]
let legacy = api
.extrinsic_filter_before_version_2(best_block, all_extrinsics)
.map_err(|err| internal_err(format!("Runtime call failed: {}", err)))?;
legacy.into_iter().map(|tx| tx.into()).collect()
};

Ok(ethereum_txs
.into_iter()
.map(|tx| Transaction::build_from(tx.recover_from().unwrap_or_default(), &tx))
.collect())
}

fn convert_transaction(
&self,
block_hash: B::Hash,
Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
future::ready(res.map(|(block, receipts)| PubSubResult::logs(block, receipts, params)))
}

fn pending_transaction(&self, hash: &TxHash<P>) -> future::Ready<Option<PubSubResult>> {
fn pending_transactions(&self, hash: &TxHash<P>) -> future::Ready<Option<PubSubResult>> {
let res = if let Some(xt) = self.pool.ready_transaction(hash) {
let best_block = self.client.info().best_hash;

Expand Down Expand Up @@ -263,7 +263,7 @@ where
let pool = pubsub.pool.clone();
let stream = pool
.import_notification_stream()
.filter_map(move |hash| pubsub.pending_transaction(&hash));
.filter_map(move |hash| pubsub.pending_transactions(&hash));
PendingSubscription::from(pending)
.pipe_from_stream(stream, BoundedVecDeque::new(16))
.await;
Expand Down
9 changes: 6 additions & 3 deletions frame/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ mod proof_size_test {
let expected_proof_size = ((read_account_metadata * 2)
+ reading_contract_len
+ reading_main_contract_len
+ is_empty_check + increase_nonce) as u64;
+ is_empty_check
+ increase_nonce) as u64;

let actual_proof_size = result
.weight_info
Expand Down Expand Up @@ -295,7 +296,8 @@ mod proof_size_test {
let expected_proof_size = (basic_account_size
+ read_account_metadata
+ reading_main_contract_len
+ is_empty_check + increase_nonce) as u64;
+ is_empty_check
+ increase_nonce) as u64;

let actual_proof_size = result
.weight_info
Expand Down Expand Up @@ -520,7 +522,8 @@ mod proof_size_test {
let expected_proof_size = ((read_account_metadata * 2)
+ reading_callee_contract_len
+ reading_main_contract_len
+ is_empty_check + increase_nonce) as u64;
+ is_empty_check
+ increase_nonce) as u64;

let actual_proof_size = result
.weight_info
Expand Down
Loading