Skip to content

Commit

Permalink
Versioned runtime fixes 2 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel authored Feb 7, 2022
1 parent 4cf13fc commit 7e4fd79
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions client/rpc/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto};
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 fc_rpc_core::{
types::{
Expand All @@ -54,6 +54,8 @@ use jsonrpc_core::Result as JsonRpcResult;

use sc_network::{ExHashT, NetworkService};

use sp_api::ApiExt;

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

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -348,11 +350,32 @@ 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()])
{
Ok(txs) => {

let api = client.runtime_api();

let api_version =
if let Ok(Some(api_version)) = api.api_version::<dyn EthereumRuntimeRPCApi<B>>(&best_block) {
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 7e4fd79

Please sign in to comment.