Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions runtime/mainnet/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ use alloc::vec::Vec;

use codec::Encode;
use frame_support::{
dispatch::DispatchInfo,
genesis_builder_helper::{build_state, get_preset},
traits::{
nonfungibles_v2::Inspect,
tokens::{Fortitude::Polite, Preservation::Preserve},
},
weights::{Weight, WeightToFee as _},
};
use pallet_revive::AddressMapper;
use pallet_revive::{evm::runtime::EthExtra, AddressMapper};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_runtime::{
traits::Block as BlockT,
traits::{Block as BlockT, TransactionExtension},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand All @@ -32,8 +33,8 @@ use xcm_runtime_apis::{
// Local module imports
use super::{
config::{monetary::fee::WeightToFee, system::RuntimeBlockWeights, xcm as xcm_config},
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EventRecord, Executive,
ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EthExtraImpl, EventRecord,
Executive, ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
PolkadotXcm, Revive, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin,
SessionKeys, System, TransactionPayment, UncheckedExtrinsic, VERSION,
};
Expand Down Expand Up @@ -406,35 +407,26 @@ impl_runtime_apis! {
System::account_nonce(account)
}

fn eth_transact(
from: H160,
dest: Option<H160>,
value: Balance,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::EthContractResult<Balance>
fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
{
use pallet_revive::AddressMapper;
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);

let encoded_size = |pallet_call| {
let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo| {
let call = RuntimeCall::Revive(pallet_call);
dispatch_info.extension_weight = EthExtraImpl::get_eth_extension(0, 0u32.into()).weight(&call);
let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();
uxt.encoded_size() as u32

pallet_transaction_payment::Pallet::<Runtime>::compute_fee(
uxt.encoded_size() as u32,
&dispatch_info,
0u32.into(),
)
};

Revive::bare_eth_transact(
origin,
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
encoded_size,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
tx,
blockweights.max_block,
tx_fee,
)
}

Expand All @@ -451,7 +443,7 @@ impl_runtime_apis! {
dest,
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
Expand All @@ -472,7 +464,7 @@ impl_runtime_apis! {
RuntimeOrigin::signed(origin),
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
code,
data,
salt,
Expand Down
46 changes: 20 additions & 26 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use cumulus_primitives_core::AggregateMessageOrigin;
use cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim;
use frame_metadata_hash_extension::CheckMetadataHash;
use frame_support::{
dispatch::DispatchClass,
dispatch::{DispatchClass, DispatchInfo},
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
Expand All @@ -52,7 +52,10 @@ use pallet_api::{fungibles, messaging};
use pallet_balances::Call as BalancesCall;
use pallet_ismp::offchain::{Leaf, Proof, ProofKeys};
use pallet_nfts_sdk as pallet_nfts;
use pallet_revive::{evm::H160, AddressMapper};
use pallet_revive::{
evm::{runtime::EthExtra, H160},
AddressMapper,
};
use pallet_transaction_payment::ChargeTransactionPayment;
// Polkadot imports
use polkadot_runtime_common::SlowAdjustingFeeUpdate;
Expand All @@ -69,7 +72,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256};
pub use sp_runtime::BuildStorage;
use sp_runtime::{
generic, impl_opaque_keys,
traits::{BlakeTwo256, Block as BlockT, Get, IdentifyAccount, Verify},
traits::{BlakeTwo256, Block as BlockT, Get, IdentifyAccount, TransactionExtension, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -693,35 +696,26 @@ impl_runtime_apis! {
System::account_nonce(account)
}

fn eth_transact(
from: H160,
dest: Option<H160>,
value: Balance,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::EthContractResult<Balance>
fn eth_transact(tx: pallet_revive::evm::GenericTransaction) -> Result<pallet_revive::EthTransactInfo<Balance>, pallet_revive::EthTransactError>
{
use pallet_revive::AddressMapper;
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);

let encoded_size = |pallet_call| {
let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo| {
let call = RuntimeCall::Revive(pallet_call);
dispatch_info.extension_weight = EthExtraImpl::get_eth_extension(0, 0u32.into()).weight(&call);
let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();
uxt.encoded_size() as u32

pallet_transaction_payment::Pallet::<Runtime>::compute_fee(
uxt.encoded_size() as u32,
&dispatch_info,
0u32.into(),
)
};

Revive::bare_eth_transact(
origin,
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
encoded_size,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
tx,
blockweights.max_block,
tx_fee,
)
}

Expand All @@ -738,7 +732,7 @@ impl_runtime_apis! {
dest,
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
Expand All @@ -759,7 +753,7 @@ impl_runtime_apis! {
RuntimeOrigin::signed(origin),
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
code,
data,
salt,
Expand Down
Loading