git.delta.rocks / unique-network / refs/commits / d53cfa28fa64

difftreelog

build update frontier

Yaroslav Bolyukin2021-11-26parent: #f2dde26.patch.diff
in: master

14 files changed

modifiedcrates/evm-coder/Cargo.tomldiffbeforeafterboth
--- a/crates/evm-coder/Cargo.toml
+++ b/crates/evm-coder/Cargo.toml
@@ -7,8 +7,8 @@
 evm-coder-macros = { path = "../evm-coder-macros" }
 primitive-types = { version = "0.10.1", default-features = false }
 hex-literal = "0.3.3"
-ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }
-evm-core = { default-features = false, git = "https://github.com/uniquenetwork/evm.git", branch="precompile-output-parachain" }
+ethereum = { version = "0.10.0", default-features = false }
+evm-core = { default-features = false, git = "https://github.com/uniquenetwork/evm.git", branch = "unique-weights" }
 impl-trait-for-tuples = "0.2.1"
 
 [dev-dependencies]
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -1,4 +1,5 @@
 pub use pallet_evm::PrecompileOutput;
+pub use pallet_evm::PrecompileResult;
 use sp_core::{H160, U256};
 
 /// Does not always represent a full collection, for RFT it is either
@@ -6,5 +7,5 @@
 pub trait CommonEvmHandler {
 	const CODE: &'static [u8];
 
-	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput>;
+	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;
 }
modifiedpallets/evm-coder-substrate/Cargo.tomldiffbeforeafterboth
--- a/pallets/evm-coder-substrate/Cargo.toml
+++ b/pallets/evm-coder-substrate/Cargo.toml
@@ -9,7 +9,7 @@
 ] }
 sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }
+ethereum = { version = "0.10.0", default-features = false }
 evm-coder = { default-features = false, path = "../../crates/evm-coder" }
 pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
 pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
modifiedpallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -20,7 +20,8 @@
 	};
 	use frame_support::{ensure};
 	use pallet_evm::{
-		ExitError, ExitReason, ExitRevert, ExitSucceed, PrecompileOutput, GasWeightMapping,
+		ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,
+		PrecompileResult,
 	};
 	use frame_system::ensure_signed;
 	pub use frame_support::dispatch::DispatchResult;
@@ -158,26 +159,28 @@
 		pub fn evm_to_precompile_output(
 			self,
 			result: evm_coder::execution::Result<Option<AbiWriter>>,
-		) -> Option<PrecompileOutput> {
+		) -> Option<PrecompileResult> {
 			use evm_coder::execution::Error;
-			let (writer, reason) = match result {
-				Ok(Some(v)) => (v, ExitReason::Succeed(ExitSucceed::Returned)),
+			Some(match result {
+				Ok(Some(v)) => Ok(PrecompileOutput {
+					exit_status: ExitSucceed::Returned,
+					cost: self.initial_gas - self.gas_left(),
+					logs: self.retrieve_logs(),
+					output: v.finish(),
+				}),
 				Ok(None) => return None,
 				Err(Error::Revert(e)) => {
 					let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));
 					(&e as &str).abi_write(&mut writer);
 
-					(writer, ExitReason::Revert(ExitRevert::Reverted))
+					Err(PrecompileFailure::Revert {
+						exit_status: ExitRevert::Reverted,
+						cost: self.initial_gas - self.gas_left(),
+						output: writer.finish(),
+					})
 				}
-				Err(Error::Fatal(f)) => (AbiWriter::new(), ExitReason::Fatal(f)),
-				Err(Error::Error(e)) => (AbiWriter::new(), ExitReason::Error(e)),
-			};
-
-			Some(PrecompileOutput {
-				cost: self.initial_gas - self.gas_left(),
-				exit_status: reason,
-				logs: self.retrieve_logs(),
-				output: writer.finish(),
+				Err(Error::Fatal(f)) => Err(f.into()),
+				Err(Error::Error(e)) => Err(e.into()),
 			})
 		}
 
@@ -234,7 +237,7 @@
 		mut e: E,
 		value: value,
 		input: &[u8],
-	) -> Option<PrecompileOutput> {
+	) -> Option<PrecompileResult> {
 		let result = call_internal(caller, &mut e, value, input);
 		e.into_recorder().evm_to_precompile_output(result)
 	}
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
before · pallets/evm-contract-helpers/src/eth.rs
1use core::marker::PhantomData;2use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};3use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};4use pallet_evm::{ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput};5use sp_core::H160;6use crate::{7	AllowlistEnabled, Config, Owner, Pallet, SelfSponsoring, SponsorBasket, SponsoringRateLimit,8};9use frame_support::traits::Get;10use up_sponsorship::SponsorshipHandler;11use sp_std::{convert::TryInto, vec::Vec};1213struct ContractHelpers<T: Config>(SubstrateRecorder<T>);14impl<T: Config> WithRecorder<T> for ContractHelpers<T> {15	fn recorder(&self) -> &SubstrateRecorder<T> {16		&self.017	}1819	fn into_recorder(self) -> SubstrateRecorder<T> {20		self.021	}22}2324#[solidity_interface(name = "ContractHelpers")]25impl<T: Config> ContractHelpers<T> {26	fn contract_owner(&self, contract_address: address) -> Result<address> {27		Ok(<Owner<T>>::get(contract_address))28	}2930	fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {31		Ok(<SelfSponsoring<T>>::get(contract_address))32	}3334	fn toggle_sponsoring(35		&mut self,36		caller: caller,37		contract_address: address,38		enabled: bool,39	) -> Result<void> {40		<Pallet<T>>::ensure_owner(contract_address, caller)?;41		<Pallet<T>>::toggle_sponsoring(contract_address, enabled);42		Ok(())43	}4445	fn set_sponsoring_rate_limit(46		&mut self,47		caller: caller,48		contract_address: address,49		rate_limit: uint32,50	) -> Result<void> {51		<Pallet<T>>::ensure_owner(contract_address, caller)?;52		<Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());53		Ok(())54	}5556	fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {57		Ok(<SponsoringRateLimit<T>>::get(contract_address)58			.try_into()59			.map_err(|_| "rate limit > u32::MAX")?)60	}6162	fn allowed(&self, contract_address: address, user: address) -> Result<bool> {63		self.0.consume_sload()?;64		Ok(<Pallet<T>>::allowed(contract_address, user)65			|| !<AllowlistEnabled<T>>::get(contract_address))66	}6768	fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {69		Ok(<AllowlistEnabled<T>>::get(contract_address))70	}7172	fn toggle_allowlist(73		&mut self,74		caller: caller,75		contract_address: address,76		enabled: bool,77	) -> Result<void> {78		<Pallet<T>>::ensure_owner(contract_address, caller)?;79		<Pallet<T>>::toggle_allowlist(contract_address, enabled);80		Ok(())81	}8283	fn toggle_allowed(84		&mut self,85		caller: caller,86		contract_address: address,87		user: address,88		allowed: bool,89	) -> Result<void> {90		<Pallet<T>>::ensure_owner(contract_address, caller)?;91		<Pallet<T>>::toggle_allowed(contract_address, user, allowed);92		Ok(())93	}94}9596pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);97impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T> {98	fn is_reserved(contract: &sp_core::H160) -> bool {99		contract == &T::ContractAddress::get()100	}101102	fn is_used(contract: &sp_core::H160) -> bool {103		contract == &T::ContractAddress::get()104	}105106	fn call(107		source: &sp_core::H160,108		target: &sp_core::H160,109		gas_left: u64,110		input: &[u8],111		value: sp_core::U256,112	) -> Option<PrecompileOutput> {113		// TODO: Extract to another OnMethodCall handler114		if <AllowlistEnabled<T>>::get(target) && !<Pallet<T>>::allowed(*target, *source) {115			return Some(PrecompileOutput {116				exit_status: ExitReason::Revert(ExitRevert::Reverted),117				cost: 0,118				output: {119					let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));120					writer.string("Target contract is allowlisted");121					writer.finish()122				},123				logs: sp_std::vec![],124			});125		}126127		if target != &T::ContractAddress::get() {128			return None;129		}130131		let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(*target, gas_left));132		pallet_evm_coder_substrate::call(*source, helpers, value, input)133	}134135	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {136		(contract == &T::ContractAddress::get())137			.then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())138	}139}140141pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);142impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {143	fn on_create(owner: H160, contract: H160) {144		<Owner<T>>::insert(contract, owner);145	}146}147148pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);149impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {150	fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {151		if !<SelfSponsoring<T>>::get(&call.0) {152			return None;153		}154		if !<Pallet<T>>::allowed(call.0, *who) {155			return None;156		}157		let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;158159		if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {160			let limit = <SponsoringRateLimit<T>>::get(&call.0);161162			let timeout = last_tx_block + limit.into();163			if block_number < timeout {164				return None;165			}166		}167168		<SponsorBasket<T>>::insert(&call.0, who, block_number);169170		Some(call.0)171	}172}173174generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);175generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);
modifiedpallets/evm-migration/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-migration/src/lib.rs
+++ b/pallets/evm-migration/src/lib.rs
@@ -98,7 +98,7 @@
 			_gas_left: u64,
 			_input: &[u8],
 			_value: sp_core::U256,
-		) -> Option<pallet_evm::PrecompileOutput> {
+		) -> Option<pallet_evm::PrecompileResult> {
 			None
 		}
 
modifiedpallets/fungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -19,7 +19,7 @@
 nft-data-structs = { default-features = false, path = '../../primitives/nft' }
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
-ethereum = { git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }
+ethereum = { version = "0.10.0", default-features = false }
 frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 scale-info = { version = "1.0.0", default-features = false, features = [
     "derive",
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -2,7 +2,7 @@
 use core::convert::TryInto;
 use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
 use nft_data_structs::CollectionMode;
-use pallet_common::erc::CommonEvmHandler;
+use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
 use sp_core::{H160, U256};
 use sp_std::vec::Vec;
 use pallet_common::account::CrossAccountId;
@@ -127,7 +127,7 @@
 impl<T: Config> CommonEvmHandler for FungibleHandle<T> {
 	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");
 
-	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
+	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {
 		call::<T, UniqueFungibleCall<T>, _>(*source, self, value, input)
 	}
 }
modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -131,7 +131,7 @@
 scale-info = { version = "1.0.0", default-features = false, features = [
     "derive",
 ] }
-ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }
+ethereum = { version = "0.10.0", default-features = false }
 rlp = { default-features = false, version = "0.5.0" }
 sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.12" }
 
modifiedpallets/nft/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/mod.rs
+++ b/pallets/nft/src/eth/mod.rs
@@ -1,5 +1,6 @@
 pub mod sponsoring;
 
+use fp_evm::PrecompileResult;
 use pallet_common::{
 	CollectionById,
 	erc::CommonEvmHandler,
@@ -10,7 +11,6 @@
 use pallet_refungible::{RefungibleHandle, erc::RefungibleTokenHandle};
 use sp_std::borrow::ToOwned;
 use sp_std::vec::Vec;
-use pallet_evm::{PrecompileOutput};
 use sp_core::{H160, U256};
 use crate::{CollectionMode, Config, dispatch::Dispatched};
 use pallet_common::CollectionHandle;
@@ -54,7 +54,7 @@
 		gas_limit: u64,
 		input: &[u8],
 		value: U256,
-	) -> Option<PrecompileOutput> {
+	) -> Option<PrecompileResult> {
 		if let Some(collection_id) = map_eth_to_id(target) {
 			let collection = <CollectionHandle<T>>::new_with_gas_limit(collection_id, gas_limit)?;
 			let dispatched = Dispatched::dispatch(collection);
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/sponsoring.rs
+++ b/pallets/nft/src/eth/sponsoring.rs
@@ -27,7 +27,7 @@
 		let (method_id, mut reader) = AbiReader::new_call(&call.1).ok()?;
 		match &collection.mode {
 			crate::CollectionMode::NFT => {
-				let call = UniqueNFTCall::parse(method_id, &mut reader).ok()??;
+				let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;
 				match call {
 					UniqueNFTCall::ERC721UniqueExtensions(
 						ERC721UniqueExtensionsCall::Transfer { token_id, .. },
@@ -49,7 +49,7 @@
 				}
 			}
 			crate::CollectionMode::Fungible(_) => {
-				let call = UniqueFungibleCall::parse(method_id, &mut reader).ok()??;
+				let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;
 				#[allow(clippy::single_match)]
 				match call {
 					UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {
modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/nonfungible/Cargo.toml
+++ b/pallets/nonfungible/Cargo.toml
@@ -19,7 +19,7 @@
 nft-data-structs = { default-features = false, path = '../../primitives/nft' }
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
-ethereum = { git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }
+ethereum = { version = "0.10.0", default-features = false }
 frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 scale-info = { version = "1.0.0", default-features = false, features = [
     "derive",
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -8,7 +8,10 @@
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_core::{H160, U256};
 use sp_std::{vec::Vec, vec};
-use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};
+use pallet_common::{
+	account::CrossAccountId,
+	erc::{CommonEvmHandler, PrecompileResult},
+};
 use pallet_evm_coder_substrate::call;
 use pallet_common::erc::PrecompileOutput;
 
@@ -434,7 +437,7 @@
 impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {
 	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");
 
-	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {
+	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {
 		call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)
 	}
 }
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -11,7 +11,7 @@
 		_source: &sp_core::H160,
 		_input: &[u8],
 		_value: sp_core::U256,
-	) -> Option<pallet_common::erc::PrecompileOutput> {
+	) -> Option<pallet_common::erc::PrecompileResult> {
 		// TODO: Implement RFT variant of ERC721
 		None
 	}
@@ -27,7 +27,7 @@
 		_source: &sp_core::H160,
 		_input: &[u8],
 		_value: sp_core::U256,
-	) -> Option<pallet_common::erc::PrecompileOutput> {
+	) -> Option<pallet_common::erc::PrecompileResult> {
 		// TODO: Implement RFT variant of ERC20
 		None
 	}