difftreelog
refactor extract EvmAddressMapping primitive
in: master
10 files changed
pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -15,10 +15,10 @@
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
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' }
+up-evm-mapping = { default-features = false, path = '../../primitives/evm-mapping' }
nft-data-structs = { default-features = false, path = '../../primitives/nft' }
pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
evm-coder = { default-features = false, path = '../../crates/evm-coder' }
-
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
serde = { version = "1.0.130", default-features = false }
scale-info = { version = "1.0.0", default-features = false, features = [
@@ -32,6 +32,7 @@
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
+ "up-evm-mapping/std",
"nft-data-structs/std",
"pallet-evm/std",
]
pallets/common/src/account.rsdiffbeforeafterboth--- a/pallets/common/src/account.rs
+++ b/pallets/common/src/account.rs
@@ -2,12 +2,12 @@
use codec::{Encode, EncodeLike, Decode};
use sp_core::H160;
use scale_info::{Type, TypeInfo};
-use sp_core::crypto::AccountId32;
use core::cmp::Ordering;
use serde::{Serialize, Deserialize};
use pallet_evm::AddressMapping;
use sp_std::vec::Vec;
use sp_std::clone::Clone;
+use up_evm_mapping::EvmBackwardsAddressMapping;
pub trait CrossAccountId<AccountId>:
Encode + EncodeLike + Decode + TypeInfo + Clone + PartialEq + Ord + core::fmt::Debug + Default
@@ -174,19 +174,5 @@
} else {
BasicCrossAccountIdRepr::Substrate(v.as_sub().clone())
}
- }
-}
-
-pub trait EvmBackwardsAddressMapping<AccountId> {
- fn from_account_id(account_id: AccountId) -> H160;
-}
-
-/// Should have same mapping as EnsureAddressTruncated
-pub struct MapBackwardsAddressTruncated;
-impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {
- fn from_account_id(account_id: AccountId32) -> H160 {
- let mut out = [0; 20];
- out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);
- H160(out)
}
}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -141,7 +141,7 @@
pub mod pallet {
use super::*;
use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key};
- use account::{EvmBackwardsAddressMapping, CrossAccountId};
+ use account::CrossAccountId;
use frame_support::traits::Currency;
use nft_data_structs::TokenId;
use scale_info::TypeInfo;
@@ -153,7 +153,7 @@
type CrossAccountId: CrossAccountId<Self::AccountId>;
type EvmAddressMapping: pallet_evm::AddressMapping<Self::AccountId>;
- type EvmBackwardsAddressMapping: EvmBackwardsAddressMapping<Self::AccountId>;
+ type EvmBackwardsAddressMapping: up_evm_mapping::EvmBackwardsAddressMapping<Self::AccountId>;
type Currency: Currency<Self::AccountId>;
type CollectionCreationPrice: Get<
pallets/evm-transaction-payment/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-transaction-payment/Cargo.toml
+++ b/pallets/evm-transaction-payment/Cargo.toml
@@ -15,6 +15,7 @@
fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" }
+up-evm-mapping = { default-features = false, path = "../../primitives/evm-mapping" }
[dependencies.codec]
default-features = false
@@ -35,4 +36,5 @@
"pallet-ethereum/std",
"fp-evm/std",
"up-sponsorship/std",
+ "up-evm-mapping/std",
]
pallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-transaction-payment/src/lib.rs
+++ b/pallets/evm-transaction-payment/src/lib.rs
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub use pallet::*;
+use up_evm_mapping::EvmBackwardsAddressMapping;
#[frame_support::pallet]
pub mod pallet {
@@ -20,6 +21,7 @@
pub trait Config: frame_system::Config {
type SponsorshipHandler: SponsorshipHandler<H160, (H160, Vec<u8>)>;
type Currency: Currency<Self::AccountId>;
+ type EvmBackwardsAddressMapping: EvmBackwardsAddressMapping<Self::AccountId>;
}
#[pallet::pallet]
pallets/nft/Cargo.tomldiffbeforeafterboth1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Substrate node nft'7edition = '2018'8homepage = 'https://unique.network'9license = 'All Rights Reserved'10name = 'pallet-nft'11repository = 'https://github.com/usetech-llc/nft_private/'12version = '3.0.0'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks']20std = [21 'codec/std',22 'serde/std',23 'frame-support/std',24 'frame-system/std',25 'pallet-balances/std',26 'pallet-evm/std',27 'pallet-timestamp/std',28 'pallet-randomness-collective-flip/std',29 'pallet-transaction-payment/std',30 'pallet-common/std',31 'pallet-fungible/std',32 'pallet-nonfungible/std',33 'pallet-refungible/std',34 'fp-evm/std',35 'nft-data-structs/std',36 'up-sponsorship/std',37 'sp-std/std',38 'sp-api/std',39 'sp-runtime/std',40 'frame-benchmarking/std',41 'ethereum/std',42 'rlp/std',4344 'primitive-types/std',45 'evm-coder/std',46 'pallet-evm-coder-substrate/std',47]48limit-testing = ["nft-data-structs/limit-testing"]4950################################################################################51# Substrate Dependencies5253[dependencies.codec]54default-features = false55features = ['derive']56package = 'parity-scale-codec'57version = '2.3.0'5859[dependencies.frame-benchmarking]60default-features = false61optional = true62git = 'https://github.com/paritytech/substrate.git'63branch = 'polkadot-v0.9.12'6465[dependencies.frame-support]66default-features = false67git = 'https://github.com/paritytech/substrate.git'68branch = 'polkadot-v0.9.12'6970[dependencies.frame-system]71default-features = false72git = 'https://github.com/paritytech/substrate.git'73branch = 'polkadot-v0.9.12'7475[dependencies.pallet-balances]76default-features = false77git = 'https://github.com/paritytech/substrate.git'78branch = 'polkadot-v0.9.12'7980[dependencies.pallet-timestamp]81default-features = false82git = 'https://github.com/paritytech/substrate.git'83branch = 'polkadot-v0.9.12'8485[dependencies.pallet-randomness-collective-flip]86default-features = false87git = 'https://github.com/paritytech/substrate.git'88branch = 'polkadot-v0.9.12'8990[dependencies.sp-std]91default-features = false92git = 'https://github.com/paritytech/substrate.git'93branch = 'polkadot-v0.9.12'9495[dependencies.pallet-transaction-payment]96default-features = false97git = 'https://github.com/paritytech/substrate.git'98branch = 'polkadot-v0.9.12'99100[dependencies.serde]101default-features = false102features = ['derive']103version = '1.0.130'104105[dependencies.sp-runtime]106default-features = false107git = 'https://github.com/paritytech/substrate.git'108branch = 'polkadot-v0.9.12'109110[dependencies.sp-core]111default-features = false112git = 'https://github.com/paritytech/substrate.git'113branch = 'polkadot-v0.9.12'114115[dependencies.sp-io]116default-features = false117git = 'https://github.com/paritytech/substrate.git'118branch = 'polkadot-v0.9.12'119120121################################################################################122# Local Dependencies123124[dependencies.nft-data-structs]125default-features = false126path = '../../primitives/nft'127version = '0.9.0'128129[dependencies]130scale-info = { version = "1.0.0", default-features = false, features = [131 "derive",132] }133ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }134rlp = { default-features = false, version = "0.5.0" }135sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.12" }136137up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 138139evm-coder = { default-features = false, path = "../../crates/evm-coder" }140pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }141primitive-types = { version = "0.10.1", default-features = false, features = [142 "serde_no_std",143] }144145pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }146pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }147fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }148hex-literal = "0.3.3"149150pallet-common = { default-features = false, path = "../common" }151pallet-fungible = { default-features = false, path = "../fungible" }152pallet-nonfungible = { default-features = false, path = "../nonfungible" }153pallet-refungible = { default-features = false, path = "../refungible" }1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6description = 'Substrate node nft'7edition = '2018'8homepage = 'https://unique.network'9license = 'All Rights Reserved'10name = 'pallet-nft'11repository = 'https://github.com/usetech-llc/nft_private/'12version = '3.0.0'1314[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']1617[features]18default = ['std']19runtime-benchmarks = ['frame-benchmarking', 'pallet-common/runtime-benchmarks']20std = [21 'codec/std',22 'serde/std',23 'frame-support/std',24 'frame-system/std',25 'pallet-balances/std',26 'pallet-evm/std',27 'pallet-timestamp/std',28 'pallet-randomness-collective-flip/std',29 'pallet-transaction-payment/std',30 'pallet-common/std',31 'pallet-fungible/std',32 'pallet-nonfungible/std',33 'pallet-refungible/std',34 'fp-evm/std',35 'nft-data-structs/std',36 'up-sponsorship/std',37 'up-evm-mapping/std',38 'sp-std/std',39 'sp-api/std',40 'sp-runtime/std',41 'frame-benchmarking/std',42 'ethereum/std',43 'rlp/std',4445 'primitive-types/std',46 'evm-coder/std',47 'pallet-evm-coder-substrate/std',48]49limit-testing = ["nft-data-structs/limit-testing"]5051################################################################################52# Substrate Dependencies5354[dependencies.codec]55default-features = false56features = ['derive']57package = 'parity-scale-codec'58version = '2.3.0'5960[dependencies.frame-benchmarking]61default-features = false62optional = true63git = 'https://github.com/paritytech/substrate.git'64branch = 'polkadot-v0.9.12'6566[dependencies.frame-support]67default-features = false68git = 'https://github.com/paritytech/substrate.git'69branch = 'polkadot-v0.9.12'7071[dependencies.frame-system]72default-features = false73git = 'https://github.com/paritytech/substrate.git'74branch = 'polkadot-v0.9.12'7576[dependencies.pallet-balances]77default-features = false78git = 'https://github.com/paritytech/substrate.git'79branch = 'polkadot-v0.9.12'8081[dependencies.pallet-timestamp]82default-features = false83git = 'https://github.com/paritytech/substrate.git'84branch = 'polkadot-v0.9.12'8586[dependencies.pallet-randomness-collective-flip]87default-features = false88git = 'https://github.com/paritytech/substrate.git'89branch = 'polkadot-v0.9.12'9091[dependencies.sp-std]92default-features = false93git = 'https://github.com/paritytech/substrate.git'94branch = 'polkadot-v0.9.12'9596[dependencies.pallet-transaction-payment]97default-features = false98git = 'https://github.com/paritytech/substrate.git'99branch = 'polkadot-v0.9.12'100101[dependencies.serde]102default-features = false103features = ['derive']104version = '1.0.130'105106[dependencies.sp-runtime]107default-features = false108git = 'https://github.com/paritytech/substrate.git'109branch = 'polkadot-v0.9.12'110111[dependencies.sp-core]112default-features = false113git = 'https://github.com/paritytech/substrate.git'114branch = 'polkadot-v0.9.12'115116[dependencies.sp-io]117default-features = false118git = 'https://github.com/paritytech/substrate.git'119branch = 'polkadot-v0.9.12'120121122################################################################################123# Local Dependencies124125[dependencies.nft-data-structs]126default-features = false127path = '../../primitives/nft'128version = '0.9.0'129130[dependencies]131scale-info = { version = "1.0.0", default-features = false, features = [132 "derive",133] }134ethereum = { version = "0.9", git = "https://github.com/purestake/ethereum", branch = "joshy-scale-info", default-features = false }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" }137138up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 139up-evm-mapping = { default-features = false, path = "../../primitives/evm-mapping" }140evm-coder = { default-features = false, path = "../../crates/evm-coder" }141pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }142primitive-types = { version = "0.10.1", default-features = false, features = [143 "serde_no_std",144] }145146pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }147pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }148fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }149hex-literal = "0.3.3"150151pallet-common = { default-features = false, path = "../common" }152pallet-fungible = { default-features = false, path = "../fungible" }153pallet-nonfungible = { default-features = false, path = "../nonfungible" }154pallet-refungible = { default-features = false, path = "../refungible" }primitives/evm-mapping/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/primitives/evm-mapping/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "up-evm-mapping"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
+frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
+
+[features]
+default = ["std"]
+std = [
+ "sp-core/std",
+ "frame-support/std",
+]
primitives/evm-mapping/src/lib.rsdiffbeforeafterboth--- /dev/null
+++ b/primitives/evm-mapping/src/lib.rs
@@ -0,0 +1,23 @@
+#![cfg_attr(not(feature = "std"), no_std)]
+
+use frame_support::sp_runtime::AccountId32;
+use sp_core::H160;
+
+/// Transforms substrate addresses to ethereum (Reverse of `EvmAddressMapping`)
+/// pallet_evm doesn't have this, as it only checks if eth address
+/// is owned by substrate via `EnsureAddressOrigin` trait
+///
+/// This trait implementations shouldn't conflict with used `EnsureAddressOrigin`
+pub trait EvmBackwardsAddressMapping<AccountId> {
+ fn from_account_id(account_id: AccountId) -> H160;
+}
+
+/// Should have same mapping as EnsureAddressTruncated
+pub struct MapBackwardsAddressTruncated;
+impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {
+ fn from_account_id(account_id: AccountId32) -> H160 {
+ let mut out = [0; 20];
+ out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);
+ H160(out)
+ }
+}
runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -69,6 +69,7 @@
'pallet-ethereum/std',
'fp-rpc/std',
'up-rpc/std',
+ 'up-evm-mapping/std',
'fp-self-contained/std',
'parachain-info/std',
'serde',
@@ -362,7 +363,7 @@
[dependencies.orml-vesting]
git = "https://github.com/open-web3-stack/open-runtime-module-library"
-version = "0.4.1-dev"
+version = "0.4.1-dev"
default-features = false
################################################################################
@@ -375,6 +376,7 @@
derivative = "2.2.0"
pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }
up-rpc = { path = "../primitives/rpc", default-features = false }
+up-evm-mapping = { path = "../primitives/evm-mapping", default-features = false }
pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }
nft-data-structs = { path = '../primitives/nft', default-features = false, version = '0.9.0' }
pallet-common = { default-features = false, path = "../pallets/common" }
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -736,7 +736,7 @@
impl pallet_common::Config for Runtime {
type Event = Event;
- type EvmBackwardsAddressMapping = pallet_common::account::MapBackwardsAddressTruncated;
+ type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;
@@ -811,6 +811,7 @@
pallet_evm_contract_helpers::HelpersContractSponsoring<Self>,
);
type Currency = Balances;
+ type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
}
impl pallet_nft_charge_transaction::Config for Runtime {