From 0707cc7cb0a89fa1f720b462ae500fd5168fed9b Mon Sep 17 00:00:00 2001 From: Grigoriy Simonov Date: Tue, 13 Sep 2022 07:37:27 +0000 Subject: [PATCH] chore: move contract address and transaction data to call context --- --- a/Cargo.lock +++ b/Cargo.lock @@ -6360,7 +6360,7 @@ [[package]] name = "pallet-template-transaction-payment" version = "3.0.0" -source = "git+https://github.com/uniquenetwork/pallet-sponsoring?rev=9ee7d6e57e03a2575cbab79431774b56f170018e#9ee7d6e57e03a2575cbab79431774b56f170018e" +source = "git+https://github.com/uniquenetwork/pallet-sponsoring?branch=polkadot-v0.9.27#853766d6033ceb68a2bef196790b962dd0663a04" dependencies = [ "frame-benchmarking", "frame-support", @@ -12528,7 +12528,7 @@ [[package]] name = "up-sponsorship" version = "0.1.0" -source = "git+https://github.com/uniquenetwork/pallet-sponsoring?rev=9ee7d6e57e03a2575cbab79431774b56f170018e#9ee7d6e57e03a2575cbab79431774b56f170018e" +source = "git+https://github.com/uniquenetwork/pallet-sponsoring?branch=polkadot-v0.9.27#853766d6033ceb68a2bef196790b962dd0663a04" dependencies = [ "impl-trait-for-tuples", ] --- a/pallets/evm-contract-helpers/Cargo.toml +++ b/pallets/evm-contract-helpers/Cargo.toml @@ -21,7 +21,7 @@ # Unique pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } fp-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } -up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } # Locals evm-coder = { default-features = false, path = '../../crates/evm-coder' } --- a/pallets/evm-contract-helpers/src/eth.rs +++ b/pallets/evm-contract-helpers/src/eth.rs @@ -379,27 +379,26 @@ /// Bridge to pallet-sponsoring pub struct HelpersContractSponsoring(PhantomData<*const T>); -impl SponsorshipHandler), CallContext> +impl SponsorshipHandler for HelpersContractSponsoring { fn get_sponsor( who: &T::CrossAccountId, - call: &(H160, Vec), call_context: &CallContext, ) -> Option { - let (contract_address, _) = call; - let mode = >::sponsoring_mode(*contract_address); + let contract_address = call_context.contract_address; + let mode = >::sponsoring_mode(contract_address); if mode == SponsoringModeT::Disabled { return None; } - let sponsor = match >::get_sponsor(*contract_address) { + let sponsor = match >::get_sponsor(contract_address) { Some(sponsor) => sponsor, None => return None, }; if mode == SponsoringModeT::Allowlisted - && !>::allowed(*contract_address, *who.as_eth()) + && !>::allowed(contract_address, *who.as_eth()) { return None; } --- a/pallets/evm-transaction-payment/Cargo.toml +++ b/pallets/evm-transaction-payment/Cargo.toml @@ -17,7 +17,7 @@ pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } -up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev = "9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } fp-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } [dependencies.codec] --- a/pallets/evm-transaction-payment/src/lib.rs +++ b/pallets/evm-transaction-payment/src/lib.rs @@ -35,6 +35,10 @@ /// Contains call data pub struct CallContext { + /// Contract address + pub contract_address: H160, + /// Transaction data + pub input: Vec, /// Max fee for transaction - gasLimit * gasPrice pub max_fee: U256, } @@ -42,11 +46,7 @@ #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::account::Config { /// Loosly-coupled handlers for evm call sponsoring - type EvmSponsorshipHandler: SponsorshipHandler< - Self::CrossAccountId, - (H160, Vec), - CallContext, - >; + type EvmSponsorshipHandler: SponsorshipHandler; } #[pallet::pallet] @@ -65,12 +65,12 @@ match reason { WithdrawReason::Call { target, input } => { let origin_sub = T::CrossAccountId::from_eth(origin); - let call_context = CallContext { max_fee }; - T::EvmSponsorshipHandler::get_sponsor( - &origin_sub, - &(*target, input.clone()), - &call_context, - ) + let call_context = CallContext { + contract_address: *target, + input: input.clone(), + max_fee, + }; + T::EvmSponsorshipHandler::get_sponsor(&origin_sub, &call_context) } _ => None, } @@ -79,12 +79,12 @@ /// Implements sponsoring for evm calls performed from pallet-evm (via api.tx.ethereum.transact/api.tx.evm.call) pub struct BridgeSponsorshipHandler(PhantomData); -impl SponsorshipHandler for BridgeSponsorshipHandler +impl SponsorshipHandler for BridgeSponsorshipHandler where T: Config + pallet_evm::Config, C: IsSubType>, { - fn get_sponsor(who: &T::AccountId, call: &C, _call_context: &()) -> Option { + fn get_sponsor(who: &T::AccountId, call: &C) -> Option { match call.is_sub_type()? { pallet_evm::Call::call { source, @@ -101,16 +101,16 @@ .ok()?; let who = T::CrossAccountId::from_sub(who.clone()); let max_fee = max_fee_per_gas.saturating_mul((*gas_limit).into()); - let call_context = CallContext { max_fee }; + let call_context = CallContext { + contract_address: *target, + input: input.clone(), + max_fee, + }; // Effects from EvmSponsorshipHandler are applied by pallet_evm::runner // TODO: Should we implement simulation mode (test, but do not apply effects) in `up-sponsorship`? let sponsor = frame_support::storage::with_transaction(|| { TransactionOutcome::Rollback(Ok::<_, DispatchError>( - T::EvmSponsorshipHandler::get_sponsor( - &who, - &(*target, input.clone()), - &call_context, - ), + T::EvmSponsorshipHandler::get_sponsor(&who, &call_context), )) }) // FIXME: it may fail with DispatchError in case of depth limit --- a/pallets/scheduler/Cargo.toml +++ b/pallets/scheduler/Cargo.toml @@ -24,7 +24,7 @@ sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.27' } frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" } -up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } log = { version = "0.4.14", default-features = false } [dev-dependencies] --- a/pallets/unique/src/eth/mod.rs +++ b/pallets/unique/src/eth/mod.rs @@ -21,25 +21,23 @@ use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*}; use frame_support::traits::Get; use pallet_common::{ - CollectionById, CollectionHandle, + CollectionById, dispatch::CollectionDispatch, erc::{ CollectionHelpersEvents, static_property::{key, value as property_value}, }, - Pallet as PalletCommon, }; use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder}; use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult}; -use pallet_evm_coder_substrate::dispatch_to_evm; use up_data_structs::{ CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData, - CollectionMode, PropertyKeyPermission, PropertyPermission, PropertyScope, PropertyValue, + CollectionMode, PropertyValue, }; use crate::{Config, SelfWeightOf, weights::WeightInfo}; -use sp_std::{vec, vec::Vec}; +use sp_std::vec::Vec; use alloc::format; /// See [`CollectionHelpersCall`] --- a/runtime/common/ethereum/sponsoring.rs +++ b/runtime/common/ethereum/sponsoring.rs @@ -34,7 +34,6 @@ }; use pallet_refungible::Config as RefungibleConfig; use pallet_unique::Config as UniqueConfig; -use sp_core::H160; use sp_std::prelude::*; use up_data_structs::{CollectionMode, CreateItemData, CreateNftData, TokenId}; use up_sponsorship::SponsorshipHandler; @@ -48,18 +47,16 @@ pub struct UniqueEthSponsorshipHandler(PhantomData<*const T>); impl - SponsorshipHandler), CallContext> - for UniqueEthSponsorshipHandler + SponsorshipHandler for UniqueEthSponsorshipHandler { fn get_sponsor( who: &T::CrossAccountId, - call: &(H160, Vec), - _fee_limit: &CallContext, + call_context: &CallContext, ) -> Option { - let collection_id = map_eth_to_id(&call.0)?; + let collection_id = map_eth_to_id(&call_context.contract_address)?; let collection = >::new(collection_id)?; let sponsor = collection.sponsorship.sponsor()?.clone(); - let (method_id, mut reader) = AbiReader::new_call(&call.1).ok()?; + let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?; Some(T::CrossAccountId::from_sub(match &collection.mode { CollectionMode::NFT => { let call = >::parse(method_id, &mut reader).ok()??; --- a/runtime/common/sponsoring.rs +++ b/runtime/common/sponsoring.rs @@ -224,12 +224,12 @@ } pub struct UniqueSponsorshipHandler(PhantomData); -impl SponsorshipHandler for UniqueSponsorshipHandler +impl SponsorshipHandler for UniqueSponsorshipHandler where T: Config, C: IsSubType>, { - fn get_sponsor(who: &T::AccountId, call: &C, _call_context: &()) -> Option { + fn get_sponsor(who: &T::AccountId, call: &C) -> Option { match IsSubType::>::is_sub_type(call)? { UniqueCall::set_token_properties { collection_id, --- a/runtime/opal/Cargo.toml +++ b/runtime/opal/Cargo.toml @@ -431,7 +431,7 @@ pallet-proxy-rmrk-equip = { default-features = false, path = "../../pallets/proxy-rmrk-equip", package = "pallet-rmrk-equip" } pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false } # pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' } -pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" } +pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" } pallet-evm-migration = { path = '../../pallets/evm-migration', default-features = false } pallet-evm-contract-helpers = { path = '../../pallets/evm-contract-helpers', default-features = false } pallet-evm-transaction-payment = { path = '../../pallets/evm-transaction-payment', default-features = false } @@ -442,7 +442,7 @@ fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } evm-coder = { default-features = false, path = '../../crates/evm-coder' } -up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } ################################################################################ # Build Dependencies --- a/runtime/quartz/Cargo.toml +++ b/runtime/quartz/Cargo.toml @@ -432,7 +432,7 @@ pallet-proxy-rmrk-equip = { default-features = false, path = "../../pallets/proxy-rmrk-equip", package = "pallet-rmrk-equip" } pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false } # pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' } -pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" } +pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" } pallet-evm-migration = { path = '../../pallets/evm-migration', default-features = false } pallet-evm-contract-helpers = { path = '../../pallets/evm-contract-helpers', default-features = false } pallet-evm-transaction-payment = { path = '../../pallets/evm-transaction-payment', default-features = false } @@ -443,7 +443,7 @@ fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } evm-coder = { default-features = false, path = '../../crates/evm-coder' } -up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } ################################################################################ # Build Dependencies --- a/runtime/tests/Cargo.toml +++ b/runtime/tests/Cargo.toml @@ -43,4 +43,4 @@ scale-info = "*" evm-coder = { default-features = false, path = '../../crates/evm-coder' } -up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } --- a/runtime/unique/Cargo.toml +++ b/runtime/unique/Cargo.toml @@ -425,7 +425,7 @@ pallet-proxy-rmrk-equip = { default-features = false, path = "../../pallets/proxy-rmrk-equip", package = "pallet-rmrk-equip" } pallet-unique-scheduler = { path = '../../pallets/scheduler', default-features = false } # pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' } -pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" } +pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" } pallet-evm-migration = { path = '../../pallets/evm-migration', default-features = false } pallet-evm-contract-helpers = { path = '../../pallets/evm-contract-helpers', default-features = false } pallet-evm-transaction-payment = { path = '../../pallets/evm-transaction-payment', default-features = false } @@ -437,7 +437,7 @@ fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } fp-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier", rev = "89a37c5a489f426cc7a42d7b94019974093a052d" } evm-coder = { default-features = false, path = '../../crates/evm-coder' } -up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", rev="9ee7d6e57e03a2575cbab79431774b56f170018e" } +up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" } ################################################################################ # Build Dependencies -- gitstuff