git.delta.rocks / unique-network / refs/commits / 35f0b49c19be

difftreelog

style reformat code

Yaroslav Bolyukin2021-06-02parent: #6bc566c.patch.diff
in: master

3 files changed

modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -42,7 +42,7 @@
 rlp = { default-features = false, version = "0.5.0" }
 
 evm-coder = { default-features = false, path = "../../crates/evm-coder" }
-primitive-types = { version = "0.9.0", default-features = false }
+primitive-types = { version = "0.9.0", default-features = false, features = ["serde_no_std"] }
 
 hex-literal = "0.3.1"
 
modifiedpallets/nft/src/eth/account.rsdiffbeforeafterboth
before · pallets/nft/src/eth/account.rs
1use crate::Config;2use codec::{Encode, EncodeLike, Decode};3use sp_core::{H160, H256, crypto::AccountId32};4use core::cmp::Ordering;5use serde::{Serialize, Deserialize};6use pallet_evm::AddressMapping;7use sp_std::vec::Vec;8use sp_std::clone::Clone;910pub trait CrossAccountId<AccountId>: 11    Encode + EncodeLike + Decode + 12    Clone + PartialEq + Ord + core::fmt::Debug // + 13    // Serialize + Deserialize<'static> 14{15    fn as_sub(&self) -> &AccountId;16    fn as_eth(&self) -> &H160;1718    fn from_sub(account: AccountId) -> Self;19    fn from_eth(account: H160) -> Self;20}2122#[derive(Eq)]23#[derive(Serialize, Deserialize)]24pub struct BasicCrossAccountId<T: Config> {25    /// If true - then ethereum is canonical encoding26    from_ethereum: bool,27    substrate: T::AccountId,28    ethereum: H160,29}3031impl<T: Config> core::fmt::Debug for BasicCrossAccountId<T> {32    fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {33        if self.from_ethereum {34            fmt.debug_tuple("CrossAccountId::Ethereum")35                .field(&self.ethereum)36                .finish()37        } else {38            fmt.debug_tuple("CrossAccountId::Substrate")39                .field(&self.substrate)40                .finish()41        }42    }43}4445impl<T: Config> PartialOrd for BasicCrossAccountId<T> {46    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {47        Some(self.substrate.cmp(&other.substrate))48    }49}5051impl<T: Config> Ord for BasicCrossAccountId<T> {52    fn cmp(&self, other: &Self) -> Ordering {53        self.partial_cmp(other).expect("substrate account is total ordered")54    }55}5657impl<T: Config> PartialEq for BasicCrossAccountId<T> {58    fn eq(&self, other: &Self) -> bool {59        if self.from_ethereum == other.from_ethereum {60            self.substrate == other.substrate && self.ethereum == other.ethereum61        } else if self.from_ethereum {62            // ethereum is canonical encoding, but we need to compare derived address63            self.substrate == other.substrate64        } else {65            self.ethereum == other.ethereum66        }67    }68}69impl<T: Config> Clone for BasicCrossAccountId<T> {70    fn clone(&self) -> Self {71        Self {72            from_ethereum: self.from_ethereum,73            substrate: self.substrate.clone(),74            ethereum: self.ethereum,75        }76    }77}78impl<T: Config> Encode for BasicCrossAccountId<T> {79    fn encode(&self) -> Vec<u8> {80        let as_result = if !self.from_ethereum {81            Ok(self.substrate.clone())82        } else {83            Err(self.ethereum)84        };85        as_result.encode()86    }87}88impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}89impl<T: Config> Decode for BasicCrossAccountId<T> {90    fn decode<I>(input: &mut I) -> Result<Self, codec::Error>91        where I: codec::Input92    {93        Ok(match <Result<T::AccountId, H160>>::decode(input)? {94            Ok(s) => Self::from_sub(s),95            Err(e) => Self::from_eth(e),96        })97    }98}99impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {100    fn as_sub(&self) -> &T::AccountId {101        &self.substrate102    }103    fn as_eth(&self) -> &H160 {104        &self.ethereum105    }106    fn from_sub(substrate: T::AccountId) -> Self {107        Self {108            ethereum: T::EvmBackwardsAddressMapping::from_account_id(substrate.clone()),109            substrate,110            from_ethereum: false,111        }112    }113    fn from_eth(ethereum: H160) -> Self {114        Self {115            ethereum,116            substrate: T::EvmAddressMapping::into_account_id(ethereum),117            from_ethereum: true,118        }119    }120}121122pub trait EvmBackwardsAddressMapping<AccountId> {123    fn from_account_id(account_id: AccountId) -> H160;124}125126/// Should have same mapping as EnsureAddressTruncated127pub struct MapBackwardsAddressTruncated;128impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {129    fn from_account_id(account_id: AccountId32) -> H160 {130        let mut out = [0; 20];131        out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);132        H160(out)133    }134}
after · pallets/nft/src/eth/account.rs
1use crate::Config;2use codec::{Encode, EncodeLike, Decode};3use sp_core::crypto::AccountId32;4use primitive_types::H160;5use core::cmp::Ordering;6use serde::{Serialize, Deserialize};7use pallet_evm::AddressMapping;8use sp_std::vec::Vec;9use sp_std::clone::Clone;1011pub trait CrossAccountId<AccountId>: 12    Encode + EncodeLike + Decode + 13    Clone + PartialEq + Ord + core::fmt::Debug // + 14    // Serialize + Deserialize<'static> 15{16    fn as_sub(&self) -> &AccountId;17    fn as_eth(&self) -> &H160;1819    fn from_sub(account: AccountId) -> Self;20    fn from_eth(account: H160) -> Self;21}2223#[derive(Eq)]24#[derive(Serialize, Deserialize)]25pub struct BasicCrossAccountId<T: Config> {26    /// If true - then ethereum is canonical encoding27    from_ethereum: bool,28    substrate: T::AccountId,29    ethereum: H160,30}3132impl<T: Config> core::fmt::Debug for BasicCrossAccountId<T> {33    fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {34        if self.from_ethereum {35            fmt.debug_tuple("CrossAccountId::Ethereum")36                .field(&self.ethereum)37                .finish()38        } else {39            fmt.debug_tuple("CrossAccountId::Substrate")40                .field(&self.substrate)41                .finish()42        }43    }44}4546impl<T: Config> PartialOrd for BasicCrossAccountId<T> {47    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {48        Some(self.substrate.cmp(&other.substrate))49    }50}5152impl<T: Config> Ord for BasicCrossAccountId<T> {53    fn cmp(&self, other: &Self) -> Ordering {54        self.partial_cmp(other).expect("substrate account is total ordered")55    }56}5758impl<T: Config> PartialEq for BasicCrossAccountId<T> {59    fn eq(&self, other: &Self) -> bool {60        if self.from_ethereum == other.from_ethereum {61            self.substrate == other.substrate && self.ethereum == other.ethereum62        } else if self.from_ethereum {63            // ethereum is canonical encoding, but we need to compare derived address64            self.substrate == other.substrate65        } else {66            self.ethereum == other.ethereum67        }68    }69}70impl<T: Config> Clone for BasicCrossAccountId<T> {71    fn clone(&self) -> Self {72        Self {73            from_ethereum: self.from_ethereum,74            substrate: self.substrate.clone(),75            ethereum: self.ethereum,76        }77    }78}79impl<T: Config> Encode for BasicCrossAccountId<T> {80    fn encode(&self) -> Vec<u8> {81        let as_result = if !self.from_ethereum {82            Ok(self.substrate.clone())83        } else {84            Err(self.ethereum)85        };86        as_result.encode()87    }88}89impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}90impl<T: Config> Decode for BasicCrossAccountId<T> {91    fn decode<I>(input: &mut I) -> Result<Self, codec::Error>92        where I: codec::Input93    {94        Ok(match <Result<T::AccountId, H160>>::decode(input)? {95            Ok(s) => Self::from_sub(s),96            Err(e) => Self::from_eth(e),97        })98    }99}100impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {101    fn as_sub(&self) -> &T::AccountId {102        &self.substrate103    }104    fn as_eth(&self) -> &H160 {105        &self.ethereum106    }107    fn from_sub(substrate: T::AccountId) -> Self {108        Self {109            ethereum: T::EvmBackwardsAddressMapping::from_account_id(substrate.clone()),110            substrate,111            from_ethereum: false,112        }113    }114    fn from_eth(ethereum: H160) -> Self {115        Self {116            ethereum,117            substrate: T::EvmAddressMapping::into_account_id(ethereum),118            from_ethereum: true,119        }120    }121}122123pub trait EvmBackwardsAddressMapping<AccountId> {124    fn from_account_id(account_id: AccountId) -> H160;125}126127/// Should have same mapping as EnsureAddressTruncated128pub struct MapBackwardsAddressTruncated;129impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {130    fn from_account_id(account_id: AccountId32) -> H160 {131        let mut out = [0; 20];132        out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);133        H160(out)134    }135}
modifiedpallets/nft/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/mod.rs
+++ b/pallets/nft/src/eth/mod.rs
@@ -1,25 +1,31 @@
 pub mod account;
-use account::CrossAccountId;
-pub mod abi;
-use abi::{AbiReader, AbiWriter};
+pub mod erc;
+mod erc_impl;
 pub mod log;
+pub mod sponsoring;
 
+use evm_coder::abi::AbiWriter;
+use evm_coder::abi::StringError;
+use sp_std::prelude::*;
 use sp_std::borrow::ToOwned;
 use sp_std::vec::Vec;
-use sp_std::convert::TryInto;
 
-use codec::{Decode, Encode};
-use pallet_evm::{AddressMapping, PrecompileLog, PrecompileOutput, ExitReason, ExitRevert, ExitSucceed};
-use sp_core::{H160, H256};
-use frame_support::storage::{StorageMap, StorageDoubleMap};
+use pallet_evm::{PrecompileOutput, ExitReason, ExitRevert, ExitSucceed};
+use sp_core::{H160, U256};
+use frame_support::storage::StorageMap;
+
+use crate::{Config, CollectionById, CollectionHandle, CollectionId, CollectionMode};
 
-use crate::{Allowances, NftItemList, Module, Balance, Config, CollectionById, CollectionHandle, CollectionId, CollectionMode};
+use erc::{UniqueFungible, UniqueFungibleCall, UniqueNFT, UniqueNFTCall};
+use evm_coder::{types::*, abi::AbiReader};
 
 pub struct NftErcSupport<T: Config>(core::marker::PhantomData<T>);
 
 // 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection
 // TODO: Unhardcode prefix
-const ETH_ACCOUNT_PREFIX: [u8; 16] = [0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e];
+const ETH_ACCOUNT_PREFIX: [u8; 16] = [
+	0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e,
+];
 
 fn map_eth_to_id(eth: &H160) -> Option<CollectionId> {
 	if &eth[0..16] != ETH_ACCOUNT_PREFIX {
@@ -113,7 +119,8 @@
 					CollectionMode::Fungible(_) => include_bytes!("stubs/ERC20.bin") as &[u8],
 					CollectionMode::ReFungible => include_bytes!("stubs/ERC1633.bin") as &[u8],
 					CollectionMode::Invalid => include_bytes!("stubs/Invalid.bin") as &[u8],
-				}.to_owned()
+				}
+				.to_owned()
 			})
 	}
 	fn call(
@@ -162,17 +169,20 @@
 			gas: 0.into(),
 			// zero selector, this transaction always have same sender, so all data should be acquired from logs
 			data: Vec::from([0, 0, 0, 0]),
-		}.sign(
+		}
+		.sign(
 			// TODO: move to pallet config
 			// 0xF70631E55faff9f3FD3681545aa6c724226a3853
 			// 9dbaef9b3ebc00e53f67c6a77bcfbf2c4f2aebe4d70d94af4f2df01744b7a91a
-			&hex_literal::hex!("9dbaef9b3ebc00e53f67c6a77bcfbf2c4f2aebe4d70d94af4f2df01744b7a91a").into(),
-			&chain_id
+			&hex_literal::hex!("9dbaef9b3ebc00e53f67c6a77bcfbf2c4f2aebe4d70d94af4f2df01744b7a91a")
+				.into(),
+			&chain_id,
 		);
-		rlp::decode::<ethereum::Transaction>(&signed).expect("transaction is just created, it can't be broken")
+		rlp::decode::<ethereum::Transaction>(&signed)
+			.expect("transaction is just created, it can't be broken")
 	}
 	#[cfg(not(feature = "std"))]
 	{
 		panic!("transaction generation not yet supported by wasm runtime")
 	}
-}
\ No newline at end of file
+}