difftreelog
refactor return CrossAccountId in backing storages
in: master
14 files changed
client/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);
}
pallets/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 {
pallets/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,
pallets/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))
}
}
pallets/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())
}
}
pallets/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)?,
pallets/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()
pallets/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 {
pallets/nonfungible/src/erc.rsdiffbeforeafterboth1use core::{2 char::{REPLACEMENT_CHARACTER, decode_utf16},3 convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};12use pallet_evm_coder_substrate::call_internal;13use pallet_common::erc::PrecompileOutput;1415use crate::{16 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,17};1819#[derive(ToLog)]20pub enum ERC721Events {21 Transfer {22 #[indexed]23 from: address,24 #[indexed]25 to: address,26 #[indexed]27 token_id: uint256,28 },29 Approval {30 #[indexed]31 owner: address,32 #[indexed]33 approved: address,34 #[indexed]35 token_id: uint256,36 },37 #[allow(dead_code)]38 ApprovalForAll {39 #[indexed]40 owner: address,41 #[indexed]42 operator: address,43 approved: bool,44 },45}4647#[derive(ToLog)]48pub enum ERC721MintableEvents {49 #[allow(dead_code)]50 MintingFinished {},51}5253#[solidity_interface(name = "ERC721Metadata")]54impl<T: Config> NonfungibleHandle<T> {55 fn name(&self) -> Result<string> {56 Ok(decode_utf16(self.name.iter().copied())57 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))58 .collect::<string>())59 }60 fn symbol(&self) -> Result<string> {61 Ok(string::from_utf8_lossy(&self.token_prefix).into())62 }6364 #[solidity(rename_selector = "tokenURI")]65 fn token_uri(&self, token_id: uint256) -> Result<string> {66 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;67 Ok(string::from_utf8_lossy(68 &<TokenData<T>>::get((self.id, token_id))69 .ok_or("token not found")?70 .const_data,71 )72 .into())73 }74}7576#[solidity_interface(name = "ERC721Enumerable")]77impl<T: Config> NonfungibleHandle<T> {78 fn token_by_index(&self, index: uint256) -> Result<uint256> {79 Ok(index)80 }8182 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {83 // TODO: Not implemetable84 Err("not implemented".into())85 }8687 fn total_supply(&self) -> Result<uint256> {88 Ok(<Pallet<T>>::total_supply(self).into())89 }90}9192#[solidity_interface(name = "ERC721", events(ERC721Events))]93impl<T: Config> NonfungibleHandle<T> {94 fn balance_of(&self, owner: address) -> Result<uint256> {95 let owner = T::CrossAccountId::from_eth(owner);96 let balance = <AccountBalance<T>>::get((self.id, owner.as_sub()));97 Ok(balance.into())98 }99 fn owner_of(&self, token_id: uint256) -> Result<address> {100 let token: TokenId = token_id.try_into()?;101 Ok(*<TokenData<T>>::get((self.id, token))102 .ok_or("token not found")?103 .owner104 .as_eth())105 }106 fn safe_transfer_from_with_data(107 &mut self,108 _from: address,109 _to: address,110 _token_id: uint256,111 _data: bytes,112 _value: value,113 ) -> Result<void> {114 // TODO: Not implemetable115 Err("not implemented".into())116 }117 fn safe_transfer_from(118 &mut self,119 _from: address,120 _to: address,121 _token_id: uint256,122 _value: value,123 ) -> Result<void> {124 // TODO: Not implemetable125 Err("not implemented".into())126 }127128 fn transfer_from(129 &mut self,130 caller: caller,131 from: address,132 to: address,133 token_id: uint256,134 _value: value,135 ) -> Result<void> {136 let caller = T::CrossAccountId::from_eth(caller);137 let from = T::CrossAccountId::from_eth(from);138 let to = T::CrossAccountId::from_eth(to);139 let token = token_id.try_into()?;140141 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token)142 .map_err(dispatch_to_evm::<T>)?;143 Ok(())144 }145146 fn approve(147 &mut self,148 caller: caller,149 approved: address,150 token_id: uint256,151 _value: value,152 ) -> Result<void> {153 let caller = T::CrossAccountId::from_eth(caller);154 let approved = T::CrossAccountId::from_eth(approved);155 let token = token_id.try_into()?;156157 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))158 .map_err(dispatch_to_evm::<T>)?;159 Ok(())160 }161162 fn set_approval_for_all(163 &mut self,164 _caller: caller,165 _operator: address,166 _approved: bool,167 ) -> Result<void> {168 // TODO: Not implemetable169 Err("not implemented".into())170 }171172 fn get_approved(&self, _token_id: uint256) -> Result<address> {173 // TODO: Not implemetable174 Err("not implemented".into())175 }176177 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {178 // TODO: Not implemetable179 Err("not implemented".into())180 }181}182183#[solidity_interface(name = "ERC721Burnable")]184impl<T: Config> NonfungibleHandle<T> {185 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {186 let caller = T::CrossAccountId::from_eth(caller);187 let token = token_id.try_into()?;188189 <Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;190 Ok(())191 }192}193194#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]195impl<T: Config> NonfungibleHandle<T> {196 fn minting_finished(&self) -> Result<bool> {197 Ok(false)198 }199200 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {201 let caller = T::CrossAccountId::from_eth(caller);202 let to = T::CrossAccountId::from_eth(to);203 let token_id: u32 = token_id.try_into()?;204 if <TokensMinted<T>>::get(self.id)205 .checked_add(1)206 .ok_or("item id overflow")?207 != token_id208 {209 return Err("item id should be next".into());210 }211212 <Pallet<T>>::create_item(213 self,214 &caller,215 CreateItemData {216 const_data: BoundedVec::default(),217 variable_data: BoundedVec::default(),218 owner: to,219 },220 )221 .map_err(dispatch_to_evm::<T>)?;222223 Ok(true)224 }225226 #[solidity(rename_selector = "mintWithTokenURI")]227 fn mint_with_token_uri(228 &mut self,229 caller: caller,230 to: address,231 token_id: uint256,232 token_uri: string,233 ) -> Result<bool> {234 let caller = T::CrossAccountId::from_eth(caller);235 let to = T::CrossAccountId::from_eth(to);236 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;237 if <TokensMinted<T>>::get(self.id)238 .checked_add(1)239 .ok_or("item id overflow")?240 != token_id241 {242 return Err("item id should be next".into());243 }244245 <Pallet<T>>::create_item(246 self,247 &caller,248 CreateItemData {249 const_data: Vec::<u8>::from(token_uri)250 .try_into()251 .map_err(|_| "token uri is too long")?,252 variable_data: BoundedVec::default(),253 owner: to,254 },255 )256 .map_err(dispatch_to_evm::<T>)?;257 Ok(true)258 }259260 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {261 Err("not implementable".into())262 }263}264265#[solidity_interface(name = "ERC721UniqueExtensions")]266impl<T: Config> NonfungibleHandle<T> {267 fn transfer(268 &mut self,269 caller: caller,270 to: address,271 token_id: uint256,272 _value: value,273 ) -> Result<void> {274 let caller = T::CrossAccountId::from_eth(caller);275 let to = T::CrossAccountId::from_eth(to);276 let token = token_id.try_into()?;277278 <Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;279 Ok(())280 }281282 fn burn_from(283 &mut self,284 caller: caller,285 from: address,286 token_id: uint256,287 _value: value,288 ) -> Result<void> {289 let caller = T::CrossAccountId::from_eth(caller);290 let from = T::CrossAccountId::from_eth(from);291 let token = token_id.try_into()?;292293 <Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;294 Ok(())295 }296297 fn next_token_id(&self) -> Result<uint256> {298 Ok(<TokensMinted<T>>::get(self.id)299 .checked_add(1)300 .ok_or("item id overflow")?301 .into())302 }303304 fn set_variable_metadata(305 &mut self,306 caller: caller,307 token_id: uint256,308 data: bytes,309 ) -> Result<void> {310 let caller = T::CrossAccountId::from_eth(caller);311 let token = token_id.try_into()?;312313 <Pallet<T>>::set_variable_metadata(self, &caller, token, data)314 .map_err(dispatch_to_evm::<T>)?;315 Ok(())316 }317318 fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {319 let token: TokenId = token_id.try_into()?;320321 Ok(<TokenData<T>>::get((self.id, token))322 .ok_or("token not found")?323 .variable_data)324 }325326 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {327 let caller = T::CrossAccountId::from_eth(caller);328 let to = T::CrossAccountId::from_eth(to);329 let mut expected_index = <TokensMinted<T>>::get(self.id)330 .checked_add(1)331 .ok_or("item id overflow")?;332333 let total_tokens = token_ids.len();334 for id in token_ids.into_iter() {335 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;336 if id != expected_index {337 return Err("item id should be next".into());338 }339 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;340 }341 let data = (0..total_tokens)342 .map(|_| CreateItemData {343 const_data: BoundedVec::default(),344 variable_data: BoundedVec::default(),345 owner: to.clone(),346 })347 .collect();348349 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;350 Ok(true)351 }352353 #[solidity(rename_selector = "mintBulkWithTokenURI")]354 fn mint_bulk_with_token_uri(355 &mut self,356 caller: caller,357 to: address,358 tokens: Vec<(uint256, string)>,359 ) -> Result<bool> {360 let caller = T::CrossAccountId::from_eth(caller);361 let to = T::CrossAccountId::from_eth(to);362 let mut expected_index = <TokensMinted<T>>::get(self.id)363 .checked_add(1)364 .ok_or("item id overflow")?;365366 let mut data = Vec::with_capacity(tokens.len());367 for (id, token_uri) in tokens {368 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;369 if id != expected_index {370 panic!("item id should be next ({}) but got {}", expected_index, id);371 }372 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;373374 data.push(CreateItemData {375 const_data: Vec::<u8>::from(token_uri)376 .try_into()377 .map_err(|_| "token uri is too long")?,378 variable_data: vec![].try_into().unwrap(),379 owner: to.clone(),380 });381 }382383 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;384 Ok(true)385 }386}387388#[solidity_interface(389 name = "UniqueNFT",390 is(391 ERC721,392 ERC721Metadata,393 ERC721Enumerable,394 ERC721UniqueExtensions,395 ERC721Mintable,396 ERC721Burnable,397 )398)]399impl<T: Config> NonfungibleHandle<T> {}400401// Not a tests, but code generators402generate_stubgen!(gen_impl, UniqueNFTCall, true);403generate_stubgen!(gen_iface, UniqueNFTCall, false);404405pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");406407impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {408 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");409410 fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {411 let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);412 self.0.recorder.evm_to_precompile_output(result)413 }414}1use core::{2 char::{REPLACEMENT_CHARACTER, decode_utf16},3 convert::TryInto,4};5use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*};6use frame_support::BoundedVec;7use nft_data_structs::TokenId;8use pallet_evm_coder_substrate::dispatch_to_evm;9use sp_core::{H160, U256};10use sp_std::{vec::Vec, vec};11use pallet_common::{account::CrossAccountId, erc::CommonEvmHandler};12use pallet_evm_coder_substrate::call_internal;13use pallet_common::erc::PrecompileOutput;1415use crate::{16 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,17};1819#[derive(ToLog)]20pub enum ERC721Events {21 Transfer {22 #[indexed]23 from: address,24 #[indexed]25 to: address,26 #[indexed]27 token_id: uint256,28 },29 Approval {30 #[indexed]31 owner: address,32 #[indexed]33 approved: address,34 #[indexed]35 token_id: uint256,36 },37 #[allow(dead_code)]38 ApprovalForAll {39 #[indexed]40 owner: address,41 #[indexed]42 operator: address,43 approved: bool,44 },45}4647#[derive(ToLog)]48pub enum ERC721MintableEvents {49 #[allow(dead_code)]50 MintingFinished {},51}5253#[solidity_interface(name = "ERC721Metadata")]54impl<T: Config> NonfungibleHandle<T> {55 fn name(&self) -> Result<string> {56 Ok(decode_utf16(self.name.iter().copied())57 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))58 .collect::<string>())59 }60 fn symbol(&self) -> Result<string> {61 Ok(string::from_utf8_lossy(&self.token_prefix).into())62 }6364 #[solidity(rename_selector = "tokenURI")]65 fn token_uri(&self, token_id: uint256) -> Result<string> {66 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;67 Ok(string::from_utf8_lossy(68 &<TokenData<T>>::get((self.id, token_id))69 .ok_or("token not found")?70 .const_data,71 )72 .into())73 }74}7576#[solidity_interface(name = "ERC721Enumerable")]77impl<T: Config> NonfungibleHandle<T> {78 fn token_by_index(&self, index: uint256) -> Result<uint256> {79 Ok(index)80 }8182 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {83 // TODO: Not implemetable84 Err("not implemented".into())85 }8687 fn total_supply(&self) -> Result<uint256> {88 Ok(<Pallet<T>>::total_supply(self).into())89 }90}9192#[solidity_interface(name = "ERC721", events(ERC721Events))]93impl<T: Config> NonfungibleHandle<T> {94 fn balance_of(&self, owner: address) -> Result<uint256> {95 let owner = T::CrossAccountId::from_eth(owner);96 let balance = <AccountBalance<T>>::get((self.id, owner));97 Ok(balance.into())98 }99 fn owner_of(&self, token_id: uint256) -> Result<address> {100 let token: TokenId = token_id.try_into()?;101 Ok(*<TokenData<T>>::get((self.id, token))102 .ok_or("token not found")?103 .owner104 .as_eth())105 }106 fn safe_transfer_from_with_data(107 &mut self,108 _from: address,109 _to: address,110 _token_id: uint256,111 _data: bytes,112 _value: value,113 ) -> Result<void> {114 // TODO: Not implemetable115 Err("not implemented".into())116 }117 fn safe_transfer_from(118 &mut self,119 _from: address,120 _to: address,121 _token_id: uint256,122 _value: value,123 ) -> Result<void> {124 // TODO: Not implemetable125 Err("not implemented".into())126 }127128 fn transfer_from(129 &mut self,130 caller: caller,131 from: address,132 to: address,133 token_id: uint256,134 _value: value,135 ) -> Result<void> {136 let caller = T::CrossAccountId::from_eth(caller);137 let from = T::CrossAccountId::from_eth(from);138 let to = T::CrossAccountId::from_eth(to);139 let token = token_id.try_into()?;140141 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token)142 .map_err(dispatch_to_evm::<T>)?;143 Ok(())144 }145146 fn approve(147 &mut self,148 caller: caller,149 approved: address,150 token_id: uint256,151 _value: value,152 ) -> Result<void> {153 let caller = T::CrossAccountId::from_eth(caller);154 let approved = T::CrossAccountId::from_eth(approved);155 let token = token_id.try_into()?;156157 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))158 .map_err(dispatch_to_evm::<T>)?;159 Ok(())160 }161162 fn set_approval_for_all(163 &mut self,164 _caller: caller,165 _operator: address,166 _approved: bool,167 ) -> Result<void> {168 // TODO: Not implemetable169 Err("not implemented".into())170 }171172 fn get_approved(&self, _token_id: uint256) -> Result<address> {173 // TODO: Not implemetable174 Err("not implemented".into())175 }176177 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {178 // TODO: Not implemetable179 Err("not implemented".into())180 }181}182183#[solidity_interface(name = "ERC721Burnable")]184impl<T: Config> NonfungibleHandle<T> {185 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {186 let caller = T::CrossAccountId::from_eth(caller);187 let token = token_id.try_into()?;188189 <Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;190 Ok(())191 }192}193194#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]195impl<T: Config> NonfungibleHandle<T> {196 fn minting_finished(&self) -> Result<bool> {197 Ok(false)198 }199200 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {201 let caller = T::CrossAccountId::from_eth(caller);202 let to = T::CrossAccountId::from_eth(to);203 let token_id: u32 = token_id.try_into()?;204 if <TokensMinted<T>>::get(self.id)205 .checked_add(1)206 .ok_or("item id overflow")?207 != token_id208 {209 return Err("item id should be next".into());210 }211212 <Pallet<T>>::create_item(213 self,214 &caller,215 CreateItemData {216 const_data: BoundedVec::default(),217 variable_data: BoundedVec::default(),218 owner: to,219 },220 )221 .map_err(dispatch_to_evm::<T>)?;222223 Ok(true)224 }225226 #[solidity(rename_selector = "mintWithTokenURI")]227 fn mint_with_token_uri(228 &mut self,229 caller: caller,230 to: address,231 token_id: uint256,232 token_uri: string,233 ) -> Result<bool> {234 let caller = T::CrossAccountId::from_eth(caller);235 let to = T::CrossAccountId::from_eth(to);236 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;237 if <TokensMinted<T>>::get(self.id)238 .checked_add(1)239 .ok_or("item id overflow")?240 != token_id241 {242 return Err("item id should be next".into());243 }244245 <Pallet<T>>::create_item(246 self,247 &caller,248 CreateItemData {249 const_data: Vec::<u8>::from(token_uri)250 .try_into()251 .map_err(|_| "token uri is too long")?,252 variable_data: BoundedVec::default(),253 owner: to,254 },255 )256 .map_err(dispatch_to_evm::<T>)?;257 Ok(true)258 }259260 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {261 Err("not implementable".into())262 }263}264265#[solidity_interface(name = "ERC721UniqueExtensions")]266impl<T: Config> NonfungibleHandle<T> {267 fn transfer(268 &mut self,269 caller: caller,270 to: address,271 token_id: uint256,272 _value: value,273 ) -> Result<void> {274 let caller = T::CrossAccountId::from_eth(caller);275 let to = T::CrossAccountId::from_eth(to);276 let token = token_id.try_into()?;277278 <Pallet<T>>::transfer(self, &caller, &to, token).map_err(dispatch_to_evm::<T>)?;279 Ok(())280 }281282 fn burn_from(283 &mut self,284 caller: caller,285 from: address,286 token_id: uint256,287 _value: value,288 ) -> Result<void> {289 let caller = T::CrossAccountId::from_eth(caller);290 let from = T::CrossAccountId::from_eth(from);291 let token = token_id.try_into()?;292293 <Pallet<T>>::burn_from(self, &caller, &from, token).map_err(dispatch_to_evm::<T>)?;294 Ok(())295 }296297 fn next_token_id(&self) -> Result<uint256> {298 Ok(<TokensMinted<T>>::get(self.id)299 .checked_add(1)300 .ok_or("item id overflow")?301 .into())302 }303304 fn set_variable_metadata(305 &mut self,306 caller: caller,307 token_id: uint256,308 data: bytes,309 ) -> Result<void> {310 let caller = T::CrossAccountId::from_eth(caller);311 let token = token_id.try_into()?;312313 <Pallet<T>>::set_variable_metadata(self, &caller, token, data)314 .map_err(dispatch_to_evm::<T>)?;315 Ok(())316 }317318 fn get_variable_metadata(&self, token_id: uint256) -> Result<bytes> {319 let token: TokenId = token_id.try_into()?;320321 Ok(<TokenData<T>>::get((self.id, token))322 .ok_or("token not found")?323 .variable_data)324 }325326 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {327 let caller = T::CrossAccountId::from_eth(caller);328 let to = T::CrossAccountId::from_eth(to);329 let mut expected_index = <TokensMinted<T>>::get(self.id)330 .checked_add(1)331 .ok_or("item id overflow")?;332333 let total_tokens = token_ids.len();334 for id in token_ids.into_iter() {335 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;336 if id != expected_index {337 return Err("item id should be next".into());338 }339 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;340 }341 let data = (0..total_tokens)342 .map(|_| CreateItemData {343 const_data: BoundedVec::default(),344 variable_data: BoundedVec::default(),345 owner: to.clone(),346 })347 .collect();348349 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;350 Ok(true)351 }352353 #[solidity(rename_selector = "mintBulkWithTokenURI")]354 fn mint_bulk_with_token_uri(355 &mut self,356 caller: caller,357 to: address,358 tokens: Vec<(uint256, string)>,359 ) -> Result<bool> {360 let caller = T::CrossAccountId::from_eth(caller);361 let to = T::CrossAccountId::from_eth(to);362 let mut expected_index = <TokensMinted<T>>::get(self.id)363 .checked_add(1)364 .ok_or("item id overflow")?;365366 let mut data = Vec::with_capacity(tokens.len());367 for (id, token_uri) in tokens {368 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;369 if id != expected_index {370 panic!("item id should be next ({}) but got {}", expected_index, id);371 }372 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;373374 data.push(CreateItemData {375 const_data: Vec::<u8>::from(token_uri)376 .try_into()377 .map_err(|_| "token uri is too long")?,378 variable_data: vec![].try_into().unwrap(),379 owner: to.clone(),380 });381 }382383 <Pallet<T>>::create_multiple_items(self, &caller, data).map_err(dispatch_to_evm::<T>)?;384 Ok(true)385 }386}387388#[solidity_interface(389 name = "UniqueNFT",390 is(391 ERC721,392 ERC721Metadata,393 ERC721Enumerable,394 ERC721UniqueExtensions,395 ERC721Mintable,396 ERC721Burnable,397 )398)]399impl<T: Config> NonfungibleHandle<T> {}400401// Not a tests, but code generators402generate_stubgen!(gen_impl, UniqueNFTCall, true);403generate_stubgen!(gen_iface, UniqueNFTCall, false);404405pub const CODE: &[u8] = include_bytes!("./stubs/UniqueNFT.raw");406407impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {408 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");409410 fn call(mut self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileOutput> {411 let result = call_internal::<UniqueNFTCall, _>(*source, &mut self, value, input);412 self.0.recorder.evm_to_precompile_output(result)413 }414}pallets/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 {
pallets/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))
}
}
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -83,7 +83,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,
@@ -95,7 +95,7 @@
Key = (
Key<Twox64Concat, CollectionId>,
// Owner
- Key<Blake2_128Concat, T::AccountId>,
+ Key<Blake2_128Concat, T::CrossAccountId>,
),
Value = u32,
QueryKind = ValueQuery,
@@ -107,7 +107,7 @@
Key<Twox64Concat, CollectionId>,
Key<Twox64Concat, TokenId>,
// Owner
- Key<Blake2_128Concat, T::AccountId>,
+ Key<Blake2_128Concat, T::CrossAccountId>,
),
Value = u128,
QueryKind = ValueQuery,
@@ -119,7 +119,7 @@
Key<Twox64Concat, CollectionId>,
Key<Twox64Concat, TokenId>,
// Owner
- Key<Blake2_128, T::AccountId>,
+ Key<Blake2_128, T::CrossAccountId>,
// Spender
Key<Blake2_128Concat, T::CrossAccountId>,
),
@@ -206,18 +206,18 @@
if total_supply == 0 {
// Ensure user actually owns this amount
ensure!(
- <Balance<T>>::get((collection.id, token, owner.as_sub())) == amount,
+ <Balance<T>>::get((collection.id, token, owner)) == amount,
<CommonError<T>>::TokenValueTooLow
);
- let account_balance = <AccountBalance<T>>::get((collection.id, owner.as_sub()))
+ let account_balance = <AccountBalance<T>>::get((collection.id, owner))
.checked_sub(1)
// Should not occur
.ok_or(ArithmeticError::Underflow)?;
// =========
- <Owned<T>>::remove((collection.id, owner.as_sub(), token));
- <AccountBalance<T>>::insert((collection.id, owner.as_sub()), account_balance);
+ <Owned<T>>::remove((collection.id, owner, token));
+ <AccountBalance<T>>::insert((collection.id, owner), account_balance);
Self::burn_token(collection, token)?;
<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
collection.id,
@@ -228,11 +228,11 @@
return Ok(());
}
- let balance = <Balance<T>>::get((collection.id, token, owner.as_sub()))
+ let balance = <Balance<T>>::get((collection.id, token, owner))
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
let account_balance = if balance == 0 {
- <AccountBalance<T>>::get((collection.id, owner.as_sub()))
+ <AccountBalance<T>>::get((collection.id, owner))
.checked_sub(1)
// Should not occur
.ok_or(ArithmeticError::Underflow)?
@@ -243,11 +243,11 @@
// =========
if balance == 0 {
- <Owned<T>>::remove((collection.id, owner.as_sub(), token));
- <Balance<T>>::remove((collection.id, token, owner.as_sub()));
- <AccountBalance<T>>::insert((collection.id, owner.as_sub()), account_balance);
+ <Owned<T>>::remove((collection.id, owner, token));
+ <Balance<T>>::remove((collection.id, token, owner));
+ <AccountBalance<T>>::insert((collection.id, owner), account_balance);
} else {
- <Balance<T>>::insert((collection.id, token, owner.as_sub()), balance);
+ <Balance<T>>::insert((collection.id, token, owner), balance);
}
<TotalSupply<T>>::insert((collection.id, token), total_supply);
// TODO: ERC20 transfer event
@@ -278,13 +278,13 @@
}
<PalletCommon<T>>::ensure_correct_receiver(to)?;
- let balance_from = <Balance<T>>::get((collection.id, token, from.as_sub()))
+ let balance_from = <Balance<T>>::get((collection.id, token, from))
.checked_sub(amount)
.ok_or(<CommonError<T>>::TokenValueTooLow)?;
let mut create_target = false;
let from_to_differ = from != to;
let balance_to = if from != to {
- let old_balance = <Balance<T>>::get((collection.id, token, to.as_sub()));
+ let old_balance = <Balance<T>>::get((collection.id, token, to));
if old_balance == 0 {
create_target = true;
}
@@ -299,7 +299,7 @@
let account_balance_from = if balance_from == 0 {
Some(
- <AccountBalance<T>>::get((collection.id, from.as_sub()))
+ <AccountBalance<T>>::get((collection.id, from))
.checked_sub(1)
// Should not occur
.ok_or(ArithmeticError::Underflow)?,
@@ -310,7 +310,7 @@
// Account data is created in token, AccountBalance should be increased
// But only if from != to as we shouldn't check overflow in this case
let account_balance_to = if create_target && from_to_differ {
- let account_balance_to = <AccountBalance<T>>::get((collection.id, to.as_sub()))
+ let account_balance_to = <AccountBalance<T>>::get((collection.id, to))
.checked_add(1)
.ok_or(ArithmeticError::Overflow)?;
ensure!(
@@ -328,18 +328,18 @@
if let Some(balance_to) = balance_to {
// from != to
if balance_from == 0 {
- <Balance<T>>::remove((collection.id, token, from.as_sub()));
+ <Balance<T>>::remove((collection.id, token, from));
} else {
- <Balance<T>>::insert((collection.id, token, from.as_sub()), balance_from);
+ <Balance<T>>::insert((collection.id, token, from), balance_from);
}
- <Balance<T>>::insert((collection.id, token, to.as_sub()), balance_to);
+ <Balance<T>>::insert((collection.id, token, to), balance_to);
if let Some(account_balance_from) = account_balance_from {
- <AccountBalance<T>>::insert((collection.id, from.as_sub()), account_balance_from);
- <Owned<T>>::remove((collection.id, from.as_sub(), token));
+ <AccountBalance<T>>::insert((collection.id, from), account_balance_from);
+ <Owned<T>>::remove((collection.id, from, token));
}
if let Some(account_balance_to) = account_balance_to {
- <AccountBalance<T>>::insert((collection.id, to.as_sub()), account_balance_to);
- <Owned<T>>::insert((collection.id, to.as_sub(), token), true);
+ <AccountBalance<T>>::insert((collection.id, to), account_balance_to);
+ <Owned<T>>::insert((collection.id, to, token), true);
}
}
@@ -412,8 +412,8 @@
for data in &data {
for (owner, _) in &data.users {
let balance = balances
- .entry(owner.as_sub())
- .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner.as_sub())));
+ .entry(owner)
+ .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));
*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;
ensure!(
@@ -444,8 +444,8 @@
if amount == 0 {
continue;
}
- <Balance<T>>::insert((collection.id, token_id, user.as_sub()), amount);
- <Owned<T>>::insert((collection.id, user.as_sub(), TokenId(token_id)), true);
+ <Balance<T>>::insert((collection.id, token_id, &user), amount);
+ <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);
// TODO: ERC20 transfer event
<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
collection.id,
@@ -465,7 +465,7 @@
token: TokenId,
amount: u128,
) {
- <Allowance<T>>::insert((collection.id, token, sender.as_sub(), spender), amount);
+ <Allowance<T>>::insert((collection.id, token, sender, spender), amount);
// TODO: ERC20 approval event
<PalletCommon<T>>::deposit_event(CommonEvent::Approved(
collection.id,
@@ -490,7 +490,7 @@
<PalletCommon<T>>::ensure_correct_receiver(spender)?;
- if <Balance<T>>::get((collection.id, token, sender.as_sub())) < amount {
+ if <Balance<T>>::get((collection.id, token, sender)) < amount {
ensure!(
collection.ignores_owned_amount(sender)? && Self::token_exists(collection, token),
<CommonError<T>>::CantApproveMoreThanOwned
@@ -511,7 +511,7 @@
token: TokenId,
amount: u128,
) -> DispatchResult {
- if spender == from {
+ if spender.conv_eq(from) {
return Self::transfer(collection, from, to, token, amount);
}
if collection.access == AccessMode::WhiteList {
@@ -519,8 +519,8 @@
collection.check_allowlist(spender)?;
}
- let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))
- .checked_sub(amount);
+ let allowance =
+ <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);
if allowance.is_none() {
ensure!(
collection.ignores_allowance(spender)?,
@@ -544,7 +544,7 @@
token: TokenId,
amount: u128,
) -> DispatchResult {
- if spender == from {
+ if spender.conv_eq(from) {
return Self::burn(collection, from, token, amount);
}
if collection.access == AccessMode::WhiteList {
@@ -552,8 +552,8 @@
collection.check_allowlist(spender)?;
}
- let allowance = <Allowance<T>>::get((collection.id, token, from.as_sub(), &spender))
- .checked_sub(amount);
+ let allowance =
+ <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);
if allowance.is_none() {
ensure!(
collection.ignores_allowance(spender)?,
primitives/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;
}
}
runtime/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 {