#188 Added EVM RPC to the node (#198)

* #188 added RPC node to enable interaction
This commit is contained in:
Nikita Khateev
2024-05-28 18:29:06 +04:00
committed by GitHub
parent 3132574062
commit 135e186816
14 changed files with 1284 additions and 87 deletions
+3
View File
@@ -86,6 +86,7 @@ parachains-common = { workspace = true }
fp-account = { workspace = true }
fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true, features = [ "serde" ] }
pallet-base-fee = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
@@ -112,6 +113,7 @@ std = [
"fp-account/std",
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"frame-benchmarking?/std",
"frame-executive/std",
"frame-support/std",
@@ -211,6 +213,7 @@ try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
"fp-self-contained/try-runtime",
"frame-executive/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
+86 -5
View File
@@ -66,10 +66,10 @@ pub use sp_runtime::BuildStorage;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, Get, IdentifyAccount, IdentityLookup,
UniqueSaturatedInto, Verify,
AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, Get,
IdentifyAccount, IdentityLookup, PostDispatchInfoOf, UniqueSaturatedInto, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
ApplyExtrinsicResult, ConsensusEngineId, RuntimeDebug,
};
pub use sp_runtime::{MultiAddress, Perbill, Permill};
@@ -139,7 +139,63 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
impl fp_self_contained::SelfContainedCall for RuntimeCall {
type SignedInfo = H160;
fn is_self_contained(&self) -> bool {
match self {
RuntimeCall::Ethereum(call) => call.is_self_contained(),
_ => false,
}
}
fn check_self_contained(&self) -> Option<Result<Self::SignedInfo, TransactionValidityError>> {
match self {
RuntimeCall::Ethereum(call) => call.check_self_contained(),
_ => None,
}
}
fn validate_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<TransactionValidity> {
match self {
RuntimeCall::Ethereum(call) => call.validate_self_contained(info, dispatch_info, len),
_ => None,
}
}
fn pre_dispatch_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), TransactionValidityError>> {
match self {
RuntimeCall::Ethereum(call) =>
call.pre_dispatch_self_contained(info, dispatch_info, len),
_ => None,
}
}
fn apply_self_contained(
self,
info: Self::SignedInfo,
) -> Option<sp_runtime::DispatchResultWithInfo<PostDispatchInfoOf<Self>>> {
match self {
call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) =>
Some(call.dispatch(RuntimeOrigin::from(
pallet_ethereum::RawOrigin::EthereumTransaction(info),
))),
_ => None,
}
}
}
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
@@ -923,6 +979,31 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorSession<F> {
}
}
#[derive(Clone)]
pub struct TransactionConverter;
impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {
fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {
UncheckedExtrinsic::new_unsigned(
pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),
)
}
}
impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {
fn convert_transaction(
&self,
transaction: pallet_ethereum::Transaction,
) -> opaque::UncheckedExtrinsic {
let extrinsic = UncheckedExtrinsic::new_unsigned(
pallet_ethereum::Call::<Runtime>::transact { transaction }.into(),
);
let encoded = extrinsic.encode();
opaque::UncheckedExtrinsic::decode(&mut &encoded[..])
.expect("Encoded extrinsic is always valid")
}
}
// Create the runtime by composing the FRAME pallets that were previously
// configured.
construct_runtime!(
@@ -1288,7 +1369,7 @@ impl_runtime_apis! {
fn extrinsic_filter(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> Vec<EthereumTransaction> {
xts.into_iter().filter_map(|xt| match xt.function {
xts.into_iter().filter_map(|xt| match xt.0.function {
RuntimeCall::Ethereum(transact { transaction }) => Some(transaction),
_ => None
}).collect::<Vec<EthereumTransaction>>()