difftreelog
added `mintCross` function for `UniqueExtensoins` interfaces
in: master
20 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6085,7 +6085,7 @@
[[package]]
name = "pallet-fungible"
-version = "0.1.7"
+version = "0.1.9"
dependencies = [
"ethereum 0.14.0",
"evm-coder",
pallets/fungible/CHANGELOG.mddiffbeforeafterboth--- a/pallets/fungible/CHANGELOG.md
+++ b/pallets/fungible/CHANGELOG.md
@@ -4,6 +4,12 @@
<!-- bureaucrate goes here -->
+## [0.1.9] - 2022-12-01
+
+### Added
+
+- The functions `mintCross` to `ERC20UniqueExtensions` interface.
+
## [0.1.8] - 2022-11-18
### Added
pallets/fungible/Cargo.tomldiffbeforeafterboth--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pallet-fungible"
-version = "0.1.7"
+version = "0.1.9"
license = "GPLv3"
edition = "2021"
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 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,24 weight,25};26use up_data_structs::CollectionMode;27use pallet_common::{28 CollectionHandle,29 erc::{CommonEvmHandler, PrecompileResult, CollectionCall},30 eth::EthCrossAccount,31};32use sp_std::vec::Vec;33use pallet_evm::{account::CrossAccountId, PrecompileHandle};34use pallet_evm_coder_substrate::{call, dispatch_to_evm};35use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};36use sp_core::Get;3738use crate::{39 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,40 weights::WeightInfo,41};4243#[derive(ToLog)]44pub enum ERC20Events {45 Transfer {46 #[indexed]47 from: address,48 #[indexed]49 to: address,50 value: uint256,51 },52 Approval {53 #[indexed]54 owner: address,55 #[indexed]56 spender: address,57 value: uint256,58 },59}6061#[solidity_interface(name = ERC20, events(ERC20Events))]62impl<T: Config> FungibleHandle<T> {63 fn name(&self) -> Result<string> {64 Ok(decode_utf16(self.name.iter().copied())65 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))66 .collect::<string>())67 }68 fn symbol(&self) -> Result<string> {69 Ok(string::from_utf8_lossy(&self.token_prefix).into())70 }71 fn total_supply(&self) -> Result<uint256> {72 self.consume_store_reads(1)?;73 Ok(<TotalSupply<T>>::get(self.id).into())74 }7576 fn decimals(&self) -> Result<uint8> {77 Ok(if let CollectionMode::Fungible(decimals) = &self.mode {78 *decimals79 } else {80 unreachable!()81 })82 }83 fn balance_of(&self, owner: address) -> Result<uint256> {84 self.consume_store_reads(1)?;85 let owner = T::CrossAccountId::from_eth(owner);86 let balance = <Balance<T>>::get((self.id, owner));87 Ok(balance.into())88 }89 #[weight(<SelfWeightOf<T>>::transfer())]90 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {91 let caller = T::CrossAccountId::from_eth(caller);92 let to = T::CrossAccountId::from_eth(to);93 let amount = amount.try_into().map_err(|_| "amount overflow")?;94 let budget = self95 .recorder96 .weight_calls_budget(<StructureWeight<T>>::find_parent());9798 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;99 Ok(true)100 }101102 #[weight(<SelfWeightOf<T>>::transfer_from())]103 fn transfer_from(104 &mut self,105 caller: caller,106 from: address,107 to: address,108 amount: uint256,109 ) -> Result<bool> {110 let caller = T::CrossAccountId::from_eth(caller);111 let from = T::CrossAccountId::from_eth(from);112 let to = T::CrossAccountId::from_eth(to);113 let amount = amount.try_into().map_err(|_| "amount overflow")?;114 let budget = self115 .recorder116 .weight_calls_budget(<StructureWeight<T>>::find_parent());117118 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)119 .map_err(dispatch_to_evm::<T>)?;120 Ok(true)121 }122 #[weight(<SelfWeightOf<T>>::approve())]123 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {124 let caller = T::CrossAccountId::from_eth(caller);125 let spender = T::CrossAccountId::from_eth(spender);126 let amount = amount.try_into().map_err(|_| "amount overflow")?;127128 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)129 .map_err(dispatch_to_evm::<T>)?;130 Ok(true)131 }132 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {133 self.consume_store_reads(1)?;134 let owner = T::CrossAccountId::from_eth(owner);135 let spender = T::CrossAccountId::from_eth(spender);136137 Ok(<Allowance<T>>::get((self.id, owner, spender)).into())138 }139140 /// @notice Returns collection helper contract address141 fn collection_helper_address(&self) -> Result<address> {142 Ok(T::ContractAddress::get())143 }144}145146#[solidity_interface(name = ERC20Mintable)]147impl<T: Config> FungibleHandle<T> {148 /// Mint tokens for `to` account.149 /// @param to account that will receive minted tokens150 /// @param amount amount of tokens to mint151 #[weight(<SelfWeightOf<T>>::create_item())]152 fn mint(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {153 let caller = T::CrossAccountId::from_eth(caller);154 let to = T::CrossAccountId::from_eth(to);155 let amount = amount.try_into().map_err(|_| "amount overflow")?;156 let budget = self157 .recorder158 .weight_calls_budget(<StructureWeight<T>>::find_parent());159 <Pallet<T>>::create_item(&self, &caller, (to, amount), &budget)160 .map_err(dispatch_to_evm::<T>)?;161 Ok(true)162 }163}164165#[solidity_interface(name = ERC20UniqueExtensions)]166impl<T: Config> FungibleHandle<T>167where168 T::AccountId: From<[u8; 32]>,169{170 /// @notice A description for the collection.171 fn description(&self) -> Result<string> {172 Ok(decode_utf16(self.description.iter().copied())173 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))174 .collect::<string>())175 }176177 #[weight(<SelfWeightOf<T>>::approve())]178 fn approve_cross(179 &mut self,180 caller: caller,181 spender: EthCrossAccount,182 amount: uint256,183 ) -> Result<bool> {184 let caller = T::CrossAccountId::from_eth(caller);185 let spender = spender.into_sub_cross_account::<T>()?;186 let amount = amount.try_into().map_err(|_| "amount overflow")?;187188 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)189 .map_err(dispatch_to_evm::<T>)?;190 Ok(true)191 }192193 /// Burn tokens from account194 /// @dev Function that burns an `amount` of the tokens of a given account,195 /// deducting from the sender's allowance for said account.196 /// @param from The account whose tokens will be burnt.197 /// @param amount The amount that will be burnt.198 #[solidity(hide)]199 #[weight(<SelfWeightOf<T>>::burn_from())]200 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {201 let caller = T::CrossAccountId::from_eth(caller);202 let from = T::CrossAccountId::from_eth(from);203 let amount = amount.try_into().map_err(|_| "amount overflow")?;204 let budget = self205 .recorder206 .weight_calls_budget(<StructureWeight<T>>::find_parent());207208 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)209 .map_err(dispatch_to_evm::<T>)?;210 Ok(true)211 }212213 /// Burn tokens from account214 /// @dev Function that burns an `amount` of the tokens of a given account,215 /// deducting from the sender's allowance for said account.216 /// @param from The account whose tokens will be burnt.217 /// @param amount The amount that will be burnt.218 #[weight(<SelfWeightOf<T>>::burn_from())]219 fn burn_from_cross(220 &mut self,221 caller: caller,222 from: EthCrossAccount,223 amount: uint256,224 ) -> Result<bool> {225 let caller = T::CrossAccountId::from_eth(caller);226 let from = from.into_sub_cross_account::<T>()?;227 let amount = amount.try_into().map_err(|_| "amount overflow")?;228 let budget = self229 .recorder230 .weight_calls_budget(<StructureWeight<T>>::find_parent());231232 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)233 .map_err(dispatch_to_evm::<T>)?;234 Ok(true)235 }236237 /// Mint tokens for multiple accounts.238 /// @param amounts array of pairs of account address and amount239 #[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]240 fn mint_bulk(&mut self, caller: caller, amounts: Vec<(address, uint256)>) -> Result<bool> {241 let caller = T::CrossAccountId::from_eth(caller);242 let budget = self243 .recorder244 .weight_calls_budget(<StructureWeight<T>>::find_parent());245 let amounts = amounts246 .into_iter()247 .map(|(to, amount)| {248 Ok((249 T::CrossAccountId::from_eth(to),250 amount.try_into().map_err(|_| "amount overflow")?,251 ))252 })253 .collect::<Result<_>>()?;254255 <Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)256 .map_err(dispatch_to_evm::<T>)?;257 Ok(true)258 }259260 #[weight(<SelfWeightOf<T>>::transfer())]261 fn transfer_cross(262 &mut self,263 caller: caller,264 to: EthCrossAccount,265 amount: uint256,266 ) -> Result<bool> {267 let caller = T::CrossAccountId::from_eth(caller);268 let to = to.into_sub_cross_account::<T>()?;269 let amount = amount.try_into().map_err(|_| "amount overflow")?;270 let budget = self271 .recorder272 .weight_calls_budget(<StructureWeight<T>>::find_parent());273274 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;275 Ok(true)276 }277278 #[weight(<SelfWeightOf<T>>::transfer_from())]279 fn transfer_from_cross(280 &mut self,281 caller: caller,282 from: EthCrossAccount,283 to: EthCrossAccount,284 amount: uint256,285 ) -> Result<bool> {286 let caller = T::CrossAccountId::from_eth(caller);287 let from = from.into_sub_cross_account::<T>()?;288 let to = to.into_sub_cross_account::<T>()?;289 let amount = amount.try_into().map_err(|_| "amount overflow")?;290 let budget = self291 .recorder292 .weight_calls_budget(<StructureWeight<T>>::find_parent());293294 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)295 .map_err(dispatch_to_evm::<T>)?;296 Ok(true)297 }298}299300#[solidity_interface(301 name = UniqueFungible,302 is(303 ERC20,304 ERC20Mintable,305 ERC20UniqueExtensions,306 Collection(via(common_mut returns CollectionHandle<T>)),307 )308)]309impl<T: Config> FungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}310311generate_stubgen!(gen_impl, UniqueFungibleCall<()>, true);312generate_stubgen!(gen_iface, UniqueFungibleCall<()>, false);313314impl<T: Config> CommonEvmHandler for FungibleHandle<T>315where316 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,317{318 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");319320 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {321 call::<T, UniqueFungibleCall<T>, _, _>(handle, self)322 }323}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 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,24 weight,25};26use up_data_structs::CollectionMode;27use pallet_common::{28 CollectionHandle,29 erc::{CommonEvmHandler, PrecompileResult, CollectionCall},30 eth::EthCrossAccount,31};32use sp_std::vec::Vec;33use pallet_evm::{account::CrossAccountId, PrecompileHandle};34use pallet_evm_coder_substrate::{call, dispatch_to_evm};35use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};36use sp_core::Get;3738use crate::{39 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,40 weights::WeightInfo,41};4243#[derive(ToLog)]44pub enum ERC20Events {45 Transfer {46 #[indexed]47 from: address,48 #[indexed]49 to: address,50 value: uint256,51 },52 Approval {53 #[indexed]54 owner: address,55 #[indexed]56 spender: address,57 value: uint256,58 },59}6061#[solidity_interface(name = ERC20, events(ERC20Events))]62impl<T: Config> FungibleHandle<T> {63 fn name(&self) -> Result<string> {64 Ok(decode_utf16(self.name.iter().copied())65 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))66 .collect::<string>())67 }68 fn symbol(&self) -> Result<string> {69 Ok(string::from_utf8_lossy(&self.token_prefix).into())70 }71 fn total_supply(&self) -> Result<uint256> {72 self.consume_store_reads(1)?;73 Ok(<TotalSupply<T>>::get(self.id).into())74 }7576 fn decimals(&self) -> Result<uint8> {77 Ok(if let CollectionMode::Fungible(decimals) = &self.mode {78 *decimals79 } else {80 unreachable!()81 })82 }83 fn balance_of(&self, owner: address) -> Result<uint256> {84 self.consume_store_reads(1)?;85 let owner = T::CrossAccountId::from_eth(owner);86 let balance = <Balance<T>>::get((self.id, owner));87 Ok(balance.into())88 }89 #[weight(<SelfWeightOf<T>>::transfer())]90 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {91 let caller = T::CrossAccountId::from_eth(caller);92 let to = T::CrossAccountId::from_eth(to);93 let amount = amount.try_into().map_err(|_| "amount overflow")?;94 let budget = self95 .recorder96 .weight_calls_budget(<StructureWeight<T>>::find_parent());9798 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;99 Ok(true)100 }101102 #[weight(<SelfWeightOf<T>>::transfer_from())]103 fn transfer_from(104 &mut self,105 caller: caller,106 from: address,107 to: address,108 amount: uint256,109 ) -> Result<bool> {110 let caller = T::CrossAccountId::from_eth(caller);111 let from = T::CrossAccountId::from_eth(from);112 let to = T::CrossAccountId::from_eth(to);113 let amount = amount.try_into().map_err(|_| "amount overflow")?;114 let budget = self115 .recorder116 .weight_calls_budget(<StructureWeight<T>>::find_parent());117118 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)119 .map_err(dispatch_to_evm::<T>)?;120 Ok(true)121 }122 #[weight(<SelfWeightOf<T>>::approve())]123 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {124 let caller = T::CrossAccountId::from_eth(caller);125 let spender = T::CrossAccountId::from_eth(spender);126 let amount = amount.try_into().map_err(|_| "amount overflow")?;127128 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)129 .map_err(dispatch_to_evm::<T>)?;130 Ok(true)131 }132 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {133 self.consume_store_reads(1)?;134 let owner = T::CrossAccountId::from_eth(owner);135 let spender = T::CrossAccountId::from_eth(spender);136137 Ok(<Allowance<T>>::get((self.id, owner, spender)).into())138 }139140 /// @notice Returns collection helper contract address141 fn collection_helper_address(&self) -> Result<address> {142 Ok(T::ContractAddress::get())143 }144}145146#[solidity_interface(name = ERC20Mintable)]147impl<T: Config> FungibleHandle<T> {148 /// Mint tokens for `to` account.149 /// @param to account that will receive minted tokens150 /// @param amount amount of tokens to mint151 #[weight(<SelfWeightOf<T>>::create_item())]152 fn mint(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {153 let caller = T::CrossAccountId::from_eth(caller);154 let to = T::CrossAccountId::from_eth(to);155 let amount = amount.try_into().map_err(|_| "amount overflow")?;156 let budget = self157 .recorder158 .weight_calls_budget(<StructureWeight<T>>::find_parent());159 <Pallet<T>>::create_item(&self, &caller, (to, amount), &budget)160 .map_err(dispatch_to_evm::<T>)?;161 Ok(true)162 }163}164165#[solidity_interface(name = ERC20UniqueExtensions)]166impl<T: Config> FungibleHandle<T>167where168 T::AccountId: From<[u8; 32]>,169{170 /// @notice A description for the collection.171 fn description(&self) -> Result<string> {172 Ok(decode_utf16(self.description.iter().copied())173 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))174 .collect::<string>())175 }176177 #[weight(<SelfWeightOf<T>>::create_item())]178 fn mint_cross(&mut self, caller: caller, to: EthCrossAccount, amount: uint256) -> Result<bool> {179 let caller = T::CrossAccountId::from_eth(caller);180 let to = to.into_sub_cross_account::<T>()?;181 let amount = amount.try_into().map_err(|_| "amount overflow")?;182 let budget = self183 .recorder184 .weight_calls_budget(<StructureWeight<T>>::find_parent());185 <Pallet<T>>::create_item(&self, &caller, (to, amount), &budget)186 .map_err(dispatch_to_evm::<T>)?;187 Ok(true)188 }189190 #[weight(<SelfWeightOf<T>>::approve())]191 fn approve_cross(192 &mut self,193 caller: caller,194 spender: EthCrossAccount,195 amount: uint256,196 ) -> Result<bool> {197 let caller = T::CrossAccountId::from_eth(caller);198 let spender = spender.into_sub_cross_account::<T>()?;199 let amount = amount.try_into().map_err(|_| "amount overflow")?;200201 <Pallet<T>>::set_allowance(self, &caller, &spender, amount)202 .map_err(dispatch_to_evm::<T>)?;203 Ok(true)204 }205206 /// Burn tokens from account207 /// @dev Function that burns an `amount` of the tokens of a given account,208 /// deducting from the sender's allowance for said account.209 /// @param from The account whose tokens will be burnt.210 /// @param amount The amount that will be burnt.211 #[solidity(hide)]212 #[weight(<SelfWeightOf<T>>::burn_from())]213 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {214 let caller = T::CrossAccountId::from_eth(caller);215 let from = T::CrossAccountId::from_eth(from);216 let amount = amount.try_into().map_err(|_| "amount overflow")?;217 let budget = self218 .recorder219 .weight_calls_budget(<StructureWeight<T>>::find_parent());220221 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)222 .map_err(dispatch_to_evm::<T>)?;223 Ok(true)224 }225226 /// Burn tokens from account227 /// @dev Function that burns an `amount` of the tokens of a given account,228 /// deducting from the sender's allowance for said account.229 /// @param from The account whose tokens will be burnt.230 /// @param amount The amount that will be burnt.231 #[weight(<SelfWeightOf<T>>::burn_from())]232 fn burn_from_cross(233 &mut self,234 caller: caller,235 from: EthCrossAccount,236 amount: uint256,237 ) -> Result<bool> {238 let caller = T::CrossAccountId::from_eth(caller);239 let from = from.into_sub_cross_account::<T>()?;240 let amount = amount.try_into().map_err(|_| "amount overflow")?;241 let budget = self242 .recorder243 .weight_calls_budget(<StructureWeight<T>>::find_parent());244245 <Pallet<T>>::burn_from(self, &caller, &from, amount, &budget)246 .map_err(dispatch_to_evm::<T>)?;247 Ok(true)248 }249250 /// Mint tokens for multiple accounts.251 /// @param amounts array of pairs of account address and amount252 #[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]253 fn mint_bulk(&mut self, caller: caller, amounts: Vec<(address, uint256)>) -> Result<bool> {254 let caller = T::CrossAccountId::from_eth(caller);255 let budget = self256 .recorder257 .weight_calls_budget(<StructureWeight<T>>::find_parent());258 let amounts = amounts259 .into_iter()260 .map(|(to, amount)| {261 Ok((262 T::CrossAccountId::from_eth(to),263 amount.try_into().map_err(|_| "amount overflow")?,264 ))265 })266 .collect::<Result<_>>()?;267268 <Pallet<T>>::create_multiple_items(&self, &caller, amounts, &budget)269 .map_err(dispatch_to_evm::<T>)?;270 Ok(true)271 }272273 #[weight(<SelfWeightOf<T>>::transfer())]274 fn transfer_cross(275 &mut self,276 caller: caller,277 to: EthCrossAccount,278 amount: uint256,279 ) -> Result<bool> {280 let caller = T::CrossAccountId::from_eth(caller);281 let to = to.into_sub_cross_account::<T>()?;282 let amount = amount.try_into().map_err(|_| "amount overflow")?;283 let budget = self284 .recorder285 .weight_calls_budget(<StructureWeight<T>>::find_parent());286287 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;288 Ok(true)289 }290291 #[weight(<SelfWeightOf<T>>::transfer_from())]292 fn transfer_from_cross(293 &mut self,294 caller: caller,295 from: EthCrossAccount,296 to: EthCrossAccount,297 amount: uint256,298 ) -> Result<bool> {299 let caller = T::CrossAccountId::from_eth(caller);300 let from = from.into_sub_cross_account::<T>()?;301 let to = to.into_sub_cross_account::<T>()?;302 let amount = amount.try_into().map_err(|_| "amount overflow")?;303 let budget = self304 .recorder305 .weight_calls_budget(<StructureWeight<T>>::find_parent());306307 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)308 .map_err(dispatch_to_evm::<T>)?;309 Ok(true)310 }311}312313#[solidity_interface(314 name = UniqueFungible,315 is(316 ERC20,317 ERC20Mintable,318 ERC20UniqueExtensions,319 Collection(via(common_mut returns CollectionHandle<T>)),320 )321)]322impl<T: Config> FungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}323324generate_stubgen!(gen_impl, UniqueFungibleCall<()>, true);325generate_stubgen!(gen_iface, UniqueFungibleCall<()>, false);326327impl<T: Config> CommonEvmHandler for FungibleHandle<T>328where329 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,330{331 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueFungible.raw");332333 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {334 call::<T, UniqueFungibleCall<T>, _, _>(handle, self)335 }336}pallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -152,10 +152,10 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() public view returns (Tuple8 memory) {
+ function collectionSponsor() public view returns (Tuple9 memory) {
require(false, stub_error);
dummy;
- return Tuple8(0x0000000000000000000000000000000000000000, 0);
+ return Tuple9(0x0000000000000000000000000000000000000000, 0);
}
/// Get current collection limits.
@@ -522,7 +522,7 @@
bytes value;
}
-/// @dev the ERC-165 identifier for this interface is 0x5b7038cf
+/// @dev the ERC-165 identifier for this interface is 0x7dee5997
contract ERC20UniqueExtensions is Dummy, ERC165 {
/// @notice A description for the collection.
/// @dev EVM selector for this function is: 0x7284e416,
@@ -533,6 +533,16 @@
return "";
}
+ /// @dev EVM selector for this function is: 0x269e6158,
+ /// or in textual repr: mintCross((address,uint256),uint256)
+ function mintCross(EthCrossAccount memory to, uint256 amount) public returns (bool) {
+ require(false, stub_error);
+ to;
+ amount;
+ dummy = 0;
+ return false;
+ }
+
/// @dev EVM selector for this function is: 0x0ecd0ab0,
/// or in textual repr: approveCross((address,uint256),uint256)
function approveCross(EthCrossAccount memory spender, uint256 amount) public returns (bool) {
@@ -577,7 +587,7 @@
/// @param amounts array of pairs of account address and amount
/// @dev EVM selector for this function is: 0x1acf2d55,
/// or in textual repr: mintBulk((address,uint256)[])
- function mintBulk(Tuple8[] memory amounts) public returns (bool) {
+ function mintBulk(Tuple9[] memory amounts) public returns (bool) {
require(false, stub_error);
amounts;
dummy = 0;
@@ -611,7 +621,7 @@
}
/// @dev anonymous struct
-struct Tuple8 {
+struct Tuple9 {
address field_0;
uint256 field_1;
}
pallets/nonfungible/CHANGELOG.mddiffbeforeafterboth--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -4,7 +4,7 @@
<!-- bureaucrate goes here -->
-## [0.1.11] - 2022-12-16
+## [0.1.12] - 2022-12-16
### Added
@@ -14,6 +14,12 @@
- Hide `setTokenPropertyPermission` function in `TokenProperties` interface.
+## [0.1.11] - 2022-12-01
+
+### Added
+
+- The functions `mintCross` to `ERC721UniqueExtensions` interface.
+
## [0.1.10] - 2022-11-18
### Added
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -1069,6 +1069,58 @@
.map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
+
+ /// @notice Function to mint token.
+ /// @param to The new owner crossAccountId
+ /// @param properties Properties of minted token
+ /// @return uint256 The id of the newly minted token
+ #[weight(<SelfWeightOf<T>>::create_item())]
+ fn mint_cross(
+ &mut self,
+ caller: caller,
+ to: EthCrossAccount,
+ properties: Vec<PropertyStruct>,
+ ) -> Result<uint256> {
+ let token_id = <TokensMinted<T>>::get(self.id)
+ .checked_add(1)
+ .ok_or("item id overflow")?;
+
+ let to = to.into_sub_cross_account::<T>()?;
+
+ let properties = properties
+ .into_iter()
+ .map(|PropertyStruct { key, value }| {
+ let key = <Vec<u8>>::from(key)
+ .try_into()
+ .map_err(|_| "key too large")?;
+
+ let value = value.0.try_into().map_err(|_| "value too large")?;
+
+ Ok(Property { key, value })
+ })
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;
+
+ let caller = T::CrossAccountId::from_eth(caller);
+
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
+ <Pallet<T>>::create_item(
+ self,
+ &caller,
+ CreateItemData::<T> {
+ properties,
+ owner: to,
+ },
+ &budget,
+ )
+ .map_err(dispatch_to_evm::<T>)?;
+
+ Ok(token_id.into())
+ }
}
#[solidity_interface(
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -290,10 +290,10 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() public view returns (Tuple30 memory) {
+ function collectionSponsor() public view returns (Tuple32 memory) {
require(false, stub_error);
dummy;
- return Tuple30(0x0000000000000000000000000000000000000000, 0);
+ return Tuple32(0x0000000000000000000000000000000000000000, 0);
}
/// Get current collection limits.
@@ -655,7 +655,7 @@
}
/// @dev anonymous struct
-struct Tuple30 {
+struct Tuple32 {
address field_0;
uint256 field_1;
}
@@ -804,7 +804,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xb74c26b7
+/// @dev the ERC-165 identifier for this interface is 0x0e48fdb4
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -961,6 +961,7 @@
dummy;
return 0;
}
+
// /// @notice Function to mint multiple tokens.
// /// @dev `tokenIds` should be an array of consecutive numbers and first number
// /// should be obtained with `nextTokenId` method
@@ -991,6 +992,19 @@
// return false;
// }
+ /// @notice Function to mint token.
+ /// @param to The new owner crossAccountId
+ /// @param properties Properties of minted token
+ /// @return uint256 The id of the newly minted token
+ /// @dev EVM selector for this function is: 0xb904db03,
+ /// or in textual repr: mintCross((address,uint256),(string,bytes)[])
+ function mintCross(EthCrossAccount memory to, Property[] memory properties) public returns (uint256) {
+ require(false, stub_error);
+ to;
+ properties;
+ dummy = 0;
+ return 0;
+ }
}
/// @dev anonymous struct
pallets/refungible/CHANGELOG.mddiffbeforeafterboth--- a/pallets/refungible/CHANGELOG.md
+++ b/pallets/refungible/CHANGELOG.md
@@ -4,7 +4,7 @@
<!-- bureaucrate goes here -->
-## [0.2.10] - 2022-12-16
+## [0.2.11] - 2022-12-16
### Added
@@ -14,6 +14,12 @@
- Hide `setTokenPropertyPermission` function in `TokenProperties` interface.
+## [0.2.10] - 2022-12-01
+
+### Added
+
+- The functions `mintCross` to `ERC721UniqueExtensions` interface.
+
## [0.2.9] - 2022-11-18
### Added
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -1120,6 +1120,60 @@
Ok(true)
}
+ /// @notice Function to mint token.
+ /// @param to The new owner crossAccountId
+ /// @param properties Properties of minted token
+ /// @return uint256 The id of the newly minted token
+ #[weight(<SelfWeightOf<T>>::create_item())]
+ fn mint_cross(
+ &mut self,
+ caller: caller,
+ to: EthCrossAccount,
+ properties: Vec<PropertyStruct>,
+ ) -> Result<uint256> {
+ let token_id = <TokensMinted<T>>::get(self.id)
+ .checked_add(1)
+ .ok_or("item id overflow")?;
+
+ let to = to.into_sub_cross_account::<T>()?;
+
+ let properties = properties
+ .into_iter()
+ .map(|PropertyStruct { key, value }| {
+ let key = <Vec<u8>>::from(key)
+ .try_into()
+ .map_err(|_| "key too large")?;
+
+ let value = value.0.try_into().map_err(|_| "value too large")?;
+
+ Ok(Property { key, value })
+ })
+ .collect::<Result<Vec<_>>>()?
+ .try_into()
+ .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;
+
+ let caller = T::CrossAccountId::from_eth(caller);
+
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
+ let users = [(to, 1)]
+ .into_iter()
+ .collect::<BTreeMap<_, _>>()
+ .try_into()
+ .unwrap();
+ <Pallet<T>>::create_item(
+ self,
+ &caller,
+ CreateItemData::<T::CrossAccountId> { users, properties },
+ &budget,
+ )
+ .map_err(dispatch_to_evm::<T>)?;
+
+ Ok(token_id.into())
+ }
+
/// Returns EVM address for refungible token
///
/// @param token ID of the token
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -290,10 +290,10 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() public view returns (Tuple29 memory) {
+ function collectionSponsor() public view returns (Tuple31 memory) {
require(false, stub_error);
dummy;
- return Tuple29(0x0000000000000000000000000000000000000000, 0);
+ return Tuple31(0x0000000000000000000000000000000000000000, 0);
}
/// Get current collection limits.
@@ -655,7 +655,7 @@
}
/// @dev anonymous struct
-struct Tuple29 {
+struct Tuple31 {
address field_0;
uint256 field_1;
}
@@ -802,7 +802,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x12f7d6c1
+/// @dev the ERC-165 identifier for this interface is 0xabf30dc2
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -979,6 +979,20 @@
// return false;
// }
+ /// @notice Function to mint token.
+ /// @param to The new owner crossAccountId
+ /// @param properties Properties of minted token
+ /// @return uint256 The id of the newly minted token
+ /// @dev EVM selector for this function is: 0xb904db03,
+ /// or in textual repr: mintCross((address,uint256),(string,bytes)[])
+ function mintCross(EthCrossAccount memory to, Property[] memory properties) public returns (uint256) {
+ require(false, stub_error);
+ to;
+ properties;
+ dummy = 0;
+ return 0;
+ }
+
/// Returns EVM address for refungible token
///
/// @param token ID of the token
tests/src/eth/abi/fungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/fungible.json
+++ b/tests/src/eth/abi/fungible.json
@@ -322,7 +322,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple8",
+ "internalType": "struct Tuple9",
"name": "",
"type": "tuple"
}
@@ -408,7 +408,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple8[]",
+ "internalType": "struct Tuple9[]",
"name": "amounts",
"type": "tuple[]"
}
@@ -419,6 +419,24 @@
"type": "function"
},
{
+ "inputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct EthCrossAccount",
+ "name": "to",
+ "type": "tuple"
+ },
+ { "internalType": "uint256", "name": "amount", "type": "uint256" }
+ ],
+ "name": "mintCross",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -352,7 +352,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple30",
+ "internalType": "struct Tuple32",
"name": "",
"type": "tuple"
}
@@ -478,6 +478,32 @@
},
{
"inputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct EthCrossAccount",
+ "name": "to",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ { "internalType": "string", "name": "key", "type": "string" },
+ { "internalType": "bytes", "name": "value", "type": "bytes" }
+ ],
+ "internalType": "struct Property[]",
+ "name": "properties",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "mintCross",
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "string", "name": "tokenUri", "type": "string" }
],
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -334,7 +334,7 @@
{ "internalType": "address", "name": "field_0", "type": "address" },
{ "internalType": "uint256", "name": "field_1", "type": "uint256" }
],
- "internalType": "struct Tuple29",
+ "internalType": "struct Tuple31",
"name": "",
"type": "tuple"
}
@@ -460,6 +460,32 @@
},
{
"inputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct EthCrossAccount",
+ "name": "to",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ { "internalType": "string", "name": "key", "type": "string" },
+ { "internalType": "bytes", "name": "value", "type": "bytes" }
+ ],
+ "internalType": "struct Property[]",
+ "name": "properties",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "mintCross",
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "string", "name": "tokenUri", "type": "string" }
],
tests/src/eth/api/UniqueFungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -102,7 +102,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() external view returns (Tuple8 memory);
+ function collectionSponsor() external view returns (Tuple9 memory);
/// Get current collection limits.
///
@@ -362,13 +362,17 @@
bytes value;
}
-/// @dev the ERC-165 identifier for this interface is 0x5b7038cf
+/// @dev the ERC-165 identifier for this interface is 0x7dee5997
interface ERC20UniqueExtensions is Dummy, ERC165 {
/// @notice A description for the collection.
/// @dev EVM selector for this function is: 0x7284e416,
/// or in textual repr: description()
function description() external view returns (string memory);
+ /// @dev EVM selector for this function is: 0x269e6158,
+ /// or in textual repr: mintCross((address,uint256),uint256)
+ function mintCross(EthCrossAccount memory to, uint256 amount) external returns (bool);
+
/// @dev EVM selector for this function is: 0x0ecd0ab0,
/// or in textual repr: approveCross((address,uint256),uint256)
function approveCross(EthCrossAccount memory spender, uint256 amount) external returns (bool);
@@ -395,7 +399,7 @@
/// @param amounts array of pairs of account address and amount
/// @dev EVM selector for this function is: 0x1acf2d55,
/// or in textual repr: mintBulk((address,uint256)[])
- function mintBulk(Tuple8[] memory amounts) external returns (bool);
+ function mintBulk(Tuple9[] memory amounts) external returns (bool);
/// @dev EVM selector for this function is: 0x2ada85ff,
/// or in textual repr: transferCross((address,uint256),uint256)
@@ -411,7 +415,7 @@
}
/// @dev anonymous struct
-struct Tuple8 {
+struct Tuple9 {
address field_0;
uint256 field_1;
}
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -198,7 +198,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() external view returns (Tuple27 memory);
+ function collectionSponsor() external view returns (Tuple29 memory);
/// Get current collection limits.
///
@@ -553,7 +553,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xb74c26b7
+/// @dev the ERC-165 identifier for this interface is 0x0e48fdb4
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -652,6 +652,7 @@
/// @dev EVM selector for this function is: 0x75794a3c,
/// or in textual repr: nextTokenId()
function nextTokenId() external view returns (uint256);
+
// /// @notice Function to mint multiple tokens.
// /// @dev `tokenIds` should be an array of consecutive numbers and first number
// /// should be obtained with `nextTokenId` method
@@ -670,6 +671,13 @@
// /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
// function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);
+ /// @notice Function to mint token.
+ /// @param to The new owner crossAccountId
+ /// @param properties Properties of minted token
+ /// @return uint256 The id of the newly minted token
+ /// @dev EVM selector for this function is: 0xb904db03,
+ /// or in textual repr: mintCross((address,uint256),(string,bytes)[])
+ function mintCross(EthCrossAccount memory to, Property[] memory properties) external returns (uint256);
}
/// @dev anonymous struct
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -198,7 +198,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x6ec0a9f1,
/// or in textual repr: collectionSponsor()
- function collectionSponsor() external view returns (Tuple26 memory);
+ function collectionSponsor() external view returns (Tuple28 memory);
/// Get current collection limits.
///
@@ -551,7 +551,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x12f7d6c1
+/// @dev the ERC-165 identifier for this interface is 0xabf30dc2
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -663,6 +663,14 @@
// /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
// function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);
+ /// @notice Function to mint token.
+ /// @param to The new owner crossAccountId
+ /// @param properties Properties of minted token
+ /// @return uint256 The id of the newly minted token
+ /// @dev EVM selector for this function is: 0xb904db03,
+ /// or in textual repr: mintCross((address,uint256),(string,bytes)[])
+ function mintCross(EthCrossAccount memory to, Property[] memory properties) external returns (uint256);
+
/// Returns EVM address for refungible token
///
/// @param token ID of the token
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -78,6 +78,25 @@
expect(event.returnValues.to).to.equal(receiver);
expect(event.returnValues.value).to.equal('100');
});
+
+
+ itEth('Can perform mintCross()', async ({helper}) => {
+ const receiverCross = helper.ethCrossAccount.fromKeyringPair(owner);
+ const ethOwner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: ethOwner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+
+ const result = await contract.methods.mintCross(receiverCross, 100).send();
+
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(helper.address.substrateToEth(owner.address));
+ expect(event.returnValues.value).to.equal('100');
+ });
itEth('Can perform mintBulk()', 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
@@ -17,6 +17,8 @@
import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
+import exp from 'constants';
+import {ITokenPropertyPermission} from '../util/playgrounds/types';
describe('NFT: Information getting', () => {
@@ -173,7 +175,45 @@
// const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
// expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
});
+
+ itEth('Can perform mintCross()', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
+ const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+ const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true}}; });
+
+
+ const collection = await helper.nft.mintCollection(minter, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: permissions,
+ });
+ await collection.addAdmin(minter, {Ethereum: caller});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller, true);
+ let expectedTokenId = await contract.methods.nextTokenId().call();
+ let result = await contract.methods.mintCross(receiverCross, []).send();
+ let tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
+
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+
+ expectedTokenId = await contract.methods.nextTokenId().call();
+ result = await contract.methods.mintCross(receiverCross, properties).send();
+ tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
+
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+ .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ });
+
//TODO: CORE-302 add eth methods
itEth.skip('Can perform mintBulk()', async ({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -17,6 +17,7 @@
import {Pallets, requirePalletsOrSkip} from '../util';
import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
+import { ITokenPropertyPermission } from '../util/playgrounds/types';
describe('Refungible: Information getting', () => {
let donor: IKeyringPair;
@@ -135,6 +136,44 @@
expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
});
+
+ itEth('Can perform mintCross()', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
+ const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+ const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true}}; });
+
+
+ const collection = await helper.rft.mintCollection(minter, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: permissions,
+ });
+ await collection.addAdmin(minter, {Ethereum: caller});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller, true);
+ let expectedTokenId = await contract.methods.nextTokenId().call();
+ let result = await contract.methods.mintCross(receiverCross, []).send();
+ let tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
+
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+
+ expectedTokenId = await contract.methods.nextTokenId().call();
+ result = await contract.methods.mintCross(receiverCross, properties).send();
+ tokenId = result.events.Transfer.returnValues.tokenId;
+
+ expect(tokenId).to.be.equal(expectedTokenId);
+
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+ .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ });
itEth.skip('Can perform mintBulk()', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);