git.delta.rocks / unique-network / refs/commits / 98884c814ce4

difftreelog

refactor return CrossAccountId in backing storages

Yaroslav Bolyukin2021-11-04parent: #8ccb268.patch.diff
in: master

14 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -75,9 +75,17 @@
 	) -> Result<String>;
 
 	#[rpc(name = "nft_adminlist")]
-	fn adminlist(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<Vec<AccountId>>;
+	fn adminlist(
+		&self,
+		collection: CollectionId,
+		at: Option<BlockHash>,
+	) -> Result<Vec<CrossAccountId>>;
 	#[rpc(name = "nft_allowlist")]
-	fn allowlist(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<Vec<AccountId>>;
+	fn allowlist(
+		&self,
+		collection: CollectionId,
+		at: Option<BlockHash>,
+	) -> Result<Vec<CrossAccountId>>;
 	#[rpc(name = "nft_lastTokenId")]
 	fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;
 }
@@ -150,7 +158,7 @@
 	pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());
 	pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());
 
-	pass_method!(adminlist(collection: CollectionId) -> Vec<AccountId>);
-	pass_method!(allowlist(collection: CollectionId) -> Vec<AccountId>);
+	pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>);
+	pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>);
 	pass_method!(last_token_id(collection: CollectionId) -> TokenId);
 }
modifiedpallets/common/src/account.rsdiffbeforeafterboth
--- a/pallets/common/src/account.rs
+++ b/pallets/common/src/account.rs
@@ -19,6 +19,8 @@
 
 	fn from_sub(account: AccountId) -> Self;
 	fn from_eth(account: H160) -> Self;
+
+	fn conv_eq(&self, other: &Self) -> bool;
 }
 
 #[derive(Encode, Decode, Serialize, Deserialize, TypeInfo)]
@@ -28,7 +30,7 @@
 	Ethereum(H160),
 }
 
-#[derive(Eq)]
+#[derive(PartialEq, Eq)]
 pub struct BasicCrossAccountId<T: Config> {
 	/// If true - then ethereum is canonical encoding
 	from_ethereum: bool,
@@ -77,18 +79,6 @@
 	}
 }
 
-impl<T: Config> PartialEq for BasicCrossAccountId<T> {
-	fn eq(&self, other: &Self) -> bool {
-		if self.from_ethereum == other.from_ethereum {
-			self.substrate == other.substrate && self.ethereum == other.ethereum
-		} else if self.from_ethereum {
-			// ethereum is canonical encoding, but we need to compare derived address
-			self.substrate == other.substrate
-		} else {
-			self.ethereum == other.ethereum
-		}
-	}
-}
 impl<T: Config> Clone for BasicCrossAccountId<T> {
 	fn clone(&self) -> Self {
 		Self {
@@ -158,6 +148,16 @@
 			from_ethereum: true,
 		}
 	}
+	fn conv_eq(&self, other: &Self) -> bool {
+		if self.from_ethereum == other.from_ethereum {
+			self.substrate == other.substrate && self.ethereum == other.ethereum
+		} else if self.from_ethereum {
+			// ethereum is canonical encoding, but we need to compare derived address
+			self.substrate == other.substrate
+		} else {
+			self.ethereum == other.ethereum
+		}
+	}
 }
 impl<T: Config> From<BasicCrossAccountIdRepr<T::AccountId>> for BasicCrossAccountId<T> {
 	fn from(repr: BasicCrossAccountIdRepr<T::AccountId>) -> Self {
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -98,7 +98,7 @@
 	pub fn is_owner_or_admin(&self, subject: &T::CrossAccountId) -> Result<bool, DispatchError> {
 		self.consume_sload()?;
 
-		Ok(*subject.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, subject.as_sub())))
+		Ok(*subject.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, subject)))
 	}
 	pub fn check_is_owner_or_admin(&self, subject: &T::CrossAccountId) -> DispatchResult {
 		ensure!(self.is_owner_or_admin(subject)?, <Error<T>>::NoPermission);
@@ -114,7 +114,7 @@
 		self.consume_sload()?;
 
 		ensure!(
-			<Allowlist<T>>::get((self.id, user.as_sub())),
+			<Allowlist<T>>::get((self.id, user)),
 			<Error<T>>::AddressNotInAllowlist
 		);
 		Ok(())
@@ -139,8 +139,7 @@
 #[frame_support::pallet]
 pub mod pallet {
 	use super::*;
-	use frame_support::{pallet_prelude::*};
-	use frame_support::{Blake2_128Concat, storage::Key};
+	use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key};
 	use account::{EvmBackwardsAddressMapping, CrossAccountId};
 	use frame_support::traits::Currency;
 	use nft_data_structs::TokenId;
@@ -311,7 +310,7 @@
 	pub type IsAdmin<T: Config> = StorageNMap<
 		Key = (
 			Key<Blake2_128Concat, CollectionId>,
-			Key<Blake2_128Concat, T::AccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>,
 		),
 		Value = bool,
 		QueryKind = ValueQuery,
@@ -322,7 +321,7 @@
 	pub type Allowlist<T: Config> = StorageNMap<
 		Key = (
 			Key<Blake2_128Concat, CollectionId>,
-			Key<Blake2_128Concat, T::AccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>,
 		),
 		Value = bool,
 		QueryKind = ValueQuery,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -2,9 +2,7 @@
 
 use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};
 use nft_data_structs::TokenId;
-use pallet_common::{
-	CommonCollectionOperations, CommonWeightInfo, account::CrossAccountId, with_weight,
-};
+use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::ArithmeticError;
 use sp_std::{vec::Vec, vec};
 
@@ -188,7 +186,7 @@
 	}
 
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
-		if <Balance<T>>::get((self.id, account.as_sub())) != 0 {
+		if <Balance<T>>::get((self.id, account)) != 0 {
 			vec![TokenId::default()]
 		} else {
 			vec![]
@@ -218,7 +216,7 @@
 	}
 
 	fn account_balance(&self, account: T::CrossAccountId) -> u32 {
-		if <Balance<T>>::get((self.id, account.as_sub())) != 0 {
+		if <Balance<T>>::get((self.id, account)) != 0 {
 			1
 		} else {
 			0
@@ -229,7 +227,7 @@
 		if token != TokenId::default() {
 			return 0;
 		}
-		<Balance<T>>::get((self.id, account.as_sub()))
+		<Balance<T>>::get((self.id, account))
 	}
 
 	fn allowance(
@@ -241,6 +239,6 @@
 		if token != TokenId::default() {
 			return 0;
 		}
-		<Allowance<T>>::get((self.id, sender.as_sub(), spender.as_sub()))
+		<Allowance<T>>::get((self.id, sender, spender))
 	}
 }
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -52,7 +52,7 @@
 	}
 	fn balance_of(&self, owner: address) -> Result<uint256> {
 		let owner = T::CrossAccountId::from_eth(owner);
-		let balance = <Balance<T>>::get((self.id, owner.as_sub()));
+		let balance = <Balance<T>>::get((self.id, owner));
 		Ok(balance.into())
 	}
 	fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {
@@ -92,7 +92,7 @@
 		let owner = T::CrossAccountId::from_eth(owner);
 		let spender = T::CrossAccountId::from_eth(spender);
 
-		Ok(<Allowance<T>>::get((self.id, owner.as_sub(), spender.as_sub())).into())
+		Ok(<Allowance<T>>::get((self.id, owner, spender)).into())
 	}
 }
 
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -55,7 +55,7 @@
 	pub(super) type Balance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
-			Key<Blake2_128Concat, T::AccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>,
 		),
 		Value = u128,
 		QueryKind = ValueQuery,
@@ -65,8 +65,8 @@
 	pub(super) type Allowance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
-			Key<Blake2_128, T::AccountId>,
-			Key<Blake2_128Concat, T::AccountId>,
+			Key<Blake2_128, T::CrossAccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>,
 		),
 		Value = u128,
 		QueryKind = ValueQuery,
@@ -119,7 +119,7 @@
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
 
-		let balance = <Balance<T>>::get((collection.id, owner.as_sub()))
+		let balance = <Balance<T>>::get((collection.id, owner))
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
 
@@ -130,9 +130,9 @@
 		// =========
 
 		if balance == 0 {
-			<Balance<T>>::remove((collection.id, owner.as_sub()));
+			<Balance<T>>::remove((collection.id, owner));
 		} else {
-			<Balance<T>>::insert((collection.id, owner.as_sub()), balance);
+			<Balance<T>>::insert((collection.id, owner), balance);
 		}
 		<TotalSupply<T>>::insert(collection.id, total_supply);
 
@@ -167,12 +167,12 @@
 		}
 		<PalletCommon<T>>::ensure_correct_receiver(to)?;
 
-		let balance_from = <Balance<T>>::get((collection.id, from.as_sub()))
+		let balance_from = <Balance<T>>::get((collection.id, from))
 			.checked_sub(amount)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
 		let balance_to = if from != to {
 			Some(
-				<Balance<T>>::get((collection.id, to.as_sub()))
+				<Balance<T>>::get((collection.id, to))
 					.checked_add(amount)
 					.ok_or(ArithmeticError::Overflow)?,
 			)
@@ -190,11 +190,11 @@
 		if let Some(balance_to) = balance_to {
 			// from != to
 			if balance_from == 0 {
-				<Balance<T>>::remove((collection.id, from.as_sub()));
+				<Balance<T>>::remove((collection.id, from));
 			} else {
-				<Balance<T>>::insert((collection.id, from.as_sub()), balance_from);
+				<Balance<T>>::insert((collection.id, from), balance_from);
 			}
-			<Balance<T>>::insert((collection.id, to.as_sub()), balance_to);
+			<Balance<T>>::insert((collection.id, to), balance_to);
 		}
 
 		collection.log_infallible(ERC20Events::Transfer {
@@ -242,7 +242,7 @@
 			collection.consume_sload()?;
 			let balance = balances
 				.entry(user.clone())
-				.or_insert_with(|| <Balance<T>>::get((collection.id, user.as_sub())));
+				.or_insert_with(|| <Balance<T>>::get((collection.id, user)));
 			*balance = (*balance)
 				.checked_add(amount)
 				.ok_or(ArithmeticError::Overflow)?;
@@ -259,7 +259,7 @@
 
 		<TotalSupply<T>>::insert(collection.id, total_supply);
 		for (user, amount) in balances {
-			<Balance<T>>::insert((collection.id, user.as_sub()), amount);
+			<Balance<T>>::insert((collection.id, &user), amount);
 
 			collection.log_infallible(ERC20Events::Transfer {
 				from: H160::default(),
@@ -283,7 +283,7 @@
 		spender: &T::CrossAccountId,
 		amount: u128,
 	) {
-		<Allowance<T>>::insert((collection.id, owner.as_sub(), spender.as_sub()), amount);
+		<Allowance<T>>::insert((collection.id, owner, spender), amount);
 
 		collection.log_infallible(ERC20Events::Approval {
 			owner: *owner.as_eth(),
@@ -310,7 +310,7 @@
 			collection.check_allowlist(&spender)?;
 		}
 
-		if <Balance<T>>::get((collection.id, owner.as_sub())) < amount {
+		if <Balance<T>>::get((collection.id, owner)) < amount {
 			ensure!(
 				collection.ignores_owned_amount(owner)?,
 				<CommonError<T>>::CantApproveMoreThanOwned
@@ -330,7 +330,7 @@
 		to: &T::CrossAccountId,
 		amount: u128,
 	) -> DispatchResult {
-		if spender == from {
+		if spender.conv_eq(from) {
 			return Self::transfer(collection, from, to, amount);
 		}
 		if collection.access == AccessMode::WhiteList {
@@ -338,8 +338,7 @@
 			collection.check_allowlist(spender)?;
 		}
 
-		let allowance = <Allowance<T>>::get((collection.id, from.as_sub(), spender.as_sub()))
-			.checked_sub(amount);
+		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);
 		if allowance.is_none() {
 			ensure!(
 				collection.ignores_allowance(spender)?,
@@ -362,7 +361,7 @@
 		from: &T::CrossAccountId,
 		amount: u128,
 	) -> DispatchResult {
-		if spender == from {
+		if spender.conv_eq(from) {
 			return Self::burn(collection, from, amount);
 		}
 		if collection.access == AccessMode::WhiteList {
@@ -370,8 +369,7 @@
 			collection.check_allowlist(spender)?;
 		}
 
-		let allowance = <Allowance<T>>::get((collection.id, from.as_sub(), spender.as_sub()))
-			.checked_sub(amount);
+		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);
 		if allowance.is_none() {
 			ensure!(
 				collection.ignores_allowance(spender)?,
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -948,12 +948,12 @@
 
 // TODO: limit returned entries?
 impl<T: Config> Pallet<T> {
-	pub fn adminlist(collection: CollectionId) -> Vec<T::AccountId> {
+	pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {
 		<IsAdmin<T>>::iter_prefix((collection,))
 			.map(|(a, _)| a)
 			.collect()
 	}
-	pub fn allowlist(collection: CollectionId) -> Vec<T::AccountId> {
+	pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {
 		<Allowlist<T>>::iter_prefix((collection,))
 			.map(|(a, _)| a)
 			.collect()
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -2,9 +2,7 @@
 
 use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight};
 use nft_data_structs::TokenId;
-use pallet_common::{
-	CommonCollectionOperations, CommonWeightInfo, account::CrossAccountId, with_weight,
-};
+use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::DispatchError;
 use sp_std::vec::Vec;
 
@@ -200,7 +198,7 @@
 	}
 
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
-		<Owned<T>>::iter_prefix((self.id, account.as_sub()))
+		<Owned<T>>::iter_prefix((self.id, account))
 			.map(|(id, _)| id)
 			.collect()
 	}
@@ -234,7 +232,7 @@
 	}
 
 	fn account_balance(&self, account: T::CrossAccountId) -> u32 {
-		<AccountBalance<T>>::get((self.id, account.as_sub()))
+		<AccountBalance<T>>::get((self.id, account))
 	}
 
 	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -93,7 +93,7 @@
 impl<T: Config> NonfungibleHandle<T> {
 	fn balance_of(&self, owner: address) -> Result<uint256> {
 		let owner = T::CrossAccountId::from_eth(owner);
-		let balance = <AccountBalance<T>>::get((self.id, owner.as_sub()));
+		let balance = <AccountBalance<T>>::get((self.id, owner));
 		Ok(balance.into())
 	}
 	fn owner_of(&self, token_id: uint256) -> Result<address> {
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -80,7 +80,7 @@
 	pub(super) type Owned<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
-			Key<Blake2_128Concat, T::AccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>,
 			Key<Twox64Concat, TokenId>,
 		),
 		Value = bool,
@@ -91,7 +91,7 @@
 	pub(super) type AccountBalance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
-			Key<Blake2_128Concat, T::AccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>,
 		),
 		Value = u32,
 		QueryKind = ValueQuery,
@@ -179,7 +179,7 @@
 
 		// =========
 
-		<Owned<T>>::remove((collection.id, token_data.owner.as_sub(), token));
+		<Owned<T>>::remove((collection.id, &token_data.owner, token));
 		<TokensBurnt<T>>::insert(collection.id, burnt);
 		<TokenData<T>>::remove((collection.id, token));
 		let old_spender = <Allowance<T>>::take((collection.id, token));
@@ -234,11 +234,11 @@
 		}
 		<PalletCommon<T>>::ensure_correct_receiver(to)?;
 
-		let balance_from = <AccountBalance<T>>::get((collection.id, from.as_sub()))
+		let balance_from = <AccountBalance<T>>::get((collection.id, from))
 			.checked_sub(1)
 			.ok_or(<CommonError<T>>::TokenValueTooLow)?;
 		let balance_to = if from != to {
-			let balance_to = <AccountBalance<T>>::get((collection.id, to.as_sub()))
+			let balance_to = <AccountBalance<T>>::get((collection.id, to))
 				.checked_add(1)
 				.ok_or(ArithmeticError::Overflow)?;
 
@@ -268,13 +268,13 @@
 		if let Some(balance_to) = balance_to {
 			// from != to
 			if balance_from == 0 {
-				<AccountBalance<T>>::remove((collection.id, from.as_sub()));
+				<AccountBalance<T>>::remove((collection.id, from));
 			} else {
-				<AccountBalance<T>>::insert((collection.id, from.as_sub()), balance_from);
+				<AccountBalance<T>>::insert((collection.id, from), balance_from);
 			}
-			<AccountBalance<T>>::insert((collection.id, to.as_sub()), balance_to);
-			<Owned<T>>::remove((collection.id, from.as_sub(), token));
-			<Owned<T>>::insert((collection.id, to.as_sub(), token), true);
+			<AccountBalance<T>>::insert((collection.id, to), balance_to);
+			<Owned<T>>::remove((collection.id, from, token));
+			<Owned<T>>::insert((collection.id, to, token), true);
 		}
 		Self::set_allowance_unchecked(collection, from, token, None, true);
 
@@ -336,8 +336,8 @@
 		let mut balances = BTreeMap::new();
 		for data in &data {
 			let balance = balances
-				.entry(data.owner.as_sub())
-				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, data.owner.as_sub())));
+				.entry(&data.owner)
+				.or_insert_with(|| <AccountBalance<T>>::get((collection.id, &data.owner)));
 			*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;
 
 			ensure!(
@@ -364,7 +364,7 @@
 					owner: data.owner.clone(),
 				},
 			);
-			<Owned<T>>::insert((collection.id, data.owner.as_sub(), token), true);
+			<Owned<T>>::insert((collection.id, &data.owner, token), true);
 
 			collection.log_infallible(ERC721Events::Transfer {
 				from: H160::default(),
@@ -481,7 +481,7 @@
 		to: &T::CrossAccountId,
 		token: TokenId,
 	) -> DispatchResult {
-		if spender == from {
+		if spender.conv_eq(from) {
 			return Self::transfer(collection, from, to, token);
 		}
 		if collection.access == AccessMode::WhiteList {
@@ -509,7 +509,7 @@
 		from: &T::CrossAccountId,
 		token: TokenId,
 	) -> DispatchResult {
-		if spender == from {
+		if spender.conv_eq(from) {
 			return Self::burn(collection, from, token);
 		}
 		if collection.access == AccessMode::WhiteList {
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -3,9 +3,7 @@
 use sp_std::collections::btree_map::BTreeMap;
 use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight};
 use nft_data_structs::TokenId;
-use pallet_common::{
-	CommonCollectionOperations, CommonWeightInfo, account::CrossAccountId, with_weight,
-};
+use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::DispatchError;
 use sp_std::vec::Vec;
 
@@ -196,7 +194,7 @@
 	}
 
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
-		<Owned<T>>::iter_prefix((self.id, account.as_sub()))
+		<Owned<T>>::iter_prefix((self.id, account))
 			.map(|(id, _)| id)
 			.collect()
 	}
@@ -224,11 +222,11 @@
 	}
 
 	fn account_balance(&self, account: T::CrossAccountId) -> u32 {
-		<AccountBalance<T>>::get((self.id, account.as_sub()))
+		<AccountBalance<T>>::get((self.id, account))
 	}
 
 	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {
-		<Balance<T>>::get((self.id, token, account.as_sub()))
+		<Balance<T>>::get((self.id, token, account))
 	}
 
 	fn allowance(
@@ -237,6 +235,6 @@
 		spender: T::CrossAccountId,
 		token: TokenId,
 	) -> u128 {
-		<Allowance<T>>::get((self.id, token, sender.as_sub(), spender))
+		<Allowance<T>>::get((self.id, token, sender, spender))
 	}
 }
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
83 pub(super) type Owned<T: Config> = StorageNMap<83 pub(super) type Owned<T: Config> = StorageNMap<
84 Key = (84 Key = (
85 Key<Twox64Concat, CollectionId>,85 Key<Twox64Concat, CollectionId>,
86 Key<Blake2_128Concat, T::AccountId>,86 Key<Blake2_128Concat, T::CrossAccountId>,
87 Key<Twox64Concat, TokenId>,87 Key<Twox64Concat, TokenId>,
88 ),88 ),
89 Value = bool,89 Value = bool,
95 Key = (95 Key = (
96 Key<Twox64Concat, CollectionId>,96 Key<Twox64Concat, CollectionId>,
97 // Owner97 // Owner
98 Key<Blake2_128Concat, T::AccountId>,98 Key<Blake2_128Concat, T::CrossAccountId>,
99 ),99 ),
100 Value = u32,100 Value = u32,
101 QueryKind = ValueQuery,101 QueryKind = ValueQuery,
107 Key<Twox64Concat, CollectionId>,107 Key<Twox64Concat, CollectionId>,
108 Key<Twox64Concat, TokenId>,108 Key<Twox64Concat, TokenId>,
109 // Owner109 // Owner
110 Key<Blake2_128Concat, T::AccountId>,110 Key<Blake2_128Concat, T::CrossAccountId>,
111 ),111 ),
112 Value = u128,112 Value = u128,
113 QueryKind = ValueQuery,113 QueryKind = ValueQuery,
119 Key<Twox64Concat, CollectionId>,119 Key<Twox64Concat, CollectionId>,
120 Key<Twox64Concat, TokenId>,120 Key<Twox64Concat, TokenId>,
121 // Owner121 // Owner
122 Key<Blake2_128, T::AccountId>,122 Key<Blake2_128, T::CrossAccountId>,
123 // Spender123 // Spender
124 Key<Blake2_128Concat, T::CrossAccountId>,124 Key<Blake2_128Concat, T::CrossAccountId>,
125 ),125 ),
206 if total_supply == 0 {206 if total_supply == 0 {
207 // Ensure user actually owns this amount207 // Ensure user actually owns this amount
208 ensure!(208 ensure!(
209 <Balance<T>>::get((collection.id, token, owner.as_sub())) == amount,209 <Balance<T>>::get((collection.id, token, owner)) == amount,
210 <CommonError<T>>::TokenValueTooLow210 <CommonError<T>>::TokenValueTooLow
211 );211 );
212 let account_balance = <AccountBalance<T>>::get((collection.id, owner.as_sub()))212 let account_balance = <AccountBalance<T>>::get((collection.id, owner))
213 .checked_sub(1)213 .checked_sub(1)
214 // Should not occur214 // Should not occur
215 .ok_or(ArithmeticError::Underflow)?;215 .ok_or(ArithmeticError::Underflow)?;
216216
217 // =========217 // =========
218218
219 <Owned<T>>::remove((collection.id, owner.as_sub(), token));219 <Owned<T>>::remove((collection.id, owner, token));
220 <AccountBalance<T>>::insert((collection.id, owner.as_sub()), account_balance);220 <AccountBalance<T>>::insert((collection.id, owner), account_balance);
221 Self::burn_token(collection, token)?;221 Self::burn_token(collection, token)?;
222 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(222 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
223 collection.id,223 collection.id,
228 return Ok(());228 return Ok(());
229 }229 }
230230
231 let balance = <Balance<T>>::get((collection.id, token, owner.as_sub()))231 let balance = <Balance<T>>::get((collection.id, token, owner))
232 .checked_sub(amount)232 .checked_sub(amount)
233 .ok_or(<CommonError<T>>::TokenValueTooLow)?;233 .ok_or(<CommonError<T>>::TokenValueTooLow)?;
234 let account_balance = if balance == 0 {234 let account_balance = if balance == 0 {
235 <AccountBalance<T>>::get((collection.id, owner.as_sub()))235 <AccountBalance<T>>::get((collection.id, owner))
236 .checked_sub(1)236 .checked_sub(1)
237 // Should not occur237 // Should not occur
238 .ok_or(ArithmeticError::Underflow)?238 .ok_or(ArithmeticError::Underflow)?
243 // =========243 // =========
244244
245 if balance == 0 {245 if balance == 0 {
246 <Owned<T>>::remove((collection.id, owner.as_sub(), token));246 <Owned<T>>::remove((collection.id, owner, token));
247 <Balance<T>>::remove((collection.id, token, owner.as_sub()));247 <Balance<T>>::remove((collection.id, token, owner));
248 <AccountBalance<T>>::insert((collection.id, owner.as_sub()), account_balance);248 <AccountBalance<T>>::insert((collection.id, owner), account_balance);
249 } else {249 } else {
250 <Balance<T>>::insert((collection.id, token, owner.as_sub()), balance);250 <Balance<T>>::insert((collection.id, token, owner), balance);
251 }251 }
252 <TotalSupply<T>>::insert((collection.id, token), total_supply);252 <TotalSupply<T>>::insert((collection.id, token), total_supply);
253 // TODO: ERC20 transfer event253 // TODO: ERC20 transfer event
278 }278 }
279 <PalletCommon<T>>::ensure_correct_receiver(to)?;279 <PalletCommon<T>>::ensure_correct_receiver(to)?;
280280
281 let balance_from = <Balance<T>>::get((collection.id, token, from.as_sub()))281 let balance_from = <Balance<T>>::get((collection.id, token, from))
282 .checked_sub(amount)282 .checked_sub(amount)
283 .ok_or(<CommonError<T>>::TokenValueTooLow)?;283 .ok_or(<CommonError<T>>::TokenValueTooLow)?;
284 let mut create_target = false;284 let mut create_target = false;
285 let from_to_differ = from != to;285 let from_to_differ = from != to;
286 let balance_to = if from != to {286 let balance_to = if from != to {
287 let old_balance = <Balance<T>>::get((collection.id, token, to.as_sub()));287 let old_balance = <Balance<T>>::get((collection.id, token, to));
288 if old_balance == 0 {288 if old_balance == 0 {
289 create_target = true;289 create_target = true;
290 }290 }
299299
300 let account_balance_from = if balance_from == 0 {300 let account_balance_from = if balance_from == 0 {
301 Some(301 Some(
302 <AccountBalance<T>>::get((collection.id, from.as_sub()))302 <AccountBalance<T>>::get((collection.id, from))
303 .checked_sub(1)303 .checked_sub(1)
304 // Should not occur304 // Should not occur
305 .ok_or(ArithmeticError::Underflow)?,305 .ok_or(ArithmeticError::Underflow)?,
310 // Account data is created in token, AccountBalance should be increased310 // Account data is created in token, AccountBalance should be increased
311 // But only if from != to as we shouldn't check overflow in this case311 // But only if from != to as we shouldn't check overflow in this case
312 let account_balance_to = if create_target && from_to_differ {312 let account_balance_to = if create_target && from_to_differ {
313 let account_balance_to = <AccountBalance<T>>::get((collection.id, to.as_sub()))313 let account_balance_to = <AccountBalance<T>>::get((collection.id, to))
314 .checked_add(1)314 .checked_add(1)
315 .ok_or(ArithmeticError::Overflow)?;315 .ok_or(ArithmeticError::Overflow)?;
316 ensure!(316 ensure!(
328 if let Some(balance_to) = balance_to {328 if let Some(balance_to) = balance_to {
329 // from != to329 // from != to
330 if balance_from == 0 {330 if balance_from == 0 {
331 <Balance<T>>::remove((collection.id, token, from.as_sub()));331 <Balance<T>>::remove((collection.id, token, from));
332 } else {332 } else {
333 <Balance<T>>::insert((collection.id, token, from.as_sub()), balance_from);333 <Balance<T>>::insert((collection.id, token, from), balance_from);
334 }334 }
335 <Balance<T>>::insert((collection.id, token, to.as_sub()), balance_to);335 <Balance<T>>::insert((collection.id, token, to), balance_to);
336 if let Some(account_balance_from) = account_balance_from {336 if let Some(account_balance_from) = account_balance_from {
337 <AccountBalance<T>>::insert((collection.id, from.as_sub()), account_balance_from);337 <AccountBalance<T>>::insert((collection.id, from), account_balance_from);
338 <Owned<T>>::remove((collection.id, from.as_sub(), token));338 <Owned<T>>::remove((collection.id, from, token));
339 }339 }
340 if let Some(account_balance_to) = account_balance_to {340 if let Some(account_balance_to) = account_balance_to {
341 <AccountBalance<T>>::insert((collection.id, to.as_sub()), account_balance_to);341 <AccountBalance<T>>::insert((collection.id, to), account_balance_to);
342 <Owned<T>>::insert((collection.id, to.as_sub(), token), true);342 <Owned<T>>::insert((collection.id, to, token), true);
343 }343 }
344 }344 }
345345
412 for data in &data {412 for data in &data {
413 for (owner, _) in &data.users {413 for (owner, _) in &data.users {
414 let balance = balances414 let balance = balances
415 .entry(owner.as_sub())415 .entry(owner)
416 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner.as_sub())));416 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));
417 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;417 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;
418418
419 ensure!(419 ensure!(
444 if amount == 0 {444 if amount == 0 {
445 continue;445 continue;
446 }446 }
447 <Balance<T>>::insert((collection.id, token_id, user.as_sub()), amount);447 <Balance<T>>::insert((collection.id, token_id, &user), amount);
448 <Owned<T>>::insert((collection.id, user.as_sub(), TokenId(token_id)), true);448 <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);
449 // TODO: ERC20 transfer event449 // TODO: ERC20 transfer event
450 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(450 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
451 collection.id,451 collection.id,
465 token: TokenId,465 token: TokenId,
466 amount: u128,466 amount: u128,
467 ) {467 ) {
468 <Allowance<T>>::insert((collection.id, token, sender.as_sub(), spender), amount);468 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);
469 // TODO: ERC20 approval event469 // TODO: ERC20 approval event
470 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(470 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(
471 collection.id,471 collection.id,
490490
491 <PalletCommon<T>>::ensure_correct_receiver(spender)?;491 <PalletCommon<T>>::ensure_correct_receiver(spender)?;
492492
493 if <Balance<T>>::get((collection.id, token, sender.as_sub())) < amount {493 if <Balance<T>>::get((collection.id, token, sender)) < amount {
494 ensure!(494 ensure!(
495 collection.ignores_owned_amount(sender)? && Self::token_exists(collection, token),495 collection.ignores_owned_amount(sender)? && Self::token_exists(collection, token),
496 <CommonError<T>>::CantApproveMoreThanOwned496 <CommonError<T>>::CantApproveMoreThanOwned
511 token: TokenId,511 token: TokenId,
512 amount: u128,512 amount: u128,
513 ) -> DispatchResult {513 ) -> DispatchResult {
514 if spender == from {514 if spender.conv_eq(from) {
515 return Self::transfer(collection, from, to, token, amount);515 return Self::transfer(collection, from, to, token, amount);
516 }516 }
517 if collection.access == AccessMode::WhiteList {517 if collection.access == AccessMode::WhiteList {
518 // `from`, `to` checked in [`transfer`]518 // `from`, `to` checked in [`transfer`]
519 collection.check_allowlist(spender)?;519 collection.check_allowlist(spender)?;
520 }520 }
521521
522 let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))522 let allowance =
523 .checked_sub(amount);523 <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);
524 if allowance.is_none() {524 if allowance.is_none() {
525 ensure!(525 ensure!(
544 token: TokenId,544 token: TokenId,
545 amount: u128,545 amount: u128,
546 ) -> DispatchResult {546 ) -> DispatchResult {
547 if spender == from {547 if spender.conv_eq(from) {
548 return Self::burn(collection, from, token, amount);548 return Self::burn(collection, from, token, amount);
549 }549 }
550 if collection.access == AccessMode::WhiteList {550 if collection.access == AccessMode::WhiteList {
551 // `from` checked in [`burn`]551 // `from` checked in [`burn`]
552 collection.check_allowlist(spender)?;552 collection.check_allowlist(spender)?;
553 }553 }
554554
555 let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))555 let allowance =
556 .checked_sub(amount);556 <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);
557 if allowance.is_none() {557 if allowance.is_none() {
558 ensure!(558 ensure!(
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -30,8 +30,8 @@
 		/// Used for ethereum integration
 		fn eth_contract_code(account: H160) -> Option<Vec<u8>>;
 
-		fn adminlist(collection: CollectionId) -> Vec<AccountId>;
-		fn allowlist(collection: CollectionId) -> Vec<AccountId>;
+		fn adminlist(collection: CollectionId) -> Vec<CrossAccountId>;
+		fn allowlist(collection: CollectionId) -> Vec<CrossAccountId>;
 		fn last_token_id(collection: CollectionId) -> TokenId;
 	}
 }
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -1033,12 +1033,14 @@
 		}
 
 		fn eth_contract_code(account: H160) -> Option<Vec<u8>> {
-			<pallet_nft::NftErcSupport<Runtime>>::get_code(&account).or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account)).or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
+			<pallet_nft::NftErcSupport<Runtime>>::get_code(&account)
+				.or_else(|| <pallet_evm_migration::OnMethodCall<Runtime>>::get_code(&account))
+				.or_else(|| <pallet_evm_contract_helpers::HelpersOnMethodCall<Self>>::get_code(&account))
 		}
-		fn adminlist(collection: CollectionId) -> Vec<AccountId> {
+		fn adminlist(collection: CollectionId) -> Vec<CrossAccountId> {
 			<pallet_nft::Pallet<Runtime>>::adminlist(collection)
 		}
-		fn allowlist(collection: CollectionId) -> Vec<AccountId> {
+		fn allowlist(collection: CollectionId) -> Vec<CrossAccountId> {
 			<pallet_nft::Pallet<Runtime>>::allowlist(collection)
 		}
 		fn last_token_id(collection: CollectionId) -> TokenId {