difftreelog
misk: remove simple type aliases
in: master
9 files changed
crates/evm-coder/src/events.rsdiffbeforeafterboth--- a/crates/evm-coder/src/events.rs
+++ b/crates/evm-coder/src/events.rs
@@ -61,7 +61,7 @@
}
}
-impl ToTopic for uint32 {
+impl ToTopic for u32 {
fn to_topic(&self) -> H256 {
let mut out = [0u8; 32];
out[28..32].copy_from_slice(&self.to_be_bytes());
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -132,11 +132,6 @@
use primitive_types::{U256, H160, H256};
pub type address = H160;
- pub type uint8 = u8;
- pub type uint16 = u16;
- pub type uint32 = u32;
- pub type uint64 = u64;
- pub type uint128 = u128;
pub type uint256 = U256;
pub type bytes4 = [u8; 4];
pub type topic = H256;
@@ -148,10 +143,6 @@
#[derive(Default, Debug, PartialEq, Eq, Clone)]
pub struct bytes(pub Vec<u8>);
-
- /// Solidity doesn't have `void` type, however we have special implementation
- /// for empty tuple return type
- pub type void = ();
//#region Special types
/// Makes function payable
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -93,12 +93,7 @@
/// @param value Propery value.
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
- fn set_collection_property(
- &mut self,
- caller: caller,
- key: string,
- value: bytes,
- ) -> Result<void> {
+ fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let key = <Vec<u8>>::from(key)
.try_into()
@@ -117,7 +112,7 @@
&mut self,
caller: caller,
properties: Vec<eth::Property>,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let properties = properties
@@ -212,7 +207,7 @@
///
/// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
#[solidity(hide)]
- fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {
+ fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -231,7 +226,7 @@
&mut self,
caller: caller,
sponsor: eth::CrossAddress,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -252,7 +247,7 @@
/// Collection sponsorship confirmation.
///
/// @dev After setting the sponsor for the collection, it must be confirmed with this function.
- fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {
+ fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -261,7 +256,7 @@
}
/// Remove collection sponsor.
- fn remove_collection_sponsor(&mut self, caller: caller) -> Result<void> {
+ fn remove_collection_sponsor(&mut self, caller: caller) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
let caller = T::CrossAccountId::from_eth(caller);
self.remove_sponsor(&caller).map_err(dispatch_to_evm::<T>)
@@ -343,11 +338,7 @@
/// @dev Throws error if limit not found.
/// @param limit Some limit.
#[solidity(rename_selector = "setCollectionLimit")]
- fn set_collection_limit(
- &mut self,
- caller: caller,
- limit: eth::CollectionLimit,
- ) -> Result<void> {
+ fn set_collection_limit(&mut self, caller: caller, limit: eth::CollectionLimit) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
if !limit.has_value() {
@@ -369,7 +360,7 @@
&mut self,
caller: caller,
new_admin: eth::CrossAddress,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -384,7 +375,7 @@
&mut self,
caller: caller,
admin: eth::CrossAddress,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -396,7 +387,7 @@
/// Add collection admin.
/// @param newAdmin Address of the added administrator.
#[solidity(hide)]
- fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<void> {
+ fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<()> {
self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -409,7 +400,7 @@
///
/// @param admin Address of the removed administrator.
#[solidity(hide)]
- fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<void> {
+ fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<()> {
self.consume_store_reads_and_writes(2, 2)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -422,7 +413,7 @@
///
/// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
#[solidity(rename_selector = "setCollectionNesting")]
- fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {
+ fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -446,7 +437,7 @@
caller: caller,
enable: bool,
collections: Vec<address>,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
if collections.is_empty() {
@@ -513,7 +504,7 @@
/// @param mode Access mode
/// 0 for Normal
/// 1 for AllowList
- fn set_collection_access(&mut self, caller: caller, mode: uint8) -> Result<void> {
+ fn set_collection_access(&mut self, caller: caller, mode: u8) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -540,7 +531,7 @@
///
/// @param user Address of a trusted user.
#[solidity(hide)]
- fn add_to_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {
+ fn add_to_collection_allow_list(&mut self, caller: caller, user: address) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -556,7 +547,7 @@
&mut self,
caller: caller,
user: eth::CrossAddress,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -569,7 +560,7 @@
///
/// @param user Address of a removed user.
#[solidity(hide)]
- fn remove_from_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {
+ fn remove_from_collection_allow_list(&mut self, caller: caller, user: address) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -585,7 +576,7 @@
&mut self,
caller: caller,
user: eth::CrossAddress,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -597,7 +588,7 @@
/// Switch permission for minting.
///
/// @param mode Enable if "true".
- fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {
+ fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<()> {
self.consume_store_reads_and_writes(1, 1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -654,7 +645,7 @@
/// @dev Owner can be changed only by current owner
/// @param newOwner new owner account
#[solidity(hide, rename_selector = "changeCollectionOwner")]
- fn set_owner(&mut self, caller: caller, new_owner: address) -> Result<void> {
+ fn set_owner(&mut self, caller: caller, new_owner: address) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
@@ -682,7 +673,7 @@
&mut self,
caller: caller,
new_owner: eth::CrossAddress,
- ) -> Result<void> {
+ ) -> Result<()> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -108,7 +108,7 @@
caller: caller,
contract_address: address,
sponsor: address,
- ) -> Result<void> {
+ ) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -125,7 +125,7 @@
/// Set contract as self sponsored.
///
/// @param contractAddress Contract for which a self sponsoring is being enabled.
- fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {
+ fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -146,7 +146,7 @@
/// Remove sponsor.
///
/// @param contractAddress Contract for which a sponsorship is being removed.
- fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {
+ fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -161,7 +161,7 @@
/// @dev Caller must be same that set via [`setSponsor`].
///
/// @param contractAddress Сontract for which need to confirm sponsorship.
- fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {
+ fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -210,7 +210,7 @@
caller: caller,
contract_address: address,
mode: SponsoringModeT,
- ) -> Result<void> {
+ ) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -223,7 +223,7 @@
/// Get current contract sponsoring rate limit
/// @param contractAddress Contract to get sponsoring rate limit of
/// @return uint32 Amount of blocks between two sponsored transactions
- fn sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {
+ fn sponsoring_rate_limit(&self, contract_address: address) -> Result<u32> {
self.recorder().consume_sload()?;
Ok(<SponsoringRateLimit<T>>::get(contract_address)
@@ -241,8 +241,8 @@
&mut self,
caller: caller,
contract_address: address,
- rate_limit: uint32,
- ) -> Result<void> {
+ rate_limit: u32,
+ ) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -262,7 +262,7 @@
caller: caller,
contract_address: address,
fee_limit: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -304,7 +304,7 @@
contract_address: address,
user: address,
is_allowed: bool,
- ) -> Result<void> {
+ ) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
@@ -332,7 +332,7 @@
caller: caller,
contract_address: address,
enabled: bool,
- ) -> Result<void> {
+ ) -> Result<()> {
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -72,7 +72,7 @@
Ok(<TotalSupply<T>>::get(self.id).into())
}
- fn decimals(&self) -> Result<uint8> {
+ fn decimals(&self) -> Result<u8> {
Ok(if let CollectionMode::Fungible(decimals) = &self.mode {
*decimals
} else {
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -423,7 +423,7 @@
_to: address,
_token_id: uint256,
_data: bytes,
- ) -> Result<void> {
+ ) -> Result<()> {
// TODO: Not implemetable
Err("not implemented".into())
}
@@ -433,7 +433,7 @@
_from: address,
_to: address,
_token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
// TODO: Not implemetable
Err("not implemented".into())
}
@@ -454,7 +454,7 @@
from: address,
to: address,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = T::CrossAccountId::from_eth(from);
let to = T::CrossAccountId::from_eth(to);
@@ -475,7 +475,7 @@
/// @param approved The new approved NFT controller
/// @param tokenId The NFT to approve
#[weight(<SelfWeightOf<T>>::approve())]
- fn approve(&mut self, caller: caller, approved: address, token_id: uint256) -> Result<void> {
+ fn approve(&mut self, caller: caller, approved: address, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let approved = T::CrossAccountId::from_eth(approved);
let token = token_id.try_into()?;
@@ -495,7 +495,7 @@
caller: caller,
operator: address,
approved: bool,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let operator = T::CrossAccountId::from_eth(operator);
@@ -528,7 +528,7 @@
/// operator of the current owner.
/// @param tokenId The NFT to approve
#[weight(<SelfWeightOf<T>>::burn_item())]
- fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {
+ fn burn(&mut self, caller: caller, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token = token_id.try_into()?;
@@ -773,7 +773,7 @@
caller: caller,
approved: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let approved = approved.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
@@ -789,7 +789,7 @@
/// @param to The new owner
/// @param tokenId The NFT to transfer
#[weight(<SelfWeightOf<T>>::transfer())]
- fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<void> {
+ fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let token = token_id.try_into()?;
@@ -812,7 +812,7 @@
caller: caller,
to: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
@@ -837,7 +837,7 @@
from: eth::CrossAddress,
to: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = from.into_sub_cross_account::<T>()?;
let to = to.into_sub_cross_account::<T>()?;
@@ -858,7 +858,7 @@
/// @param tokenId The NFT to transfer
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::burn_from())]
- fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<void> {
+ fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = T::CrossAccountId::from_eth(from);
let token = token_id.try_into()?;
@@ -883,7 +883,7 @@
caller: caller,
from: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = from.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -424,7 +424,7 @@
_to: address,
_token_id: uint256,
_data: bytes,
- ) -> Result<void> {
+ ) -> Result<()> {
// TODO: Not implemetable
Err("not implemented".into())
}
@@ -436,7 +436,7 @@
_from: address,
_to: address,
_token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
// TODO: Not implemetable
Err("not implemented".into())
}
@@ -458,7 +458,7 @@
from: address,
to: address,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = T::CrossAccountId::from_eth(from);
let to = T::CrossAccountId::from_eth(to);
@@ -477,7 +477,7 @@
}
/// @dev Not implemented
- fn approve(&mut self, _caller: caller, _approved: address, _token_id: uint256) -> Result<void> {
+ fn approve(&mut self, _caller: caller, _approved: address, _token_id: uint256) -> Result<()> {
Err("not implemented".into())
}
@@ -491,7 +491,7 @@
caller: caller,
operator: address,
approved: bool,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let operator = T::CrossAccountId::from_eth(operator);
@@ -556,7 +556,7 @@
/// operator of the current owner.
/// @param tokenId The RFT to approve
#[weight(<SelfWeightOf<T>>::burn_item_fully())]
- fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {
+ fn burn(&mut self, caller: caller, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token = token_id.try_into()?;
@@ -805,7 +805,7 @@
/// @param to The new owner
/// @param tokenId The RFT to transfer
#[weight(<SelfWeightOf<T>>::transfer_creating_removing())]
- fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<void> {
+ fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let to = T::CrossAccountId::from_eth(to);
let token = token_id.try_into()?;
@@ -833,7 +833,7 @@
caller: caller,
to: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
@@ -862,7 +862,7 @@
from: eth::CrossAddress,
to: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = from.into_sub_cross_account::<T>()?;
let to = to.into_sub_cross_account::<T>()?;
@@ -888,7 +888,7 @@
/// @param tokenId The RFT to transfer
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::burn_from())]
- fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<void> {
+ fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = T::CrossAccountId::from_eth(from);
let token = token_id.try_into()?;
@@ -917,7 +917,7 @@
caller: caller,
from: eth::CrossAddress,
token_id: uint256,
- ) -> Result<void> {
+ ) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let from = from.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
pallets/refungible/src/erc_token.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//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122use core::{23 char::{REPLACEMENT_CHARACTER, decode_utf16},24 convert::TryInto,25 ops::Deref,26};27use evm_coder::{28 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity_interface, solidity, types::*,29 weight,30};31use pallet_common::{32 CommonWeightInfo,33 erc::{CommonEvmHandler, PrecompileResult},34 eth::collection_id_to_address,35};36use pallet_evm::{account::CrossAccountId, PrecompileHandle};37use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};38use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};39use sp_std::vec::Vec;40use up_data_structs::TokenId;4142use crate::{43 Allowance, Balance, common::CommonWeights, Config, Pallet, RefungibleHandle, SelfWeightOf,44 TotalSupply, weights::WeightInfo,45};4647/// Refungible token handle contains information about token's collection and id48///49/// RefungibleTokenHandle doesn't check token's existance upon creation50pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);5152#[solidity_interface(name = ERC1633)]53impl<T: Config> RefungibleTokenHandle<T> {54 fn parent_token(&self) -> Result<address> {55 Ok(collection_id_to_address(self.id))56 }5758 fn parent_token_id(&self) -> Result<uint256> {59 Ok(self.1.into())60 }61}6263#[derive(ToLog)]64pub enum ERC20Events {65 /// @dev This event is emitted when the amount of tokens (value) is sent66 /// from the from address to the to address. In the case of minting new67 /// tokens, the transfer is usually from the 0 address while in the case68 /// of burning tokens the transfer is to 0.69 Transfer {70 #[indexed]71 from: address,72 #[indexed]73 to: address,74 value: uint256,75 },76 /// @dev This event is emitted when the amount of tokens (value) is approved77 /// by the owner to be used by the spender.78 Approval {79 #[indexed]80 owner: address,81 #[indexed]82 spender: address,83 value: uint256,84 },85}8687/// @title Standard ERC20 token88///89/// @dev Implementation of the basic standard token.90/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md91#[solidity_interface(name = ERC20, events(ERC20Events))]92impl<T: Config> RefungibleTokenHandle<T> {93 /// @return the name of the token.94 fn name(&self) -> Result<string> {95 Ok(decode_utf16(self.name.iter().copied())96 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))97 .collect::<string>())98 }99100 /// @return the symbol of the token.101 fn symbol(&self) -> Result<string> {102 Ok(string::from_utf8_lossy(&self.token_prefix).into())103 }104105 /// @dev Total number of tokens in existence106 fn total_supply(&self) -> Result<uint256> {107 self.consume_store_reads(1)?;108 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())109 }110111 /// @dev Not supported112 fn decimals(&self) -> Result<uint8> {113 // Decimals aren't supported for refungible tokens114 Ok(0)115 }116117 /// @dev Gets the balance of the specified address.118 /// @param owner The address to query the balance of.119 /// @return An uint256 representing the amount owned by the passed address.120 fn balance_of(&self, owner: address) -> Result<uint256> {121 self.consume_store_reads(1)?;122 let owner = T::CrossAccountId::from_eth(owner);123 let balance = <Balance<T>>::get((self.id, self.1, owner));124 Ok(balance.into())125 }126127 /// @dev Transfer token for a specified address128 /// @param to The address to transfer to.129 /// @param amount The amount to be transferred.130 #[weight(<CommonWeights<T>>::transfer())]131 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {132 let caller = T::CrossAccountId::from_eth(caller);133 let to = T::CrossAccountId::from_eth(to);134 let amount = amount.try_into().map_err(|_| "amount overflow")?;135 let budget = self136 .recorder137 .weight_calls_budget(<StructureWeight<T>>::find_parent());138139 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)140 .map_err(dispatch_to_evm::<T>)?;141 Ok(true)142 }143144 /// @dev Transfer tokens from one address to another145 /// @param from address The address which you want to send tokens from146 /// @param to address The address which you want to transfer to147 /// @param amount uint256 the amount of tokens to be transferred148 #[weight(<CommonWeights<T>>::transfer_from())]149 fn transfer_from(150 &mut self,151 caller: caller,152 from: address,153 to: address,154 amount: uint256,155 ) -> Result<bool> {156 let caller = T::CrossAccountId::from_eth(caller);157 let from = T::CrossAccountId::from_eth(from);158 let to = T::CrossAccountId::from_eth(to);159 let amount = amount.try_into().map_err(|_| "amount overflow")?;160 let budget = self161 .recorder162 .weight_calls_budget(<StructureWeight<T>>::find_parent());163164 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)165 .map_err(dispatch_to_evm::<T>)?;166 Ok(true)167 }168169 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.170 /// Beware that changing an allowance with this method brings the risk that someone may use both the old171 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this172 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:173 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729174 /// @param spender The address which will spend the funds.175 /// @param amount The amount of tokens to be spent.176 #[weight(<SelfWeightOf<T>>::approve())]177 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {178 let caller = T::CrossAccountId::from_eth(caller);179 let spender = T::CrossAccountId::from_eth(spender);180 let amount = amount.try_into().map_err(|_| "amount overflow")?;181182 <Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)183 .map_err(dispatch_to_evm::<T>)?;184 Ok(true)185 }186187 /// @dev Function to check the amount of tokens that an owner allowed to a spender.188 /// @param owner address The address which owns the funds.189 /// @param spender address The address which will spend the funds.190 /// @return A uint256 specifying the amount of tokens still available for the spender.191 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {192 self.consume_store_reads(1)?;193 let owner = T::CrossAccountId::from_eth(owner);194 let spender = T::CrossAccountId::from_eth(spender);195196 Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())197 }198}199200#[solidity_interface(name = ERC20UniqueExtensions)]201impl<T: Config> RefungibleTokenHandle<T>202where203 T::AccountId: From<[u8; 32]>,204{205 /// @dev Function that burns an amount of the token of a given account,206 /// deducting from the sender's allowance for said account.207 /// @param from The account whose tokens will be burnt.208 /// @param amount The amount that will be burnt.209 #[weight(<SelfWeightOf<T>>::burn_from())]210 #[solidity(hide)]211 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {212 let caller = T::CrossAccountId::from_eth(caller);213 let from = T::CrossAccountId::from_eth(from);214 let amount = amount.try_into().map_err(|_| "amount overflow")?;215 let budget = self216 .recorder217 .weight_calls_budget(<StructureWeight<T>>::find_parent());218219 <Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)220 .map_err(dispatch_to_evm::<T>)?;221 Ok(true)222 }223224 /// @dev Function that burns an amount of the token of a given account,225 /// deducting from the sender's allowance for said account.226 /// @param from The account whose tokens will be burnt.227 /// @param amount The amount that will be burnt.228 #[weight(<SelfWeightOf<T>>::burn_from())]229 fn burn_from_cross(230 &mut self,231 caller: caller,232 from: pallet_common::eth::CrossAddress,233 amount: uint256,234 ) -> Result<bool> {235 let caller = T::CrossAccountId::from_eth(caller);236 let from = from.into_sub_cross_account::<T>()?;237 let amount = amount.try_into().map_err(|_| "amount overflow")?;238 let budget = self239 .recorder240 .weight_calls_budget(<StructureWeight<T>>::find_parent());241242 <Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)243 .map_err(dispatch_to_evm::<T>)?;244 Ok(true)245 }246247 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.248 /// Beware that changing an allowance with this method brings the risk that someone may use both the old249 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this250 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:251 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729252 /// @param spender The crossaccount which will spend the funds.253 /// @param amount The amount of tokens to be spent.254 #[weight(<SelfWeightOf<T>>::approve())]255 fn approve_cross(256 &mut self,257 caller: caller,258 spender: pallet_common::eth::CrossAddress,259 amount: uint256,260 ) -> Result<bool> {261 let caller = T::CrossAccountId::from_eth(caller);262 let spender = spender.into_sub_cross_account::<T>()?;263 let amount = amount.try_into().map_err(|_| "amount overflow")?;264265 <Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)266 .map_err(dispatch_to_evm::<T>)?;267 Ok(true)268 }269 /// @dev Function that changes total amount of the tokens.270 /// Throws if `msg.sender` doesn't owns all of the tokens.271 /// @param amount New total amount of the tokens.272 #[weight(<SelfWeightOf<T>>::repartition_item())]273 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {274 let caller = T::CrossAccountId::from_eth(caller);275 let amount = amount.try_into().map_err(|_| "amount overflow")?;276277 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;278 Ok(true)279 }280281 /// @dev Transfer token for a specified address282 /// @param to The crossaccount to transfer to.283 /// @param amount The amount to be transferred.284 #[weight(<CommonWeights<T>>::transfer())]285 fn transfer_cross(286 &mut self,287 caller: caller,288 to: pallet_common::eth::CrossAddress,289 amount: uint256,290 ) -> Result<bool> {291 let caller = T::CrossAccountId::from_eth(caller);292 let to = to.into_sub_cross_account::<T>()?;293 let amount = amount.try_into().map_err(|_| "amount overflow")?;294 let budget = self295 .recorder296 .weight_calls_budget(<StructureWeight<T>>::find_parent());297298 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)299 .map_err(dispatch_to_evm::<T>)?;300 Ok(true)301 }302303 /// @dev Transfer tokens from one address to another304 /// @param from The address which you want to send tokens from305 /// @param to The address which you want to transfer to306 /// @param amount the amount of tokens to be transferred307 #[weight(<CommonWeights<T>>::transfer_from())]308 fn transfer_from_cross(309 &mut self,310 caller: caller,311 from: pallet_common::eth::CrossAddress,312 to: pallet_common::eth::CrossAddress,313 amount: uint256,314 ) -> Result<bool> {315 let caller = T::CrossAccountId::from_eth(caller);316 let from = from.into_sub_cross_account::<T>()?;317 let to = to.into_sub_cross_account::<T>()?;318 let amount = amount.try_into().map_err(|_| "amount overflow")?;319 let budget = self320 .recorder321 .weight_calls_budget(<StructureWeight<T>>::find_parent());322323 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)324 .map_err(dispatch_to_evm::<T>)?;325 Ok(true)326 }327}328329impl<T: Config> RefungibleTokenHandle<T> {330 pub fn into_inner(self) -> RefungibleHandle<T> {331 self.0332 }333 pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {334 &mut self.0335 }336}337338impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {339 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {340 self.0.recorder()341 }342 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {343 self.0.into_recorder()344 }345}346347impl<T: Config> Deref for RefungibleTokenHandle<T> {348 type Target = RefungibleHandle<T>;349350 fn deref(&self) -> &Self::Target {351 &self.0352 }353}354355#[solidity_interface(356 name = UniqueRefungibleToken,357 is(ERC20, ERC20UniqueExtensions, ERC1633)358)]359impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}360361generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);362generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);363364impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>365where366 T::AccountId: From<[u8; 32]>,367{368 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");369370 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {371 call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)372 }373}pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -231,7 +231,7 @@
caller: caller,
value: value,
name: string,
- decimals: uint8,
+ decimals: u8,
description: string,
token_prefix: string,
) -> Result<address> {
@@ -334,7 +334,7 @@
}
#[weight(<SelfWeightOf<T>>::destroy_collection())]
- fn destroy_collection(&mut self, caller: caller, collection_address: address) -> Result<void> {
+ fn destroy_collection(&mut self, caller: caller, collection_address: address) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)
@@ -366,14 +366,14 @@
/// Returns address of a collection.
/// @param collectionId - CollectionId of the collection
/// @return eth mirror address of the collection
- fn collection_address(&self, collection_id: uint32) -> Result<address> {
+ fn collection_address(&self, collection_id: u32) -> Result<address> {
Ok(collection_id_to_address(collection_id.into()))
}
/// Returns collectionId of a collection.
/// @param collectionAddress - Eth address of the collection
/// @return collectionId of the collection
- fn collection_id(&self, collection_address: address) -> Result<uint32> {
+ fn collection_id(&self, collection_address: address) -> Result<u32> {
map_eth_to_id(&collection_address)
.map(|id| id.0)
.ok_or(Error::Revert(format!(