Skip to content

Commit

Permalink
Use runtime api version in NewPendingTransactions subscriptions (pa…
Browse files Browse the repository at this point in the history
…ritytech#597)

* Versioned runtime fixes 2 (paritytech#38)

(cherry picked from commit 7e4fd790f7592b77fab0b9007860d98335b2f133)
(cherry picked from commit a40e29a63f3923730e0e5807ddcc63aff5255d87)

* fmt
  • Loading branch information
tgmichel authored Mar 21, 2022
1 parent 55c0c80 commit 165c000
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions client/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use std::{collections::BTreeMap, iter, marker::PhantomData, sync::Arc};

use ethereum::BlockV2 as EthereumBlock;
use ethereum::{BlockV2 as EthereumBlock, TransactionV2 as EthereumTransaction};
use ethereum_types::{H256, U256};
use futures::{FutureExt as _, SinkExt as _, StreamExt as _};
use jsonrpc_core::Result as JsonRpcResult;
Expand Down Expand Up @@ -51,6 +51,8 @@ use fc_rpc_core::{
};
use fp_rpc::EthereumRuntimeRPCApi;

use sp_api::ApiExt;

use crate::{frontier_backend_client, overrides::OverrideHandle};

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -335,11 +337,34 @@ where
.filter_map(move |txhash| {
if let Some(xt) = pool.ready_transaction(&txhash) {
let best_block: BlockId<B> = BlockId::Hash(client.info().best_hash);
let res = match client
.runtime_api()
.extrinsic_filter(&best_block, vec![xt.data().clone()])

let api = client.runtime_api();

let api_version = if let Ok(Some(api_version)) =
api.api_version::<dyn EthereumRuntimeRPCApi<B>>(&best_block)
{
Ok(txs) => {
api_version
} else {
return futures::future::ready(None);
};

let xts = vec![xt.data().clone()];

let txs: Option<Vec<EthereumTransaction>> = if api_version > 1 {
api.extrinsic_filter(&best_block, xts).ok()
} else {
#[allow(deprecated)]
if let Ok(legacy) =
api.extrinsic_filter_before_version_2(&best_block, xts)
{
Some(legacy.into_iter().map(|tx| tx.into()).collect())
} else {
None
}
};

let res = match txs {
Some(txs) => {
if txs.len() == 1 {
Some(txs[0].clone())
} else {
Expand Down

0 comments on commit 165c000

Please sign in to comment.