Skip to content

Commit

Permalink
Use impl_self_contained_call (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest authored Feb 2, 2023
1 parent 1537527 commit dae3f31
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 184 deletions.
74 changes: 74 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,77 @@ pub const fn darwinia_deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 100 * UNIT + (bytes as Balance) * 100 * MICROUNIT
// items as Balance * 100 * UNIT + (bytes as Balance) * 100 * MILLIUNIT
}

#[macro_export]
macro_rules! impl_self_contained_call {
() => {
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,
sp_runtime::transaction_validity::TransactionValidityError,
>,
> {
match self {
RuntimeCall::Ethereum(call) => call.check_self_contained(),
_ => None,
}
}

fn validate_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &sp_runtime::traits::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: &sp_runtime::traits::DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), sp_runtime::transaction_validity::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<sp_runtime::traits::PostDispatchInfoOf<Self>>,
> {
// substrate
use sp_runtime::traits::Dispatchable;

match self {
call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) =>
Some(call.dispatch(RuntimeOrigin::from(
pallet_ethereum::RawOrigin::EthereumTransaction(info),
))),
_ => None,
}
}
}
};
}
62 changes: 1 addition & 61 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,67 +144,7 @@ where
}
}

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, sp_runtime::transaction_validity::TransactionValidityError>>
{
match self {
RuntimeCall::Ethereum(call) => call.check_self_contained(),
_ => None,
}
}

fn validate_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &sp_runtime::traits::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: &sp_runtime::traits::DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), sp_runtime::transaction_validity::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<sp_runtime::traits::PostDispatchInfoOf<Self>>> {
// substrate
use sp_runtime::traits::Dispatchable;

match self {
call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) =>
Some(call.dispatch(RuntimeOrigin::from(
pallet_ethereum::RawOrigin::EthereumTransaction(info),
))),
_ => None,
}
}
}
impl_self_contained_call!();

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
Expand Down
64 changes: 2 additions & 62 deletions runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,74 +144,14 @@ where
}
}

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, sp_runtime::transaction_validity::TransactionValidityError>>
{
match self {
RuntimeCall::Ethereum(call) => call.check_self_contained(),
_ => None,
}
}

fn validate_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &sp_runtime::traits::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: &sp_runtime::traits::DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), sp_runtime::transaction_validity::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<sp_runtime::traits::PostDispatchInfoOf<Self>>> {
// substrate
use sp_runtime::traits::Dispatchable;

match self {
call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) =>
Some(call.dispatch(RuntimeOrigin::from(
pallet_ethereum::RawOrigin::EthereumTransaction(info),
))),
_ => None,
}
}
}

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}

impl_self_contained_call!();

// Create the runtime by composing the FRAME pallets that were previously configured.
frame_support::construct_runtime! {
pub enum Runtime where
Expand Down
62 changes: 1 addition & 61 deletions runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,67 +141,7 @@ where
}
}

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, sp_runtime::transaction_validity::TransactionValidityError>>
{
match self {
RuntimeCall::Ethereum(call) => call.check_self_contained(),
_ => None,
}
}

fn validate_self_contained(
&self,
info: &Self::SignedInfo,
dispatch_info: &sp_runtime::traits::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: &sp_runtime::traits::DispatchInfoOf<RuntimeCall>,
len: usize,
) -> Option<Result<(), sp_runtime::transaction_validity::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<sp_runtime::traits::PostDispatchInfoOf<Self>>> {
// substrate
use sp_runtime::traits::Dispatchable;

match self {
call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) =>
Some(call.dispatch(RuntimeOrigin::from(
pallet_ethereum::RawOrigin::EthereumTransaction(info),
))),
_ => None,
}
}
}
impl_self_contained_call!();

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
Expand Down

0 comments on commit dae3f31

Please sign in to comment.