difftreelog
refactor fix complex value type support in evm-coder
in: master
14 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2653,8 +2653,9 @@
[[package]]
name = "evm-coder"
-version = "0.3.6"
-source = "git+https://github.com/uniquenetwork/evm-coder?tag=v0.3.6#be59ae41a5d2ec9389bae22d54f81122b6ba55a4"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b88ae5a449e7e9dfef59c0dd2df396bc56d81a6f4e297490c0c64aa73f7f7ad4"
dependencies = [
"ethereum",
"evm-coder-procedural",
@@ -2665,8 +2666,9 @@
[[package]]
name = "evm-coder-procedural"
-version = "0.3.6"
-source = "git+https://github.com/uniquenetwork/evm-coder?tag=v0.3.6#be59ae41a5d2ec9389bae22d54f81122b6ba55a4"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6223c1063c1f53380b4b9aaf2e4d82eba4808c661c61265619b804b09b7a6b1a"
dependencies = [
"Inflector",
"hex",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,7 @@
[workspace.dependencies]
# Unique
app-promotion-rpc = { path = "primitives/app_promotion_rpc", default-features = false }
-evm-coder = { git = "https://github.com/uniquenetwork/evm-coder", tag = "v0.3.6", default-features = false, features = [
+evm-coder = { version = "0.4.2", default-features = false, features = [
'bondrewd',
] }
pallet-app-promotion = { path = "pallets/app-promotion", default-features = false }
pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -35,7 +35,8 @@
"sp-std/std",
"up-data-structs/std",
"up-pov-estimate-rpc/std",
+ "evm-coder/std",
]
-stubgen = ["evm-coder/stubgen"]
+stubgen = ["evm-coder/stubgen", "up-data-structs/stubgen"]
tests = []
try-runtime = ["frame-support/try-runtime"]
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -549,8 +549,6 @@
/// Collection properties
#[derive(Debug, Default, AbiCoder)]
pub struct CreateCollectionData {
- /// Collection sponsor
- pub pending_sponsor: CrossAddress,
/// Collection name
pub name: String,
/// Collection description
@@ -571,6 +569,8 @@
pub nesting_settings: CollectionNestingAndPermission,
/// Collection limits
pub limits: Vec<CollectionLimitValue>,
+ /// Collection sponsor
+ pub pending_sponsor: CrossAddress,
/// Extra collection flags
pub flags: CollectionFlags,
}
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819extern crate self as pallet_evm_coder_substrate;2021#[cfg(not(feature = "std"))]22extern crate alloc;23#[cfg(not(feature = "std"))]24use alloc::format;25use execution::PreDispatch;26use frame_support::dispatch::Weight;2728use core::marker::PhantomData;29use sp_std::cell::RefCell;3031use codec::Decode;32use frame_support::pallet_prelude::DispatchError;33use frame_support::traits::PalletInfo;34use frame_support::{ensure, sp_runtime::ModuleError};35use up_data_structs::budget;36use pallet_evm::{37 ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,38 PrecompileResult, PrecompileHandle,39};40use sp_core::{Get, H160};41// #[cfg(feature = "runtime-benchmarks")]42// pub mod benchmarking;43pub mod execution;4445#[doc(hidden)]46pub use spez::spez;4748use evm_coder::{49 abi::{AbiReader, AbiWrite, AbiWriter},50 types::{Msg, Value},51};5253pub use pallet::*;54pub use evm_coder::{ResultWithPostInfoOf, Contract, abi, solidity_interface, ToLog, types};5556#[frame_support::pallet]57pub mod pallet {58 use super::*;5960 pub use frame_support::dispatch::DispatchResult;6162 /// DispatchError is opaque, but we need to somehow extract correct error in case of OutOfGas failure63 /// So we have this pallet, which defines OutOfGas error, and knews its own id to check if DispatchError64 /// is thrown because of it65 ///66 /// These errors shouldn't end in extrinsic results, as they only used in evm execution path67 #[pallet::error]68 pub enum Error<T> {69 OutOfGas,70 OutOfFund,71 }7273 #[pallet::config]74 pub trait Config: frame_system::Config + pallet_evm::Config {}7576 #[pallet::pallet]77 pub struct Pallet<T>(_);78}7980// From instabul hardfork configuration: https://github.com/rust-blockchain/evm/blob/fd4fd6acc0ca3208d6770fdb3ba407c94cdf97c6/runtime/src/lib.rs#L28481pub const G_SLOAD_WORD: u64 = 800;82pub const G_SSTORE_WORD: u64 = 20000;8384pub struct GasCallsBudget<'r, T: Config> {85 recorder: &'r SubstrateRecorder<T>,86 gas_per_call: u64,87}88impl<T: Config> budget::Budget for GasCallsBudget<'_, T> {89 fn consume_custom(&self, calls: u32) -> bool {90 let (gas, overflown) = (calls as u64).overflowing_add(self.gas_per_call);91 if overflown {92 return false;93 }94 self.recorder.consume_gas(gas).is_ok()95 }96}9798#[derive(Default)]99pub struct SubstrateRecorder<T: Config> {100 initial_gas: u64,101 gas_limit: RefCell<u64>,102 _phantom: PhantomData<*const T>,103}104105impl<T: Config> SubstrateRecorder<T> {106 pub fn new(gas_limit: u64) -> Self {107 Self {108 initial_gas: gas_limit,109 gas_limit: RefCell::new(gas_limit),110 _phantom: PhantomData,111 }112 }113114 pub fn gas_left(&self) -> u64 {115 *self.gas_limit.borrow()116 }117 pub fn gas_calls_budget(&self, gas_per_call: u64) -> GasCallsBudget<T> {118 GasCallsBudget {119 recorder: self,120 gas_per_call,121 }122 }123 pub fn weight_calls_budget(&self, weight_per_call: Weight) -> GasCallsBudget<T> {124 GasCallsBudget {125 recorder: self,126 gas_per_call: T::GasWeightMapping::weight_to_gas(weight_per_call),127 }128 }129 pub fn consume_sload_sub(&self) -> DispatchResult {130 self.consume_gas_sub(G_SLOAD_WORD)131 }132 pub fn consume_sstores_sub(&self, amount: usize) -> DispatchResult {133 self.consume_gas_sub(G_SSTORE_WORD.saturating_mul(amount as u64))134 }135 pub fn consume_sstore_sub(&self) -> DispatchResult {136 self.consume_gas_sub(G_SSTORE_WORD)137 }138 pub fn consume_gas_sub(&self, gas: u64) -> DispatchResult {139 ensure!(gas != u64::MAX, Error::<T>::OutOfGas);140 let mut gas_limit = self.gas_limit.borrow_mut();141 ensure!(gas <= *gas_limit, Error::<T>::OutOfGas);142 *gas_limit -= gas;143 Ok(())144 }145146 pub fn consume_sload(&self) -> execution::Result<()> {147 self.consume_gas(G_SLOAD_WORD)148 }149 pub fn consume_sstore(&self) -> execution::Result<()> {150 self.consume_gas(G_SSTORE_WORD)151 }152 pub fn consume_gas(&self, gas: u64) -> execution::Result<()> {153 if gas == u64::MAX {154 return Err(execution::Error::Error(ExitError::OutOfGas));155 }156 let mut gas_limit = self.gas_limit.borrow_mut();157 if gas > *gas_limit {158 return Err(execution::Error::Error(ExitError::OutOfGas));159 }160 *gas_limit -= gas;161 Ok(())162 }163 pub fn return_gas(&self, gas: u64) {164 let mut gas_limit = self.gas_limit.borrow_mut();165 *gas_limit += gas;166 }167168 pub fn evm_to_precompile_output(169 self,170 handle: &mut impl PrecompileHandle,171 result: execution::Result<Option<AbiWriter>>,172 ) -> Option<PrecompileResult> {173 use execution::Error;174 // We ignore error here, as it should not occur, as we have our own bookkeeping of gas175 let _ = handle.record_cost(self.initial_gas - self.gas_left());176 Some(match result {177 Ok(Some(v)) => Ok(PrecompileOutput {178 exit_status: ExitSucceed::Returned,179 output: v.finish(),180 }),181 Ok(None) => return None,182 Err(Error::Revert(e)) => {183 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));184 (&e as &str).abi_write(&mut writer);185186 Err(PrecompileFailure::Revert {187 exit_status: ExitRevert::Reverted,188 output: writer.finish(),189 })190 }191 Err(Error::Fatal(f)) => Err(PrecompileFailure::Fatal { exit_status: f }),192 Err(Error::Error(e)) => Err(e.into()),193 })194 }195196 /// Consume gas for reading.197 pub fn consume_store_reads(&self, reads: u64) -> execution::Result<()> {198 self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(199 <T as frame_system::Config>::DbWeight::get()200 .read201 .saturating_mul(reads),202 // TODO: measure proof203 0,204 )))205 }206207 /// Consume gas for writing.208 pub fn consume_store_writes(&self, writes: u64) -> execution::Result<()> {209 self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(210 <T as frame_system::Config>::DbWeight::get()211 .write212 .saturating_mul(writes),213 // TODO: measure proof214 0,215 )))216 }217218 /// Consume gas for reading and writing.219 pub fn consume_store_reads_and_writes(&self, reads: u64, writes: u64) -> execution::Result<()> {220 let weight = <T as frame_system::Config>::DbWeight::get();221 let reads = weight.read.saturating_mul(reads);222 let writes = weight.read.saturating_mul(writes);223 self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(224 reads.saturating_add(writes),225 // TODO: measure proof226 0,227 )))228 }229}230231pub fn dispatch_to_evm<T: Config>(err: DispatchError) -> execution::Error {232 use execution::Error as ExError;233 match err {234 DispatchError::Module(ModuleError { index, error, .. })235 if index236 == T::PalletInfo::index::<Pallet<T>>()237 .expect("evm-coder-substrate is a pallet, which should be added to runtime")238 as u8 =>239 {240 let mut read = &error as &[u8];241 match Error::<T>::decode(&mut read) {242 Ok(Error::<T>::OutOfGas) => ExError::Error(ExitError::OutOfGas),243 Ok(Error::<T>::OutOfFund) => ExError::Error(ExitError::OutOfFund),244 _ => unreachable!("this pallet only defines two possible errors"),245 }246 }247 DispatchError::Module(ModuleError {248 message: Some(msg), ..249 }) => ExError::Revert(msg.into()),250 DispatchError::Module(ModuleError { index, error, .. }) => {251 ExError::Revert(format!("error {error:?} in pallet {index}"))252 }253 e => ExError::Revert(format!("substrate error: {e:?}")),254 }255}256257pub trait WithRecorder<T: Config> {258 fn recorder(&self) -> &SubstrateRecorder<T>;259 fn into_recorder(self) -> SubstrateRecorder<T>;260}261262/// Helper to simplify implementing bridge between evm-coder definitions and pallet-evm263pub fn call<T, C, E, H>(handle: &mut H, mut e: E) -> Option<PrecompileResult>264where265 T: Config,266 C: evm_coder::Call + PreDispatch,267 E: evm_coder::Callable<C> + WithRecorder<T>,268 H: PrecompileHandle,269 execution::ResultWithPostInfo<AbiWriter>: From<ResultWithPostInfoOf<E, AbiWriter>>,270{271 let result = call_internal(272 handle.context().caller,273 &mut e,274 handle.context().apparent_value,275 handle.input(),276 );277 e.into_recorder().evm_to_precompile_output(handle, result)278}279280fn call_internal<T, C, E>(281 caller: H160,282 e: &mut E,283 value: Value,284 input: &[u8],285) -> execution::Result<Option<AbiWriter>>286where287 T: Config,288 C: evm_coder::Call + PreDispatch,289 E: Contract + evm_coder::Callable<C> + WithRecorder<T>,290 execution::ResultWithPostInfo<AbiWriter>: From<ResultWithPostInfoOf<E, AbiWriter>>,291{292 let (selector, mut reader) = AbiReader::new_call(input)?;293 let call = C::parse(selector, &mut reader)?;294 if call.is_none() {295 let selector = u32::from_be_bytes(selector);296 return Err(format!("unrecognized selector: 0x{selector:0<8x}").into());297 }298 let call = call.unwrap();299300 let dispatch_info = call.dispatch_info();301 e.recorder()302 .consume_gas(T::GasWeightMapping::weight_to_gas(dispatch_info.weight))?;303304 match execution::ResultWithPostInfo::from(e.call(Msg {305 call,306 caller,307 value,308 })) {309 Ok(v) => {310 let unspent = v.post_info.calc_unspent(&dispatch_info);311 e.recorder()312 .return_gas(T::GasWeightMapping::weight_to_gas(unspent));313 Ok(Some(v.data))314 }315 Err(v) => {316 let unspent = v.post_info.calc_unspent(&dispatch_info);317 e.recorder()318 .return_gas(T::GasWeightMapping::weight_to_gas(unspent));319 Err(v.data)320 }321 }322}323324#[cfg(test)]325#[allow(dead_code)]326mod tests {327 use core::marker::PhantomData;328329 use evm_coder::ERC165Call;330 use frame_support::weights::Weight;331332 use crate::execution::PreDispatch;333334 #[derive(PreDispatch)]335 enum ExampleCall<T: super::Config> {336 ERC165Call(ERC165Call, PhantomData<fn() -> T>),337 OtherCall(ERC165Call),338339 #[weight(Weight::from_ref_time(a + b))]340 Example {341 a: u64,342 b: u64,343 },344 }345}pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -19,7 +19,7 @@
extern crate alloc;
use core::marker::PhantomData;
use evm_coder::{
- abi::{AbiWriter, AbiType},
+ abi::{AbiType, AbiEncode},
generate_stubgen, solidity_interface,
types::*,
ToLog,
@@ -370,11 +370,8 @@
{
return Some(Err(PrecompileFailure::Revert {
exit_status: ExitRevert::Reverted,
- output: {
- let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));
- writer.string("Target contract is allowlisted");
- writer.finish()
- },
+ output: ("target contract is allowlisted",)
+ .abi_encode_call(evm_coder::fn_selector!(Error(string))),
}));
}
pallets/gov-origins/src/lib.rsdiffbeforeafterboth--- a/pallets/gov-origins/src/lib.rs
+++ b/pallets/gov-origins/src/lib.rs
@@ -31,6 +31,7 @@
#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[pallet::origin]
+ #[non_exhaustive]
pub enum Origin {
/// Origin able to send proposal from fellowship collective to democracy pallet.
FellowshipProposition,
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -139,116 +139,114 @@
T: Config + pallet_common::Config + pallet_nonfungible::Config + pallet_refungible::Config,
T::AccountId: From<[u8; 32]>,
{
- /*
- /// Create a collection
- /// @return address Address of the newly created collection
- #[weight(<SelfWeightOf<T>>::create_collection())]
- #[solidity(rename_selector = "createCollection")]
- fn create_collection(
- &mut self,
- caller: Caller,
- value: Value,
- data: eth::CreateCollectionData,
- ) -> Result<Address> {
- let (caller, name, description, token_prefix) =
- convert_data::<T>(caller, data.name, data.description, data.token_prefix)?;
- if data.mode != eth::CollectionMode::Fungible && data.decimals != 0 {
- return Err("decimals are only supported for NFT and RFT collections".into());
- }
- let mode = match data.mode {
- eth::CollectionMode::Fungible => CollectionMode::Fungible(data.decimals),
- eth::CollectionMode::Nonfungible => CollectionMode::NFT,
- eth::CollectionMode::Refungible => CollectionMode::ReFungible,
- };
+ /// Create a collection
+ /// @return address Address of the newly created collection
+ #[weight(<SelfWeightOf<T>>::create_collection())]
+ #[solidity(rename_selector = "createCollection")]
+ fn create_collection(
+ &mut self,
+ caller: Caller,
+ value: Value,
+ data: eth::CreateCollectionData,
+ ) -> Result<Address> {
+ let (caller, name, description, token_prefix) =
+ convert_data::<T>(caller, data.name, data.description, data.token_prefix)?;
+ if data.mode != eth::CollectionMode::Fungible && data.decimals != 0 {
+ return Err("decimals are only supported for NFT and RFT collections".into());
+ }
+ let mode = match data.mode {
+ eth::CollectionMode::Fungible => CollectionMode::Fungible(data.decimals),
+ eth::CollectionMode::Nonfungible => CollectionMode::NFT,
+ eth::CollectionMode::Refungible => CollectionMode::ReFungible,
+ };
- let properties: BoundedVec<_, _> = data
- .properties
- .into_iter()
- .map(eth::Property::try_into)
- .collect::<Result<Vec<_>>>()?
- .try_into()
- .map_err(|_| "too many properties")?;
+ let properties: BoundedVec<_, _> = data
+ .properties
+ .into_iter()
+ .map(eth::Property::try_into)
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| "too many properties")?;
- let token_property_permissions =
- eth::TokenPropertyPermission::into_property_key_permissions(
- data.token_property_permissions,
- )?
- .try_into()
- .map_err(|_| "too many property permissions")?;
+ let token_property_permissions =
+ eth::TokenPropertyPermission::into_property_key_permissions(
+ data.token_property_permissions,
+ )?
+ .try_into()
+ .map_err(|_| "too many property permissions")?;
- let limits = if !data.limits.is_empty() {
- Some(
- data.limits
- .into_iter()
- .collect::<Result<up_data_structs::CollectionLimits>>()?,
- )
- } else {
- None
- };
+ let limits = if !data.limits.is_empty() {
+ Some(
+ data.limits
+ .into_iter()
+ .collect::<Result<up_data_structs::CollectionLimits>>()?,
+ )
+ } else {
+ None
+ };
- let pending_sponsor = data.pending_sponsor.into_option_sub_cross_account::<T>()?;
+ let pending_sponsor = data.pending_sponsor.into_option_sub_cross_account::<T>()?;
- let restricted = if !data.nesting_settings.restricted.is_empty() {
- Some(
- data.nesting_settings
- .restricted
- .iter()
- .map(map_eth_to_id)
- .collect::<Option<BTreeSet<_>>>()
- .ok_or("can't convert address into collection id")?
- .try_into()
- .map_err(|_| "too many collections")?,
- )
- } else {
- None
- };
+ let restricted = if !data.nesting_settings.restricted.is_empty() {
+ Some(
+ data.nesting_settings
+ .restricted
+ .iter()
+ .map(map_eth_to_id)
+ .collect::<Option<BTreeSet<_>>>()
+ .ok_or("can't convert address into collection id")?
+ .try_into()
+ .map_err(|_| "too many collections")?,
+ )
+ } else {
+ None
+ };
- let admin_list = data
- .admin_list
- .into_iter()
- .map(|admin| admin.into_sub_cross_account::<T>())
- .collect::<Result<Vec<_>>>()?;
+ let admin_list = data
+ .admin_list
+ .into_iter()
+ .map(|admin| admin.into_sub_cross_account::<T>())
+ .collect::<Result<Vec<_>>>()?;
- let flags = data.flags;
- if !flags.is_allowed_for_user() {
- return Err("internal flags were used".into());
- }
+ let flags = data.flags;
+ if !flags.is_allowed_for_user() {
+ return Err("internal flags were used".into());
+ }
- let data = CreateCollectionData {
- name,
- mode,
- description,
- token_prefix,
- properties,
- token_property_permissions,
- limits,
- pending_sponsor,
+ let data = CreateCollectionData {
+ name,
+ mode,
+ description,
+ token_prefix,
+ properties,
+ token_property_permissions,
+ limits,
+ pending_sponsor,
+ access: None,
+ permissions: Some(CollectionPermissions {
access: None,
- permissions: Some(CollectionPermissions {
- access: None,
- mint_mode: None,
- nesting: Some(NestingPermissions {
- token_owner: data.nesting_settings.token_owner,
- collection_admin: data.nesting_settings.collection_admin,
- restricted,
- #[cfg(feature = "runtime-benchmarks")]
- permissive: true,
- }),
+ mint_mode: None,
+ nesting: Some(NestingPermissions {
+ token_owner: data.nesting_settings.token_owner,
+ collection_admin: data.nesting_settings.collection_admin,
+ restricted,
+ #[cfg(feature = "runtime-benchmarks")]
+ permissive: true,
}),
- admin_list,
- flags,
- };
- check_sent_amount_equals_collection_creation_price::<T>(value)?;
- let collection_helpers_address =
- T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
+ }),
+ admin_list,
+ flags,
+ };
+ check_sent_amount_equals_collection_creation_price::<T>(value)?;
+ let collection_helpers_address =
+ T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
- let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
- .map_err(dispatch_to_evm::<T>)?;
+ let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
+ .map_err(dispatch_to_evm::<T>)?;
- let address = pallet_common::eth::collection_id_to_address(collection_id);
- Ok(address)
- }
- */
+ let address = pallet_common::eth::collection_id_to_address(collection_id);
+ Ok(address)
+ }
/// Create an NFT collection
/// @param name Name of the collection
primitives/data-structs/Cargo.tomldiffbeforeafterboth--- a/primitives/data-structs/Cargo.toml
+++ b/primitives/data-structs/Cargo.toml
@@ -39,3 +39,4 @@
"sp-runtime/std",
"sp-std/std",
]
+stubgen = ["evm-coder/stubgen"]
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -24,7 +24,7 @@
weights::CommonWeights,
RelayChainBlockNumberProvider,
},
- Runtime, RuntimeEvent, RuntimeCall, RuntimeOrigin, RUNTIME_NAME, TOKEN_SYMBOL, DECIMALS,
+ Runtime, RuntimeEvent, RuntimeCall, RUNTIME_NAME, TOKEN_SYMBOL, DECIMALS,
Balances,
};
use frame_support::traits::{ConstU32, ConstU64, Currency};
runtime/common/ethereum/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring.rs
+++ b/runtime/common/ethereum/sponsoring.rs
@@ -17,7 +17,7 @@
//! Implements EVM sponsoring logic via TransactionValidityHack
use core::{convert::TryInto, marker::PhantomData};
-use evm_coder::{Call, abi::AbiReader};
+use evm_coder::{Call};
use pallet_common::{CollectionHandle, eth::map_eth_to_id};
use pallet_evm::account::CrossAccountId;
use pallet_evm_transaction_payment::CallContext;
@@ -66,11 +66,11 @@
if let Some(collection_id) = map_eth_to_id(&call_context.contract_address) {
let collection = <CollectionHandle<T>>::new(collection_id)?;
let sponsor = collection.sponsorship.sponsor()?.clone();
- let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?;
+ // let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?;
Some(T::CrossAccountId::from_sub(match &collection.mode {
CollectionMode::NFT => {
let collection = NonfungibleHandle::cast(collection);
- let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;
+ let call = <UniqueNFTCall<T>>::parse_full(&call_context.input).ok()??;
match call {
UniqueNFTCall::TokenProperties(call) => match call {
TokenPropertiesCall::SetProperty {
@@ -161,11 +161,11 @@
}
}
CollectionMode::ReFungible => {
- let call = <UniqueRefungibleCall<T>>::parse(method_id, &mut reader).ok()??;
+ let call = <UniqueRefungibleCall<T>>::parse_full(&call_context.input).ok()??;
refungible::call_sponsor(call, collection, who).map(|()| sponsor)
}
CollectionMode::Fungible(_) => {
- let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;
+ let call = <UniqueFungibleCall<T>>::parse_full(&call_context.input).ok()??;
match call {
UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {
withdraw_transfer::<T>(&collection, who, &TokenId::default())
@@ -196,8 +196,7 @@
// Token existance isn't checked at this point and should be checked in `withdraw` method.
let token = RefungibleTokenHandle(rft_collection, token_id);
- let (method_id, mut reader) = AbiReader::new_call(&call_context.input).ok()?;
- let call = <UniqueRefungibleTokenCall<T>>::parse(method_id, &mut reader).ok()??;
+ let call = <UniqueRefungibleTokenCall<T>>::parse_full(&call_context.input).ok()??;
Some(T::CrossAccountId::from_sub(
refungible::token_call_sponsor(call, token, who).map(|()| sponsor)?,
))
tests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth--- a/tests/src/eth/abi/collectionHelpers.json
+++ b/tests/src/eth/abi/collectionHelpers.json
@@ -77,15 +77,6 @@
"inputs": [
{
"components": [
- {
- "components": [
- { "internalType": "address", "name": "eth", "type": "address" },
- { "internalType": "uint256", "name": "sub", "type": "uint256" }
- ],
- "internalType": "struct CrossAddress",
- "name": "pending_sponsor",
- "type": "tuple"
- },
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "string", "name": "description", "type": "string" },
{
@@ -170,6 +161,15 @@
"type": "tuple[]"
},
{
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "pending_sponsor",
+ "type": "tuple"
+ },
+ {
"internalType": "CollectionFlags",
"name": "flags",
"type": "uint8"
tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/types.ts
+++ b/tests/src/eth/util/playgrounds/types.ts
@@ -59,8 +59,8 @@
}
export enum CollectionMode {
+ Nonfungible,
Fungible,
- Nonfungible,
Refungible,
}
@@ -129,4 +129,4 @@
else
this.decimals = 0;
}
-}
\ No newline at end of file
+}
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -216,7 +216,6 @@
}
const tx = collectionHelper.methods.createCollection([
- this.data.pendingSponsor,
this.data.name,
this.data.description,
this.data.tokenPrefix,
@@ -227,6 +226,7 @@
this.data.adminList,
this.data.nestingSettings,
this.data.limits,
+ this.data.pendingSponsor,
this.data.flags,
]);
return tx;