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
7evm-coder-macros = { path = "../evm-coder-macros" }7evm-coder-macros = { path = "../evm-coder-macros" }
8primitive-types = { version = "0.10.1", default-features = false }8primitive-types = { version = "0.10.1", default-features = false }
9hex-literal = "0.3.3"9hex-literal = "0.3.3"
10ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }10ethereum = { version = "0.10.0", default-features = false }
11evm-core = { default-features = false, git = "https://github.com/uniquenetwork/evm.git", branch="precompile-output-parachain" }11evm-core = { default-features = false, git = "https://github.com/uniquenetwork/evm.git", branch = "unique-weights" }
12impl-trait-for-tuples = "0.2.1"12impl-trait-for-tuples = "0.2.1"
1313
14[dev-dependencies]14[dev-dependencies]
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
1pub use pallet_evm::PrecompileOutput;1pub use pallet_evm::PrecompileOutput;
2pub use pallet_evm::PrecompileResult;
2use sp_core::{H160, U256};3use sp_core::{H160, U256};
34
4/// Does not always represent a full collection, for RFT it is either5/// Does not always represent a full collection, for RFT it is either
5/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)6/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)
6pub trait CommonEvmHandler {7pub trait CommonEvmHandler {
7 const CODE: &'static [u8];8 const CODE: &'static [u8];
89
9 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput>;10 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;
10}11}
1112
modifiedpallets/evm-coder-substrate/Cargo.tomldiffbeforeafterboth
9] }9] }
10sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }10sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
11sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }11sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
12ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }12ethereum = { version = "0.10.0", default-features = false }
13evm-coder = { default-features = false, path = "../../crates/evm-coder" }13evm-coder = { default-features = false, path = "../../crates/evm-coder" }
14pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }14pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }
15pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12-weights" }15pallet-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
20 };20 };
21 use frame_support::{ensure};21 use frame_support::{ensure};
22 use pallet_evm::{22 use pallet_evm::{
23 ExitError, ExitReason, ExitRevert, ExitSucceed, PrecompileOutput, GasWeightMapping,23 ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,
24 PrecompileResult,
24 };25 };
25 use frame_system::ensure_signed;26 use frame_system::ensure_signed;
26 pub use frame_support::dispatch::DispatchResult;27 pub use frame_support::dispatch::DispatchResult;
158 pub fn evm_to_precompile_output(159 pub fn evm_to_precompile_output(
159 self,160 self,
160 result: evm_coder::execution::Result<Option<AbiWriter>>,161 result: evm_coder::execution::Result<Option<AbiWriter>>,
161 ) -> Option<PrecompileOutput> {162 ) -> Option<PrecompileResult> {
162 use evm_coder::execution::Error;163 use evm_coder::execution::Error;
163 let (writer, reason) = match result {164 Some(match result {
164 Ok(Some(v)) => (v, ExitReason::Succeed(ExitSucceed::Returned)),165 Ok(Some(v)) => Ok(PrecompileOutput {
166 exit_status: ExitSucceed::Returned,
167 cost: self.initial_gas - self.gas_left(),
168 logs: self.retrieve_logs(),
169 output: v.finish(),
170 }),
165 Ok(None) => return None,171 Ok(None) => return None,
166 Err(Error::Revert(e)) => {172 Err(Error::Revert(e)) => {
167 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));173 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));
168 (&e as &str).abi_write(&mut writer);174 (&e as &str).abi_write(&mut writer);
169175
170 (writer, ExitReason::Revert(ExitRevert::Reverted))176 Err(PrecompileFailure::Revert {
177 exit_status: ExitRevert::Reverted,
178 cost: self.initial_gas - self.gas_left(),
179 output: writer.finish(),
180 })
171 }181 }
172 Err(Error::Fatal(f)) => (AbiWriter::new(), ExitReason::Fatal(f)),182 Err(Error::Fatal(f)) => Err(f.into()),
173 Err(Error::Error(e)) => (AbiWriter::new(), ExitReason::Error(e)),183 Err(Error::Error(e)) => Err(e.into()),
174 };184 })
175
176 Some(PrecompileOutput {
177 cost: self.initial_gas - self.gas_left(),
178 exit_status: reason,
179 logs: self.retrieve_logs(),
180 output: writer.finish(),
181 })
182 }185 }
183186
184 pub fn submit_logs(self) {187 pub fn submit_logs(self) {
234 mut e: E,237 mut e: E,
235 value: value,238 value: value,
236 input: &[u8],239 input: &[u8],
237 ) -> Option<PrecompileOutput> {240 ) -> Option<PrecompileResult> {
238 let result = call_internal(caller, &mut e, value, input);241 let result = call_internal(caller, &mut e, value, input);
239 e.into_recorder().evm_to_precompile_output(result)242 e.into_recorder().evm_to_precompile_output(result)
240 }243 }
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
2use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};2use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
3use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};3use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
4use pallet_evm::{ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput};4use pallet_evm::{
5 ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput, PrecompileResult,
6 PrecompileFailure,
7};
5use sp_core::H160;8use sp_core::H160;
6use crate::{9use crate::{
109 gas_left: u64,112 gas_left: u64,
110 input: &[u8],113 input: &[u8],
111 value: sp_core::U256,114 value: sp_core::U256,
112 ) -> Option<PrecompileOutput> {115 ) -> Option<PrecompileResult> {
113 // TODO: Extract to another OnMethodCall handler116 // TODO: Extract to another OnMethodCall handler
114 if <AllowlistEnabled<T>>::get(target) && !<Pallet<T>>::allowed(*target, *source) {117 if <AllowlistEnabled<T>>::get(target) && !<Pallet<T>>::allowed(*target, *source) {
115 return Some(PrecompileOutput {118 return Some(Err(PrecompileFailure::Revert {
116 exit_status: ExitReason::Revert(ExitRevert::Reverted),119 exit_status: ExitRevert::Reverted,
117 cost: 0,120 cost: 0,
118 output: {121 output: {
119 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));122 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));
120 writer.string("Target contract is allowlisted");123 writer.string("Target contract is allowlisted");
121 writer.finish()124 writer.finish()
122 },125 },
123 logs: sp_std::vec![],
124 });126 }));
125 }127 }
126128
127 if target != &T::ContractAddress::get() {129 if target != &T::ContractAddress::get() {
modifiedpallets/evm-migration/src/lib.rsdiffbeforeafterboth
98 _gas_left: u64,98 _gas_left: u64,
99 _input: &[u8],99 _input: &[u8],
100 _value: sp_core::U256,100 _value: sp_core::U256,
101 ) -> Option<pallet_evm::PrecompileOutput> {101 ) -> Option<pallet_evm::PrecompileResult> {
102 None102 None
103 }103 }
104104
modifiedpallets/fungible/Cargo.tomldiffbeforeafterboth
19nft-data-structs = { default-features = false, path = '../../primitives/nft' }19nft-data-structs = { default-features = false, path = '../../primitives/nft' }
20evm-coder = { default-features = false, path = '../../crates/evm-coder' }20evm-coder = { default-features = false, path = '../../crates/evm-coder' }
21pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }21pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
22ethereum = { git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }22ethereum = { version = "0.10.0", default-features = false }
23frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }23frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
24scale-info = { version = "1.0.0", default-features = false, features = [24scale-info = { version = "1.0.0", default-features = false, features = [
25 "derive",25 "derive",
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
2use core::convert::TryInto;2use core::convert::TryInto;
3use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};3use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
4use nft_data_structs::CollectionMode;4use nft_data_structs::CollectionMode;
5use pallet_common::erc::CommonEvmHandler;5use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
6use sp_core::{H160, U256};6use sp_core::{H160, U256};
7use sp_std::vec::Vec;7use sp_std::vec::Vec;
8use pallet_common::account::CrossAccountId;8use pallet_common::account::CrossAccountId;
127impl<T: Config> CommonEvmHandler for FungibleHandle<T> {127impl<T: Config> CommonEvmHandler for FungibleHandle<T> {
128 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");128 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");
129129
130 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {130 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {
131 call::<T, UniqueFungibleCall<T>, _>(*source, self, value, input)131 call::<T, UniqueFungibleCall<T>, _>(*source, self, value, input)
132 }132 }
133}133}
modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
131scale-info = { version = "1.0.0", default-features = false, features = [131scale-info = { version = "1.0.0", default-features = false, features = [
132 "derive",132 "derive",
133] }133] }
134ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }134ethereum = { version = "0.10.0", default-features = false }
135rlp = { default-features = false, version = "0.5.0" }135rlp = { default-features = false, version = "0.5.0" }
136sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.12" }136sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.12" }
137137
modifiedpallets/nft/src/eth/mod.rsdiffbeforeafterboth
1pub mod sponsoring;1pub mod sponsoring;
22
3use fp_evm::PrecompileResult;
3use pallet_common::{4use pallet_common::{
4 CollectionById,5 CollectionById,
5 erc::CommonEvmHandler,6 erc::CommonEvmHandler,
10use pallet_refungible::{RefungibleHandle, erc::RefungibleTokenHandle};11use pallet_refungible::{RefungibleHandle, erc::RefungibleTokenHandle};
11use sp_std::borrow::ToOwned;12use sp_std::borrow::ToOwned;
12use sp_std::vec::Vec;13use sp_std::vec::Vec;
13use pallet_evm::{PrecompileOutput};
14use sp_core::{H160, U256};14use sp_core::{H160, U256};
15use crate::{CollectionMode, Config, dispatch::Dispatched};15use crate::{CollectionMode, Config, dispatch::Dispatched};
16use pallet_common::CollectionHandle;16use pallet_common::CollectionHandle;
54 gas_limit: u64,54 gas_limit: u64,
55 input: &[u8],55 input: &[u8],
56 value: U256,56 value: U256,
57 ) -> Option<PrecompileOutput> {57 ) -> Option<PrecompileResult> {
58 if let Some(collection_id) = map_eth_to_id(target) {58 if let Some(collection_id) = map_eth_to_id(target) {
59 let collection = <CollectionHandle<T>>::new_with_gas_limit(collection_id, gas_limit)?;59 let collection = <CollectionHandle<T>>::new_with_gas_limit(collection_id, gas_limit)?;
60 let dispatched = Dispatched::dispatch(collection);60 let dispatched = Dispatched::dispatch(collection);
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
27 let (method_id, mut reader) = AbiReader::new_call(&call.1).ok()?;27 let (method_id, mut reader) = AbiReader::new_call(&call.1).ok()?;
28 match &collection.mode {28 match &collection.mode {
29 crate::CollectionMode::NFT => {29 crate::CollectionMode::NFT => {
30 let call = UniqueNFTCall::parse(method_id, &mut reader).ok()??;30 let call = <UniqueNFTCall<T>>::parse(method_id, &mut reader).ok()??;
31 match call {31 match call {
32 UniqueNFTCall::ERC721UniqueExtensions(32 UniqueNFTCall::ERC721UniqueExtensions(
33 ERC721UniqueExtensionsCall::Transfer { token_id, .. },33 ERC721UniqueExtensionsCall::Transfer { token_id, .. },
49 }49 }
50 }50 }
51 crate::CollectionMode::Fungible(_) => {51 crate::CollectionMode::Fungible(_) => {
52 let call = UniqueFungibleCall::parse(method_id, &mut reader).ok()??;52 let call = <UniqueFungibleCall<T>>::parse(method_id, &mut reader).ok()??;
53 #[allow(clippy::single_match)]53 #[allow(clippy::single_match)]
54 match call {54 match call {
55 UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {55 UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {
modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
19nft-data-structs = { default-features = false, path = '../../primitives/nft' }19nft-data-structs = { default-features = false, path = '../../primitives/nft' }
20evm-coder = { default-features = false, path = '../../crates/evm-coder' }20evm-coder = { default-features = false, path = '../../crates/evm-coder' }
21pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }21pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
22ethereum = { git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }22ethereum = { version = "0.10.0", default-features = false }
23frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }23frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
24scale-info = { version = "1.0.0", default-features = false, features = [24scale-info = { version = "1.0.0", default-features = false, features = [
25 "derive",25 "derive",
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
10use sp_std::{vec::Vec, vec};10use sp_std::{vec::Vec, vec};
11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};11use pallet_common::{
12 account::CrossAccountId,
13 erc::{CommonEvmHandler, PrecompileResult},
14};
12use pallet_evm_coder_substrate::call;15use pallet_evm_coder_substrate::call;
13use pallet_common::erc::PrecompileOutput;16use pallet_common::erc::PrecompileOutput;
434impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {437impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {
435 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");438 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");
436439
437 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {440 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {
438 call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)441 call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)
439 }442 }
440}443}
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
11 _source: &sp_core::H160,11 _source: &sp_core::H160,
12 _input: &[u8],12 _input: &[u8],
13 _value: sp_core::U256,13 _value: sp_core::U256,
14 ) -> Option<pallet_common::erc::PrecompileOutput> {14 ) -> Option<pallet_common::erc::PrecompileResult> {
15 // TODO: Implement RFT variant of ERC72115 // TODO: Implement RFT variant of ERC721
16 None16 None
17 }17 }
27 _source: &sp_core::H160,27 _source: &sp_core::H160,
28 _input: &[u8],28 _input: &[u8],
29 _value: sp_core::U256,29 _value: sp_core::U256,
30 ) -> Option<pallet_common::erc::PrecompileOutput> {30 ) -> Option<pallet_common::erc::PrecompileResult> {
31 // TODO: Implement RFT variant of ERC2031 // TODO: Implement RFT variant of ERC20
32 None32 None
33 }33 }