difftreelog
feat Using EthCrossAccount in appropriate functions
in: master
11 files changed
crates/evm-coder/src/abi.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -450,7 +450,7 @@
}
}
-impl AbiWrite for &EthCrossAccount {
+impl AbiWrite for EthCrossAccount {
fn abi_write(&self, writer: &mut AbiWriter) {
self.eth.abi_write(writer);
self.sub.abi_write(writer);
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -218,7 +218,7 @@
}
}
- #[derive(Debug)]
+ #[derive(Debug, Default)]
pub struct EthCrossAccount {
pub(crate) eth: address,
pub(crate) sub: uint256,
crates/evm-coder/src/solidity.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -203,7 +203,7 @@
}
fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {
- write!(writer, "{}(", tc.collect_tuple::<Self>())?;
+ write!(writer, "{}(", tc.collect_struct::<Self>())?;
address::solidity_default(writer, tc)?;
write!(writer, ",")?;
uint256::solidity_default(writer, tc)?;
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -231,13 +231,13 @@
fn set_collection_sponsor_cross(
&mut self,
caller: caller,
- sponsor: (address, uint256),
+ sponsor: EthCrossAccount,
) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
check_is_owner_or_admin(caller, self)?;
- let sponsor = convert_tuple_to_cross_account::<T>(sponsor)?;
+ let sponsor = sponsor.into_sub_cross_account::<T>()?;
self.set_sponsor(sponsor.as_sub().clone())
.map_err(dispatch_to_evm::<T>)?;
save(self)
@@ -388,12 +388,12 @@
fn add_collection_admin_cross(
&mut self,
caller: caller,
- new_admin: (address, uint256),
+ new_admin: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(2)?;
let caller = T::CrossAccountId::from_eth(caller);
- let new_admin = convert_tuple_to_cross_account::<T>(new_admin)?;
+ let new_admin = new_admin.into_sub_cross_account::<T>()?;
<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -403,12 +403,12 @@
fn remove_collection_admin_cross(
&mut self,
caller: caller,
- admin: (address, uint256),
+ admin: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(2)?;
let caller = T::CrossAccountId::from_eth(caller);
- let admin = convert_tuple_to_cross_account::<T>(admin)?;
+ let admin = admin.into_sub_cross_account::<T>()?;
<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -566,12 +566,12 @@
fn add_to_collection_allow_list_cross(
&mut self,
caller: caller,
- user: (address, uint256),
+ user: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- let user = convert_tuple_to_cross_account::<T>(user)?;
+ let user = user.into_sub_cross_account::<T>()?;
Pallet::<T>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -594,12 +594,12 @@
fn remove_from_collection_allow_list_cross(
&mut self,
caller: caller,
- user: (address, uint256),
+ user: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- let user = convert_tuple_to_cross_account::<T>(user)?;
+ let user = user.into_sub_cross_account::<T>()?;
Pallet::<T>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -639,8 +639,8 @@
///
/// @param user User cross account to verify
/// @return "true" if account is the owner or admin
- fn is_owner_or_admin_cross(&self, user: (address, uint256)) -> Result<bool> {
- let user = convert_tuple_to_cross_account::<T>(user)?;
+ fn is_owner_or_admin_cross(&self, user: EthCrossAccount) -> Result<bool> {
+ let user = user.into_sub_cross_account::<T>()?;
Ok(self.is_owner_or_admin(&user))
}
@@ -660,8 +660,8 @@
///
/// @return Tuble with sponsor address and his substrate mirror.
/// If address is canonical then substrate mirror is zero and vice versa.
- fn collection_owner(&self) -> Result<(address, uint256)> {
- Ok(convert_cross_account_to_tuple::<T>(
+ fn collection_owner(&self) -> Result<EthCrossAccount> {
+ Ok(EthCrossAccount::from_sub_cross_account::<T>(
&T::CrossAccountId::from_sub(self.owner.clone()),
))
}
@@ -684,9 +684,9 @@
///
/// @return Vector of tuples with admins address and his substrate mirror.
/// If address is canonical then substrate mirror is zero and vice versa.
- fn collection_admins(&self) -> Result<Vec<(address, uint256)>> {
+ fn collection_admins(&self) -> Result<Vec<EthCrossAccount>> {
let result = crate::IsAdmin::<T>::iter_prefix((self.id,))
- .map(|(admin, _)| crate::eth::convert_cross_account_to_tuple::<T>(&admin))
+ .map(|(admin, _)| EthCrossAccount::from_sub_cross_account::<T>(&admin))
.collect();
Ok(result)
}
@@ -695,11 +695,11 @@
///
/// @dev Owner can be changed only by current owner
/// @param newOwner new owner cross account
- fn set_owner_cross(&mut self, caller: caller, new_owner: (address, uint256)) -> Result<void> {
+ fn set_owner_cross(&mut self, caller: caller, new_owner: EthCrossAccount) -> Result<void> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- let new_owner = convert_tuple_to_cross_account::<T>(new_owner)?;
+ let new_owner = new_owner.into_sub_cross_account::<T>()?;
self.set_owner_internal(caller, new_owner)
.map_err(dispatch_to_evm::<T>)
}
pallets/fungible/src/erc.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! ERC-20 standart support implementation.1819extern crate alloc;20use core::char::{REPLACEMENT_CHARACTER, decode_utf16};21use core::convert::TryInto;22use evm_coder::{23 ToLog,24 execution::*,25 generate_stubgen, solidity_interface,26 types::*,27 weight,28 custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},29 make_signature,30};31use pallet_common::eth::convert_tuple_to_cross_account;32use up_data_structs::CollectionMode;33use pallet_common::erc::{CommonEvmHandler, PrecompileResult};34use sp_std::vec::Vec;35use pallet_evm::{account::CrossAccountId, PrecompileHandle};36use pallet_evm_coder_substrate::{call, dispatch_to_evm};37use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};38use pallet_common::{CollectionHandle, erc::CollectionCall};3940use crate::{41 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,42 weights::WeightInfo,43};4445#[derive(ToLog)]46pub enum ERC20Events {47 Transfer {48 #[indexed]49 from: address,50 #[indexed]51 to: address,52 value: uint256,53 },54 Approval {55 #[indexed]56 owner: address,57 #[indexed]58 spender: address,59 value: uint256,60 },61}6263#[solidity_interface(name = ERC20, events(ERC20Events))]64impl<T: Config> FungibleHandle<T> {65 fn name(&self) -> Result<string> {66 Ok(decode_utf16(self.name.iter().copied())67 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))68 .collect::<string>())69 }70 fn symbol(&self) -> Result<string> {71 Ok(string::from_utf8_lossy(&self.token_prefix).into())72 }73 fn total_supply(&self) -> Result<uint256> {74 self.consume_store_reads(1)?;75 Ok(<TotalSupply<T>>::get(self.id).into())76 }7778 fn decimals(&self) -> Result<uint8> {79 Ok(if let CollectionMode::Fungible(decimals) = &self.mode {80 *decimals81 } else {82 unreachable!()83 })84 }85 fn balance_of(&self, owner: address) -> Result<uint256> {86 self.consume_store_reads(1)?;87 let owner = T::CrossAccountId::from_eth(owner);88 let balance = <Balance<T>>::get((self.id, owner));89 Ok(balance.into())90 }91 #[weight(<SelfWeightOf<T>>::transfer())]92 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {93 let caller = T::CrossAccountId::from_eth(caller);94 let to = T::CrossAccountId::from_eth(to);95 let amount = amount.try_into().map_err(|_| "amount overflow")?;96 let budget = self97 .recorder98 .weight_calls_budget(<StructureWeight<T>>::find_parent());99100 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;101 Ok(true)102 }103 #[weight(<SelfWeightOf<T>>::transfer_from())]104 fn transfer_from(105 &mut self,106 caller: caller,107 from: address,108 to: address,109 amount: uint256,110 ) -> Result<bool> {111 let caller = T::CrossAccountId::from_eth(caller);112 let from = T::CrossAccountId::from_eth(from);113 let to = T::CrossAccountId::from_eth(to);114 let amount = amount.try_into().map_err(|_| "amount overflow")?;115 let budget = self116 .recorder117 .weight_calls_budget(<StructureWeight<T>>::find_parent());118119 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)120 .map_err(dispatch_to_evm::<T>)?;121 Ok(true)122 }123 #[weight(<SelfWeightOf<T>>::approve())]124 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {125 let caller = T::CrossAccountId::from_eth(caller);126 let spender = T::CrossAccountId::from_eth(spender);127 let amount = amount.try_into().map_err(|_| "amount overflow")?;128129 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)130 .map_err(dispatch_to_evm::<T>)?;131 Ok(true)132 }133 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {134 self.consume_store_reads(1)?;135 let owner = T::CrossAccountId::from_eth(owner);136 let spender = T::CrossAccountId::from_eth(spender);137138 Ok(<Allowance<T>>::get((self.id, owner, spender)).into())139 }140}141142#[solidity_interface(name = ERC20Mintable)]143impl<T: Config> FungibleHandle<T> {144 /// Mint tokens for `to` account.145 /// @param to account that will receive minted tokens146 /// @param amount amount of tokens to mint147 #[weight(<SelfWeightOf<T>>::create_item())]148 fn mint(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {149 let caller = T::CrossAccountId::from_eth(caller);150 let to = T::CrossAccountId::from_eth(to);151 let amount = amount.try_into().map_err(|_| "amount overflow")?;152 let budget = self153 .recorder154 .weight_calls_budget(<StructureWeight<T>>::find_parent());155 <Pallet<T>>::create_item(&self, &caller, (to, amount), &budget)156 .map_err(dispatch_to_evm::<T>)?;157 Ok(true)158 }159}160161#[solidity_interface(name = ERC20UniqueExtensions)]162impl<T: Config> FungibleHandle<T>163where164 T::AccountId: From<[u8; 32]>,165{166 #[weight(<SelfWeightOf<T>>::approve())]167 fn approve_cross(168 &mut self,169 caller: caller,170 spender: (address, uint256),171 amount: uint256,172 ) -> Result<bool> {173 let caller = T::CrossAccountId::from_eth(caller);174 let spender = convert_tuple_to_cross_account::<T>(spender)?;175 let amount = amount.try_into().map_err(|_| "amount overflow")?;176177 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)178 .map_err(dispatch_to_evm::<T>)?;179 Ok(true)180 }181182 /// Burn tokens from account183 /// @dev Function that burns an `amount` of the tokens of a given account,184 /// deducting from the sender's allowance for said account.185 /// @param from The account whose tokens will be burnt.186 /// @param amount The amount that will be burnt.187 #[weight(<SelfWeightOf<T>>::burn_from())]188 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {189 let caller = T::CrossAccountId::from_eth(caller);190 let from = T::CrossAccountId::from_eth(from);191 let amount = amount.try_into().map_err(|_| "amount overflow")?;192 let budget = self193 .recorder194 .weight_calls_budget(<StructureWeight<T>>::find_parent());195196 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)197 .map_err(dispatch_to_evm::<T>)?;198 Ok(true)199 }200201 /// Burn tokens from account202 /// @dev Function that burns an `amount` of the tokens of a given account,203 /// deducting from the sender's allowance for said account.204 /// @param from The account whose tokens will be burnt.205 /// @param amount The amount that will be burnt.206 #[weight(<SelfWeightOf<T>>::burn_from())]207 fn burn_from_cross(208 &mut self,209 caller: caller,210 from: (address, uint256),211 amount: uint256,212 ) -> Result<bool> {213 let caller = T::CrossAccountId::from_eth(caller);214 let from = convert_tuple_to_cross_account::<T>(from)?;215 let amount = amount.try_into().map_err(|_| "amount overflow")?;216 let budget = self217 .recorder218 .weight_calls_budget(<StructureWeight<T>>::find_parent());219220 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)221 .map_err(dispatch_to_evm::<T>)?;222 Ok(true)223 }224225 /// Mint tokens for multiple accounts.226 /// @param amounts array of pairs of account address and amount227 #[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]228 fn mint_bulk(&mut self, caller: caller, amounts: Vec<(address, uint256)>) -> Result<bool> {229 let caller = T::CrossAccountId::from_eth(caller);230 let budget = self231 .recorder232 .weight_calls_budget(<StructureWeight<T>>::find_parent());233 let amounts = amounts234 .into_iter()235 .map(|(to, amount)| {236 Ok((237 T::CrossAccountId::from_eth(to),238 amount.try_into().map_err(|_| "amount overflow")?,239 ))240 })241 .collect::<Result<_>>()?;242243 <Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)244 .map_err(dispatch_to_evm::<T>)?;245 Ok(true)246 }247248 #[weight(<SelfWeightOf<T>>::transfer_from())]249 fn transfer_from_cross(250 &mut self,251 caller: caller,252 from: (address, uint256),253 to: (address, uint256),254 amount: uint256,255 ) -> Result<bool> {256 let caller = T::CrossAccountId::from_eth(caller);257 let from = convert_tuple_to_cross_account::<T>(from)?;258 let to = convert_tuple_to_cross_account::<T>(to)?;259 let amount = amount.try_into().map_err(|_| "amount overflow")?;260 let budget = self261 .recorder262 .weight_calls_budget(<StructureWeight<T>>::find_parent());263264 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)265 .map_err(dispatch_to_evm::<T>)?;266 Ok(true)267 }268}269270#[solidity_interface(271 name = UniqueFungible,272 is(273 ERC20,274 ERC20Mintable,275 ERC20UniqueExtensions,276 Collection(via(common_mut returns CollectionHandle<T>)),277 )278)]279impl<T: Config> FungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}280281generate_stubgen!(gen_impl, UniqueFungibleCall<()>, true);282generate_stubgen!(gen_iface, UniqueFungibleCall<()>, false);283284impl<T: Config> CommonEvmHandler for FungibleHandle<T>285where286 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,287{288 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");289290 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {291 call::<T, UniqueFungibleCall<T>, _, _>(handle, self)292 }293}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! ERC-20 standart support implementation.1819extern crate alloc;20use core::char::{REPLACEMENT_CHARACTER, decode_utf16};21use core::convert::TryInto;22use evm_coder::{23 ToLog,24 execution::*,25 generate_stubgen, solidity_interface,26 types::*,27 weight,28 custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},29 make_signature,30};31use pallet_common::eth::convert_tuple_to_cross_account;32use up_data_structs::CollectionMode;33use pallet_common::erc::{CommonEvmHandler, PrecompileResult};34use sp_std::vec::Vec;35use pallet_evm::{account::CrossAccountId, PrecompileHandle};36use pallet_evm_coder_substrate::{call, dispatch_to_evm};37use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};38use pallet_common::{CollectionHandle, erc::CollectionCall};3940use crate::{41 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,42 weights::WeightInfo,43};4445#[derive(ToLog)]46pub enum ERC20Events {47 Transfer {48 #[indexed]49 from: address,50 #[indexed]51 to: address,52 value: uint256,53 },54 Approval {55 #[indexed]56 owner: address,57 #[indexed]58 spender: address,59 value: uint256,60 },61}6263#[solidity_interface(name = ERC20, events(ERC20Events))]64impl<T: Config> FungibleHandle<T> {65 fn name(&self) -> Result<string> {66 Ok(decode_utf16(self.name.iter().copied())67 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))68 .collect::<string>())69 }70 fn symbol(&self) -> Result<string> {71 Ok(string::from_utf8_lossy(&self.token_prefix).into())72 }73 fn total_supply(&self) -> Result<uint256> {74 self.consume_store_reads(1)?;75 Ok(<TotalSupply<T>>::get(self.id).into())76 }7778 fn decimals(&self) -> Result<uint8> {79 Ok(if let CollectionMode::Fungible(decimals) = &self.mode {80 *decimals81 } else {82 unreachable!()83 })84 }85 fn balance_of(&self, owner: address) -> Result<uint256> {86 self.consume_store_reads(1)?;87 let owner = T::CrossAccountId::from_eth(owner);88 let balance = <Balance<T>>::get((self.id, owner));89 Ok(balance.into())90 }91 #[weight(<SelfWeightOf<T>>::transfer())]92 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {93 let caller = T::CrossAccountId::from_eth(caller);94 let to = T::CrossAccountId::from_eth(to);95 let amount = amount.try_into().map_err(|_| "amount overflow")?;96 let budget = self97 .recorder98 .weight_calls_budget(<StructureWeight<T>>::find_parent());99100 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;101 Ok(true)102 }103 #[weight(<SelfWeightOf<T>>::transfer_from())]104 fn transfer_from(105 &mut self,106 caller: caller,107 from: address,108 to: address,109 amount: uint256,110 ) -> Result<bool> {111 let caller = T::CrossAccountId::from_eth(caller);112 let from = T::CrossAccountId::from_eth(from);113 let to = T::CrossAccountId::from_eth(to);114 let amount = amount.try_into().map_err(|_| "amount overflow")?;115 let budget = self116 .recorder117 .weight_calls_budget(<StructureWeight<T>>::find_parent());118119 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)120 .map_err(dispatch_to_evm::<T>)?;121 Ok(true)122 }123 #[weight(<SelfWeightOf<T>>::approve())]124 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {125 let caller = T::CrossAccountId::from_eth(caller);126 let spender = T::CrossAccountId::from_eth(spender);127 let amount = amount.try_into().map_err(|_| "amount overflow")?;128129 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)130 .map_err(dispatch_to_evm::<T>)?;131 Ok(true)132 }133 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {134 self.consume_store_reads(1)?;135 let owner = T::CrossAccountId::from_eth(owner);136 let spender = T::CrossAccountId::from_eth(spender);137138 Ok(<Allowance<T>>::get((self.id, owner, spender)).into())139 }140}141142#[solidity_interface(name = ERC20Mintable)]143impl<T: Config> FungibleHandle<T> {144 /// Mint tokens for `to` account.145 /// @param to account that will receive minted tokens146 /// @param amount amount of tokens to mint147 #[weight(<SelfWeightOf<T>>::create_item())]148 fn mint(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {149 let caller = T::CrossAccountId::from_eth(caller);150 let to = T::CrossAccountId::from_eth(to);151 let amount = amount.try_into().map_err(|_| "amount overflow")?;152 let budget = self153 .recorder154 .weight_calls_budget(<StructureWeight<T>>::find_parent());155 <Pallet<T>>::create_item(&self, &caller, (to, amount), &budget)156 .map_err(dispatch_to_evm::<T>)?;157 Ok(true)158 }159}160161#[solidity_interface(name = ERC20UniqueExtensions)]162impl<T: Config> FungibleHandle<T>163where164 T::AccountId: From<[u8; 32]>,165{166 #[weight(<SelfWeightOf<T>>::approve())]167 fn approve_cross(168 &mut self,169 caller: caller,170 spender: EthCrossAccount,171 amount: uint256,172 ) -> Result<bool> {173 let caller = T::CrossAccountId::from_eth(caller);174 let spender = spender.into_sub_cross_account::<T>()?;175 let amount = amount.try_into().map_err(|_| "amount overflow")?;176177 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)178 .map_err(dispatch_to_evm::<T>)?;179 Ok(true)180 }181182 /// Burn tokens from account183 /// @dev Function that burns an `amount` of the tokens of a given account,184 /// deducting from the sender's allowance for said account.185 /// @param from The account whose tokens will be burnt.186 /// @param amount The amount that will be burnt.187 #[weight(<SelfWeightOf<T>>::burn_from())]188 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {189 let caller = T::CrossAccountId::from_eth(caller);190 let from = T::CrossAccountId::from_eth(from);191 let amount = amount.try_into().map_err(|_| "amount overflow")?;192 let budget = self193 .recorder194 .weight_calls_budget(<StructureWeight<T>>::find_parent());195196 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)197 .map_err(dispatch_to_evm::<T>)?;198 Ok(true)199 }200201 /// Burn tokens from account202 /// @dev Function that burns an `amount` of the tokens of a given account,203 /// deducting from the sender's allowance for said account.204 /// @param from The account whose tokens will be burnt.205 /// @param amount The amount that will be burnt.206 #[weight(<SelfWeightOf<T>>::burn_from())]207 fn burn_from_cross(208 &mut self,209 caller: caller,210 from: EthCrossAccount,211 amount: uint256,212 ) -> Result<bool> {213 let caller = T::CrossAccountId::from_eth(caller);214 let from = from.into_sub_cross_account::<T>()?;215 let amount = amount.try_into().map_err(|_| "amount overflow")?;216 let budget = self217 .recorder218 .weight_calls_budget(<StructureWeight<T>>::find_parent());219220 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)221 .map_err(dispatch_to_evm::<T>)?;222 Ok(true)223 }224225 /// Mint tokens for multiple accounts.226 /// @param amounts array of pairs of account address and amount227 #[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]228 fn mint_bulk(&mut self, caller: caller, amounts: Vec<(address, uint256)>) -> Result<bool> {229 let caller = T::CrossAccountId::from_eth(caller);230 let budget = self231 .recorder232 .weight_calls_budget(<StructureWeight<T>>::find_parent());233 let amounts = amounts234 .into_iter()235 .map(|(to, amount)| {236 Ok((237 T::CrossAccountId::from_eth(to),238 amount.try_into().map_err(|_| "amount overflow")?,239 ))240 })241 .collect::<Result<_>>()?;242243 <Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)244 .map_err(dispatch_to_evm::<T>)?;245 Ok(true)246 }247248 #[weight(<SelfWeightOf<T>>::transfer_from())]249 fn transfer_from_cross(250 &mut self,251 caller: caller,252 from: EthCrossAccount,253 to: EthCrossAccount,254 amount: uint256,255 ) -> Result<bool> {256 let caller = T::CrossAccountId::from_eth(caller);257 let from = from.into_sub_cross_account::<T>()?;258 let to = to.into_sub_cross_account::<T>()?;259 let amount = amount.try_into().map_err(|_| "amount overflow")?;260 let budget = self261 .recorder262 .weight_calls_budget(<StructureWeight<T>>::find_parent());263264 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)265 .map_err(dispatch_to_evm::<T>)?;266 Ok(true)267 }268}269270#[solidity_interface(271 name = UniqueFungible,272 is(273 ERC20,274 ERC20Mintable,275 ERC20UniqueExtensions,276 Collection(via(common_mut returns CollectionHandle<T>)),277 )278)]279impl<T: Config> FungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}280281generate_stubgen!(gen_impl, UniqueFungibleCall<()>, true);282generate_stubgen!(gen_iface, UniqueFungibleCall<()>, false);283284impl<T: Config> CommonEvmHandler for FungibleHandle<T>285where286 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,287{288 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");289290 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {291 call::<T, UniqueFungibleCall<T>, _, _>(handle, self)292 }293}pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -684,11 +684,11 @@
fn approve_cross(
&mut self,
caller: caller,
- approved: (address, uint256),
+ approved: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- let approved = convert_tuple_to_cross_account::<T>(approved)?;
+ let approved = approved.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))
@@ -770,11 +770,11 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
+ from: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- let from = convert_tuple_to_cross_account::<T>(from)?;
+ let from = from.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
let budget = self
.recorder
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -734,23 +734,23 @@
fn transfer_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
- to: (address, uint256),
+ from: EthCrossAccount,
+ to: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- // let from = convert_tuple_to_cross_account::<T>(from)?;
- // let to = convert_tuple_to_cross_account::<T>(to)?;
- // let token_id = token_id.try_into()?;
- // let budget = self
- // .recorder
- // .weight_calls_budget(<StructureWeight<T>>::find_parent());
+ let from = from.into_sub_cross_account::<T>()?;
+ let to = to.into_sub_cross_account::<T>()?;
+ let token_id = token_id.try_into()?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
- // let balance = balance(self, token_id, &from)?;
- // ensure_single_owner(self, token_id, balance)?;
+ let balance = balance(self, token_id, &from)?;
+ ensure_single_owner(self, token_id, balance)?;
- // Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)
- // .map_err(dispatch_to_evm::<T>)?;
+ Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -789,11 +789,11 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
+ from: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- let from = convert_tuple_to_cross_account::<T>(from)?;
+ let from = from.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
let budget = self
.recorder
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -94,25 +94,6 @@
await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;
});
-
- itEth.skip('Check adminlist', async ({helper, privateKey}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
-
- const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
- const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
-
- const admin1 = helper.eth.createAccount();
- const admin2 = privateKey('admin');
- await collectionEvm.methods.addCollectionAdmin(admin1).send();
- await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();
-
- const adminListRpc = await helper.collection.getAdmins(collectionId);
- let adminListEth = await collectionEvm.methods.collectionAdmins().call();
- adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
- return helper.address.convertCrossAccountFromEthCrossAcoount(element);
- });
- expect(adminListRpc).to.be.like(adminListEth);
- });
itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -409,7 +409,7 @@
expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itEth.only('Can perform transferFromCross()', async ({helper, privateKey}) => {
+ itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
const alice = privateKey('//Alice');
const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
tests/src/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -73,8 +73,8 @@
export interface IEthCrossAccountId {
0: TEthereumAccount;
1: TSubstrateAccount;
- field_0: TEthereumAccount;
- field_1: TSubstrateAccount;
+ eth: TEthereumAccount;
+ sub: TSubstrateAccount;
}
export interface ICollectionLimits {
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2430,11 +2430,11 @@
* @returns substrate cross account id
*/
convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
- if (ethCrossAccount.field_1 === '0') {
- return {Ethereum: ethCrossAccount.field_0.toLocaleLowerCase()};
+ if (ethCrossAccount.sub === '0') {
+ return {Ethereum: ethCrossAccount.eth.toLocaleLowerCase()};
}
- const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.field_1));
+ const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.sub));
return {Substrate: ss58};
}