difftreelog
Merge pull request #827 from UniqueNetwork/fix/frontier-get-code
in: master
Fix eth_getCode
15 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2467,7 +2467,7 @@
[[package]]
name = "fc-consensus"
version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"async-trait",
"fc-db",
@@ -2486,7 +2486,7 @@
[[package]]
name = "fc-db"
version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"fp-storage",
"kvdb-rocksdb",
@@ -2505,7 +2505,7 @@
[[package]]
name = "fc-mapping-sync"
version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"fc-db",
"fp-consensus",
@@ -2522,7 +2522,7 @@
[[package]]
name = "fc-rpc"
version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"ethereum-types 0.14.1",
@@ -2565,7 +2565,7 @@
[[package]]
name = "fc-rpc-core"
version = "1.1.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"ethereum-types 0.14.1",
@@ -2730,7 +2730,7 @@
[[package]]
name = "fp-consensus"
version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"parity-scale-codec 3.2.1",
@@ -2742,7 +2742,7 @@
[[package]]
name = "fp-ethereum"
version = "1.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"ethereum-types 0.14.1",
@@ -2757,7 +2757,7 @@
[[package]]
name = "fp-evm"
version = "3.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"evm",
"frame-support",
@@ -2771,7 +2771,7 @@
[[package]]
name = "fp-evm-mapping"
version = "0.1.0"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"frame-support",
"sp-core",
@@ -2780,7 +2780,7 @@
[[package]]
name = "fp-rpc"
version = "3.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"ethereum-types 0.14.1",
@@ -2797,7 +2797,7 @@
[[package]]
name = "fp-self-contained"
version = "1.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"frame-support",
@@ -2810,7 +2810,7 @@
[[package]]
name = "fp-storage"
version = "2.0.0"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"parity-scale-codec 3.2.1",
"serde",
@@ -5687,7 +5687,7 @@
[[package]]
name = "pallet-base-fee"
version = "1.0.0"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"fp-evm",
"frame-support",
@@ -5952,7 +5952,7 @@
[[package]]
name = "pallet-ethereum"
version = "4.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"ethereum 0.14.0",
"ethereum-types 0.14.1",
@@ -5980,7 +5980,7 @@
[[package]]
name = "pallet-evm"
version = "6.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"environmental",
"evm",
@@ -6066,7 +6066,7 @@
[[package]]
name = "pallet-evm-precompile-simple"
version = "2.0.0-dev"
-source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#cf1894629c7df1c4dafe58aa773627a3d940da14"
+source = "git+https://github.com/uniquenetwork/frontier?branch=unique-polkadot-v0.9.36#ef8d2809ed05da0664e9b43cb87436451295b634"
dependencies = [
"fp-evm",
"ripemd",
crates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/solidity_interface.rs
+++ b/crates/evm-coder/procedural/src/solidity_interface.rs
@@ -811,6 +811,13 @@
let list = generics_list(gen);
quote! { <#list> }
}
+fn generics_stub(gen: &Generics) -> proc_macro2::TokenStream {
+ if gen.params.is_empty() {
+ return quote! {};
+ }
+ let params = (0..gen.params.len()).map(|_| quote! {()});
+ quote! {<#(#params,)*>}
+}
fn generics_data(gen: &Generics) -> proc_macro2::TokenStream {
let list = generics_list(gen);
if gen.params.len() == 1 {
@@ -866,6 +873,7 @@
let generics = self.generics;
let gen_ref = generics_reference(&generics);
let gen_data = generics_data(&generics);
+ let gen_stub = generics_stub(&generics);
let gen_where = &generics.where_clause;
let call_sub = self
@@ -936,6 +944,12 @@
let solidity_events_idents = self.info.events.0.iter().map(|is| is.name.clone());
let docs = &self.docs;
+ let expect_selector = self.info.expect_selector.map(|s| {
+ quote! {
+ const _: () = assert!(#s == u32::from_be_bytes(<#call_name #gen_stub>::interface_id()), "selector mismatch, review contained function selectors");
+ }
+ });
+
quote! {
#(
const _: ::core::marker::PhantomData<#solidity_events_idents> = ::core::marker::PhantomData;
@@ -952,12 +966,15 @@
#call_sub,
)*
}
+
+ #expect_selector
+
impl #gen_ref #call_name #gen_ref {
#(
#consts
)*
/// Return this call ERC165 selector
- pub fn interface_id() -> ::evm_coder::types::bytes4 {
+ pub const fn interface_id() -> ::evm_coder::types::bytes4 {
let mut interface_id = 0;
#(#interface_id)*
#(#inline_interface_id)*
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -524,11 +524,6 @@
Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))
}
-
- /// @notice Returns collection helper contract address
- fn collection_helper_address(&self) -> Result<address> {
- Ok(T::ContractAddress::get())
- }
}
/// @title ERC721 Token that can be irreversibly burned (destroyed).
@@ -1058,6 +1053,11 @@
Ok(token_id.into())
}
+
+ /// @notice Returns collection helper contract address
+ fn collection_helper_address(&self) -> Result<address> {
+ Ok(T::ContractAddress::get())
+ }
}
#[solidity_interface(
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -785,7 +785,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x0e48fdb4
+/// @dev the ERC-165 identifier for this interface is 0x16de3152
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,
@@ -986,6 +986,15 @@
dummy = 0;
return 0;
}
+
+ /// @notice Returns collection helper contract address
+ /// @dev EVM selector for this function is: 0x1896cce6,
+ /// or in textual repr: collectionHelperAddress()
+ function collectionHelperAddress() public view returns (address) {
+ require(false, stub_error);
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
}
/// @dev anonymous struct
@@ -1043,7 +1052,7 @@
/// @title ERC-721 Non-Fungible Token Standard
/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
-/// @dev the ERC-165 identifier for this interface is 0x983a942b
+/// @dev the ERC-165 identifier for this interface is 0x80ac58cd
contract ERC721 is Dummy, ERC165, ERC721Events {
/// @notice Count all NFTs assigned to an owner
/// @dev NFTs assigned to the zero address are considered invalid, and this
@@ -1175,15 +1184,6 @@
operator;
dummy;
return false;
- }
-
- /// @notice Returns collection helper contract address
- /// @dev EVM selector for this function is: 0x1896cce6,
- /// or in textual repr: collectionHelperAddress()
- function collectionHelperAddress() public view returns (address) {
- require(false, stub_error);
- dummy;
- return 0x0000000000000000000000000000000000000000;
}
}
pallets/refungible/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//! # Refungible Pallet EVM API for tokens18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Refungible Pallet methods.2122extern crate alloc;2324use core::{25 char::{REPLACEMENT_CHARACTER, decode_utf16},26 convert::TryInto,27};28use evm_coder::{29 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,30 weight,31};32use frame_support::{BoundedBTreeMap, BoundedVec};33use pallet_common::{34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,35 Error as CommonError,36 erc::{CommonEvmHandler, CollectionCall, static_property::key},37 eth,38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};42use sp_core::{H160, Get};43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};44use up_data_structs::{45 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,46 PropertyKeyPermission, PropertyPermission, TokenId,47};4849use crate::{50 AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,51 TokenProperties, TokensMinted, TotalSupply, weights::WeightInfo,52};5354pub const ADDRESS_FOR_PARTIALLY_OWNED_TOKENS: H160 = H160::repeat_byte(0xff);5556/// @title A contract that allows to set and delete token properties and change token property permissions.57#[solidity_interface(name = TokenProperties)]58impl<T: Config> RefungibleHandle<T> {59 /// @notice Set permissions for token property.60 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.61 /// @param key Property key.62 /// @param isMutable Permission to mutate property.63 /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.64 /// @param tokenOwner Permission to mutate property by token owner if property is mutable.65 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(1))]66 #[solidity(hide)]67 fn set_token_property_permission(68 &mut self,69 caller: caller,70 key: string,71 is_mutable: bool,72 collection_admin: bool,73 token_owner: bool,74 ) -> Result<()> {75 let caller = T::CrossAccountId::from_eth(caller);76 <Pallet<T>>::set_token_property_permissions(77 self,78 &caller,79 vec![PropertyKeyPermission {80 key: <Vec<u8>>::from(key)81 .try_into()82 .map_err(|_| "too long key")?,83 permission: PropertyPermission {84 mutable: is_mutable,85 collection_admin,86 token_owner,87 },88 }],89 )90 .map_err(dispatch_to_evm::<T>)91 }9293 /// @notice Set permissions for token property.94 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.95 /// @param permissions Permissions for keys.96 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(permissions.len() as u32))]97 fn set_token_property_permissions(98 &mut self,99 caller: caller,100 permissions: Vec<eth::TokenPropertyPermission>,101 ) -> Result<()> {102 let caller = T::CrossAccountId::from_eth(caller);103 let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;104105 <Pallet<T>>::set_token_property_permissions(self, &caller, perms)106 .map_err(dispatch_to_evm::<T>)107 }108109 /// @notice Get permissions for token properties.110 fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {111 let perms = <Pallet<T>>::token_property_permission(self.id);112 Ok(perms113 .into_iter()114 .map(eth::TokenPropertyPermission::from)115 .collect())116 }117118 /// @notice Set token property value.119 /// @dev Throws error if `msg.sender` has no permission to edit the property.120 /// @param tokenId ID of the token.121 /// @param key Property key.122 /// @param value Property value.123 #[solidity(hide)]124 #[weight(<SelfWeightOf<T>>::set_token_properties(1))]125 fn set_property(126 &mut self,127 caller: caller,128 token_id: uint256,129 key: string,130 value: bytes,131 ) -> Result<()> {132 let caller = T::CrossAccountId::from_eth(caller);133 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;134 let key = <Vec<u8>>::from(key)135 .try_into()136 .map_err(|_| "key too long")?;137 let value = value.0.try_into().map_err(|_| "value too long")?;138139 let nesting_budget = self140 .recorder141 .weight_calls_budget(<StructureWeight<T>>::find_parent());142143 <Pallet<T>>::set_token_property(144 self,145 &caller,146 TokenId(token_id),147 Property { key, value },148 &nesting_budget,149 )150 .map_err(dispatch_to_evm::<T>)151 }152153 /// @notice Set token properties value.154 /// @dev Throws error if `msg.sender` has no permission to edit the property.155 /// @param tokenId ID of the token.156 /// @param properties settable properties157 #[weight(<SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]158 fn set_properties(159 &mut self,160 caller: caller,161 token_id: uint256,162 properties: Vec<eth::Property>,163 ) -> Result<()> {164 let caller = T::CrossAccountId::from_eth(caller);165 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;166167 let nesting_budget = self168 .recorder169 .weight_calls_budget(<StructureWeight<T>>::find_parent());170171 let properties = properties172 .into_iter()173 .map(eth::Property::try_into)174 .collect::<Result<Vec<_>>>()?;175176 <Pallet<T>>::set_token_properties(177 self,178 &caller,179 TokenId(token_id),180 properties.into_iter(),181 false,182 &nesting_budget,183 )184 .map_err(dispatch_to_evm::<T>)185 }186187 /// @notice Delete token property value.188 /// @dev Throws error if `msg.sender` has no permission to edit the property.189 /// @param tokenId ID of the token.190 /// @param key Property key.191 #[solidity(hide)]192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]193 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {194 let caller = T::CrossAccountId::from_eth(caller);195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;196 let key = <Vec<u8>>::from(key)197 .try_into()198 .map_err(|_| "key too long")?;199200 let nesting_budget = self201 .recorder202 .weight_calls_budget(<StructureWeight<T>>::find_parent());203204 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)205 .map_err(dispatch_to_evm::<T>)206 }207208 /// @notice Delete token properties value.209 /// @dev Throws error if `msg.sender` has no permission to edit the property.210 /// @param tokenId ID of the token.211 /// @param keys Properties key.212 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]213 fn delete_properties(214 &mut self,215 token_id: uint256,216 caller: caller,217 keys: Vec<string>,218 ) -> Result<()> {219 let caller = T::CrossAccountId::from_eth(caller);220 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;221 let keys = keys222 .into_iter()223 .map(|k| Ok(<Vec<u8>>::from(k).try_into().map_err(|_| "key too long")?))224 .collect::<Result<Vec<_>>>()?;225226 let nesting_budget = self227 .recorder228 .weight_calls_budget(<StructureWeight<T>>::find_parent());229230 <Pallet<T>>::delete_token_properties(231 self,232 &caller,233 TokenId(token_id),234 keys.into_iter(),235 &nesting_budget,236 )237 .map_err(dispatch_to_evm::<T>)238 }239240 /// @notice Get token property value.241 /// @dev Throws error if key not found242 /// @param tokenId ID of the token.243 /// @param key Property key.244 /// @return Property value bytes245 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;247 let key = <Vec<u8>>::from(key)248 .try_into()249 .map_err(|_| "key too long")?;250251 let props = <TokenProperties<T>>::get((self.id, token_id));252 let prop = props.get(&key).ok_or("key not found")?;253254 Ok(prop.to_vec().into())255 }256}257258#[derive(ToLog)]259pub enum ERC721Events {260 /// @dev This event emits when NFTs are created (`from` == 0) and destroyed261 /// (`to` == 0). Exception: during contract creation, any number of RFTs262 /// may be created and assigned without emitting Transfer.263 Transfer {264 #[indexed]265 from: address,266 #[indexed]267 to: address,268 #[indexed]269 token_id: uint256,270 },271 /// @dev Not supported272 Approval {273 #[indexed]274 owner: address,275 #[indexed]276 approved: address,277 #[indexed]278 token_id: uint256,279 },280 /// @dev Not supported281 #[allow(dead_code)]282 ApprovalForAll {283 #[indexed]284 owner: address,285 #[indexed]286 operator: address,287 approved: bool,288 },289}290291#[derive(ToLog)]292pub enum ERC721UniqueMintableEvents {293 /// @dev Not supported294 #[allow(dead_code)]295 MintingFinished {},296}297298/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension299/// @dev See https://eips.ethereum.org/EIPS/eip-721300#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f)]301impl<T: Config> RefungibleHandle<T>302where303 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,304{305 /// @notice A descriptive name for a collection of NFTs in this contract306 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`307 #[solidity(hide, rename_selector = "name")]308 fn name_proxy(&self) -> Result<string> {309 self.name()310 }311312 /// @notice An abbreviated name for NFTs in this contract313 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`314 #[solidity(hide, rename_selector = "symbol")]315 fn symbol_proxy(&self) -> Result<string> {316 self.symbol()317 }318319 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.320 ///321 /// @dev If the token has a `url` property and it is not empty, it is returned.322 /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.323 /// If the collection property `baseURI` is empty or absent, return "" (empty string)324 /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix325 /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).326 ///327 /// @return token's const_metadata328 #[solidity(rename_selector = "tokenURI")]329 fn token_uri(&self, token_id: uint256) -> Result<string> {330 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;331332 match get_token_property(self, token_id_u32, &key::url()).as_deref() {333 Err(_) | Ok("") => (),334 Ok(url) => {335 return Ok(url.into());336 }337 };338339 let base_uri =340 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())341 .map(BoundedVec::into_inner)342 .map(string::from_utf8)343 .transpose()344 .map_err(|e| {345 Error::Revert(alloc::format!(346 "Can not convert value \"baseURI\" to string with error \"{}\"",347 e348 ))349 })?;350351 let base_uri = match base_uri.as_deref() {352 None | Some("") => {353 return Ok("".into());354 }355 Some(base_uri) => base_uri.into(),356 };357358 Ok(359 match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {360 Err(_) | Ok("") => base_uri,361 Ok(suffix) => base_uri + suffix,362 },363 )364 }365}366367/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension368/// @dev See https://eips.ethereum.org/EIPS/eip-721369#[solidity_interface(name = ERC721Enumerable, expect_selector = 0x780e9d63)]370impl<T: Config> RefungibleHandle<T> {371 /// @notice Enumerate valid RFTs372 /// @param index A counter less than `totalSupply()`373 /// @return The token identifier for the `index`th NFT,374 /// (sort order not specified)375 fn token_by_index(&self, index: uint256) -> Result<uint256> {376 Ok(index)377 }378379 /// Not implemented380 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {381 // TODO: Not implemetable382 Err("not implemented".into())383 }384385 /// @notice Count RFTs tracked by this contract386 /// @return A count of valid RFTs tracked by this contract, where each one of387 /// them has an assigned and queryable owner not equal to the zero address388 fn total_supply(&self) -> Result<uint256> {389 self.consume_store_reads(1)?;390 Ok(<Pallet<T>>::total_supply(self).into())391 }392}393394/// @title ERC-721 Non-Fungible Token Standard395/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md396#[solidity_interface(name = ERC721, events(ERC721Events), expect_selector = 0x80ac58cd)]397impl<T: Config> RefungibleHandle<T> {398 /// @notice Count all RFTs assigned to an owner399 /// @dev RFTs assigned to the zero address are considered invalid, and this400 /// function throws for queries about the zero address.401 /// @param owner An address for whom to query the balance402 /// @return The number of RFTs owned by `owner`, possibly zero403 fn balance_of(&self, owner: address) -> Result<uint256> {404 self.consume_store_reads(1)?;405 let owner = T::CrossAccountId::from_eth(owner);406 let balance = <AccountBalance<T>>::get((self.id, owner));407 Ok(balance.into())408 }409410 /// @notice Find the owner of an RFT411 /// @dev RFTs assigned to zero address are considered invalid, and queries412 /// about them do throw.413 /// Returns special 0xffffffffffffffffffffffffffffffffffffffff address for414 /// the tokens that are partially owned.415 /// @param tokenId The identifier for an RFT416 /// @return The address of the owner of the RFT417 fn owner_of(&self, token_id: uint256) -> Result<address> {418 self.consume_store_reads(2)?;419 let token = token_id.try_into()?;420 let owner = <Pallet<T>>::token_owner(self.id, token);421 Ok(owner422 .map(|address| *address.as_eth())423 .unwrap_or_else(|| ADDRESS_FOR_PARTIALLY_OWNED_TOKENS))424 }425426 /// @dev Not implemented427 #[solidity(rename_selector = "safeTransferFrom")]428 fn safe_transfer_from_with_data(429 &mut self,430 _from: address,431 _to: address,432 _token_id: uint256,433 _data: bytes,434 ) -> Result<void> {435 // TODO: Not implemetable436 Err("not implemented".into())437 }438439 /// @dev Not implemented440 #[solidity(rename_selector = "safeTransferFrom")]441 fn safe_transfer_from(442 &mut self,443 _from: address,444 _to: address,445 _token_id: uint256,446 ) -> Result<void> {447 // TODO: Not implemetable448 Err("not implemented".into())449 }450451 /// @notice Transfer ownership of an RFT -- THE CALLER IS RESPONSIBLE452 /// TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE453 /// THEY MAY BE PERMANENTLY LOST454 /// @dev Throws unless `msg.sender` is the current owner or an authorized455 /// operator for this RFT. Throws if `from` is not the current owner. Throws456 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.457 /// Throws if RFT pieces have multiple owners.458 /// @param from The current owner of the NFT459 /// @param to The new owner460 /// @param tokenId The NFT to transfer461 #[weight(<SelfWeightOf<T>>::transfer_from_creating_removing())]462 fn transfer_from(463 &mut self,464 caller: caller,465 from: address,466 to: address,467 token_id: uint256,468 ) -> Result<void> {469 let caller = T::CrossAccountId::from_eth(caller);470 let from = T::CrossAccountId::from_eth(from);471 let to = T::CrossAccountId::from_eth(to);472 let token = token_id.try_into()?;473 let budget = self474 .recorder475 .weight_calls_budget(<StructureWeight<T>>::find_parent());476477 let balance = balance(&self, token, &from)?;478 ensure_single_owner(&self, token, balance)?;479480 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token, balance, &budget)481 .map_err(dispatch_to_evm::<T>)?;482483 Ok(())484 }485486 /// @dev Not implemented487 fn approve(&mut self, _caller: caller, _approved: address, _token_id: uint256) -> Result<void> {488 Err("not implemented".into())489 }490491 /// @notice Sets or unsets the approval of a given operator.492 /// The `operator` is allowed to transfer all token pieces of the `caller` on their behalf.493 /// @param operator Operator494 /// @param approved Should operator status be granted or revoked?495 #[weight(<SelfWeightOf<T>>::set_allowance_for_all())]496 fn set_approval_for_all(497 &mut self,498 caller: caller,499 operator: address,500 approved: bool,501 ) -> Result<void> {502 let caller = T::CrossAccountId::from_eth(caller);503 let operator = T::CrossAccountId::from_eth(operator);504505 <Pallet<T>>::set_allowance_for_all(self, &caller, &operator, approved)506 .map_err(dispatch_to_evm::<T>)?;507 Ok(())508 }509510 /// @dev Not implemented511 fn get_approved(&self, _token_id: uint256) -> Result<address> {512 // TODO: Not implemetable513 Err("not implemented".into())514 }515516 /// @notice Tells whether the given `owner` approves the `operator`.517 #[weight(<SelfWeightOf<T>>::allowance_for_all())]518 fn is_approved_for_all(&self, owner: address, operator: address) -> Result<bool> {519 let owner = T::CrossAccountId::from_eth(owner);520 let operator = T::CrossAccountId::from_eth(operator);521522 Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))523 }524}525526/// Returns amount of pieces of `token` that `owner` have527pub fn balance<T: Config>(528 collection: &RefungibleHandle<T>,529 token: TokenId,530 owner: &T::CrossAccountId,531) -> Result<u128> {532 collection.consume_store_reads(1)?;533 let balance = <Balance<T>>::get((collection.id, token, &owner));534 Ok(balance)535}536537/// Throws if `owner_balance` is lower than total amount of `token` pieces538pub fn ensure_single_owner<T: Config>(539 collection: &RefungibleHandle<T>,540 token: TokenId,541 owner_balance: u128,542) -> Result<()> {543 collection.consume_store_reads(1)?;544 let total_supply = <TotalSupply<T>>::get((collection.id, token));545546 if owner_balance == 0 {547 return Err(dispatch_to_evm::<T>(548 <CommonError<T>>::MustBeTokenOwner.into(),549 ));550 }551552 if total_supply != owner_balance {553 return Err("token has multiple owners".into());554 }555 Ok(())556}557558/// @title ERC721 Token that can be irreversibly burned (destroyed).559#[solidity_interface(name = ERC721Burnable)]560impl<T: Config> RefungibleHandle<T> {561 /// @notice Burns a specific ERC721 token.562 /// @dev Throws unless `msg.sender` is the current RFT owner, or an authorized563 /// operator of the current owner.564 /// @param tokenId The RFT to approve565 #[weight(<SelfWeightOf<T>>::burn_item_fully())]566 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {567 let caller = T::CrossAccountId::from_eth(caller);568 let token = token_id.try_into()?;569570 let balance = balance(&self, token, &caller)?;571 ensure_single_owner(&self, token, balance)?;572573 <Pallet<T>>::burn(self, &caller, token, balance).map_err(dispatch_to_evm::<T>)?;574 Ok(())575 }576}577578/// @title ERC721 minting logic.579#[solidity_interface(name = ERC721UniqueMintable, events(ERC721UniqueMintableEvents))]580impl<T: Config> RefungibleHandle<T> {581 fn minting_finished(&self) -> Result<bool> {582 Ok(false)583 }584585 /// @notice Function to mint a token.586 /// @param to The new owner587 /// @return uint256 The id of the newly minted token588 #[weight(<SelfWeightOf<T>>::create_item())]589 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {590 let token_id: uint256 = <TokensMinted<T>>::get(self.id)591 .checked_add(1)592 .ok_or("item id overflow")?593 .into();594 self.mint_check_id(caller, to, token_id)?;595 Ok(token_id)596 }597598 /// @notice Function to mint a token.599 /// @dev `tokenId` should be obtained with `nextTokenId` method,600 /// unlike standard, you can't specify it manually601 /// @param to The new owner602 /// @param tokenId ID of the minted RFT603 #[solidity(hide, rename_selector = "mint")]604 #[weight(<SelfWeightOf<T>>::create_item())]605 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {606 let caller = T::CrossAccountId::from_eth(caller);607 let to = T::CrossAccountId::from_eth(to);608 let token_id: u32 = token_id.try_into()?;609 let budget = self610 .recorder611 .weight_calls_budget(<StructureWeight<T>>::find_parent());612613 if <TokensMinted<T>>::get(self.id)614 .checked_add(1)615 .ok_or("item id overflow")?616 != token_id617 {618 return Err("item id should be next".into());619 }620621 let users = [(to.clone(), 1)]622 .into_iter()623 .collect::<BTreeMap<_, _>>()624 .try_into()625 .unwrap();626 <Pallet<T>>::create_item(627 self,628 &caller,629 CreateItemData::<T> {630 users,631 properties: CollectionPropertiesVec::default(),632 },633 &budget,634 )635 .map_err(dispatch_to_evm::<T>)?;636637 Ok(true)638 }639640 /// @notice Function to mint token with the given tokenUri.641 /// @param to The new owner642 /// @param tokenUri Token URI that would be stored in the NFT properties643 /// @return uint256 The id of the newly minted token644 #[solidity(rename_selector = "mintWithTokenURI")]645 #[weight(<SelfWeightOf<T>>::create_item())]646 fn mint_with_token_uri(647 &mut self,648 caller: caller,649 to: address,650 token_uri: string,651 ) -> Result<uint256> {652 let token_id: uint256 = <TokensMinted<T>>::get(self.id)653 .checked_add(1)654 .ok_or("item id overflow")?655 .into();656 self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;657 Ok(token_id)658 }659660 /// @notice Function to mint token with the given tokenUri.661 /// @dev `tokenId` should be obtained with `nextTokenId` method,662 /// unlike standard, you can't specify it manually663 /// @param to The new owner664 /// @param tokenId ID of the minted RFT665 /// @param tokenUri Token URI that would be stored in the RFT properties666 #[solidity(hide, rename_selector = "mintWithTokenURI")]667 #[weight(<SelfWeightOf<T>>::create_item())]668 fn mint_with_token_uri_check_id(669 &mut self,670 caller: caller,671 to: address,672 token_id: uint256,673 token_uri: string,674 ) -> Result<bool> {675 let key = key::url();676 let permission = get_token_permission::<T>(self.id, &key)?;677 if !permission.collection_admin {678 return Err("Operation is not allowed".into());679 }680681 let caller = T::CrossAccountId::from_eth(caller);682 let to = T::CrossAccountId::from_eth(to);683 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;684 let budget = self685 .recorder686 .weight_calls_budget(<StructureWeight<T>>::find_parent());687688 if <TokensMinted<T>>::get(self.id)689 .checked_add(1)690 .ok_or("item id overflow")?691 != token_id692 {693 return Err("item id should be next".into());694 }695696 let mut properties = CollectionPropertiesVec::default();697 properties698 .try_push(Property {699 key,700 value: token_uri701 .into_bytes()702 .try_into()703 .map_err(|_| "token uri is too long")?,704 })705 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;706707 let users = [(to.clone(), 1)]708 .into_iter()709 .collect::<BTreeMap<_, _>>()710 .try_into()711 .unwrap();712 <Pallet<T>>::create_item(713 self,714 &caller,715 CreateItemData::<T> { users, properties },716 &budget,717 )718 .map_err(dispatch_to_evm::<T>)?;719 Ok(true)720 }721722 /// @dev Not implemented723 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {724 Err("not implementable".into())725 }726}727728fn get_token_property<T: Config>(729 collection: &CollectionHandle<T>,730 token_id: u32,731 key: &up_data_structs::PropertyKey,732) -> Result<string> {733 collection.consume_store_reads(1)?;734 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))735 .map_err(|_| Error::Revert("Token properties not found".into()))?;736 if let Some(property) = properties.get(key) {737 return Ok(string::from_utf8_lossy(property).into());738 }739740 Err("Property tokenURI not found".into())741}742743fn get_token_permission<T: Config>(744 collection_id: CollectionId,745 key: &PropertyKey,746) -> Result<PropertyPermission> {747 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)748 .map_err(|_| Error::Revert("No permissions for collection".into()))?;749 let a = token_property_permissions750 .get(key)751 .map(Clone::clone)752 .ok_or_else(|| {753 let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();754 Error::Revert(alloc::format!("No permission for key {}", key))755 })?;756 Ok(a)757}758759/// @title Unique extensions for ERC721.760#[solidity_interface(name = ERC721UniqueExtensions)]761impl<T: Config> RefungibleHandle<T>762where763 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,764{765 /// @notice A descriptive name for a collection of NFTs in this contract766 fn name(&self) -> Result<string> {767 Ok(decode_utf16(self.name.iter().copied())768 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))769 .collect::<string>())770 }771772 /// @notice An abbreviated name for NFTs in this contract773 fn symbol(&self) -> Result<string> {774 Ok(string::from_utf8_lossy(&self.token_prefix).into())775 }776777 /// @notice A description for the collection.778 fn description(&self) -> Result<string> {779 Ok(decode_utf16(self.description.iter().copied())780 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))781 .collect::<string>())782 }783784 /// Returns the owner (in cross format) of the token.785 ///786 /// @param tokenId Id for the token.787 fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {788 Self::token_owner(&self, token_id.try_into()?)789 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))790 .ok_or(Error::Revert("key too large".into()))791 }792793 /// Returns the token properties.794 ///795 /// @param tokenId Id for the token.796 /// @param keys Properties keys. Empty keys for all propertyes.797 /// @return Vector of properties key/value pairs.798 fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {799 let keys = keys800 .into_iter()801 .map(|key| {802 <Vec<u8>>::from(key)803 .try_into()804 .map_err(|_| Error::Revert("key too large".into()))805 })806 .collect::<Result<Vec<_>>>()?;807808 <Self as CommonCollectionOperations<T>>::token_properties(809 &self,810 token_id.try_into()?,811 if keys.is_empty() { None } else { Some(keys) },812 )813 .into_iter()814 .map(eth::Property::try_from)815 .collect::<Result<Vec<_>>>()816 }817 /// @notice Transfer ownership of an RFT818 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`819 /// is the zero address. Throws if `tokenId` is not a valid RFT.820 /// Throws if RFT pieces have multiple owners.821 /// @param to The new owner822 /// @param tokenId The RFT to transfer823 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]824 fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<void> {825 let caller = T::CrossAccountId::from_eth(caller);826 let to = T::CrossAccountId::from_eth(to);827 let token = token_id.try_into()?;828 let budget = self829 .recorder830 .weight_calls_budget(<StructureWeight<T>>::find_parent());831832 let balance = balance(self, token, &caller)?;833 ensure_single_owner(self, token, balance)?;834835 <Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)836 .map_err(dispatch_to_evm::<T>)?;837 Ok(())838 }839840 /// @notice Transfer ownership of an RFT841 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`842 /// is the zero address. Throws if `tokenId` is not a valid RFT.843 /// Throws if RFT pieces have multiple owners.844 /// @param to The new owner845 /// @param tokenId The RFT to transfer846 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]847 fn transfer_cross(848 &mut self,849 caller: caller,850 to: eth::CrossAddress,851 token_id: uint256,852 ) -> Result<void> {853 let caller = T::CrossAccountId::from_eth(caller);854 let to = to.into_sub_cross_account::<T>()?;855 let token = token_id.try_into()?;856 let budget = self857 .recorder858 .weight_calls_budget(<StructureWeight<T>>::find_parent());859860 let balance = balance(self, token, &caller)?;861 ensure_single_owner(self, token, balance)?;862863 <Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)864 .map_err(dispatch_to_evm::<T>)?;865 Ok(())866 }867868 /// @notice Transfer ownership of an RFT869 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`870 /// is the zero address. Throws if `tokenId` is not a valid RFT.871 /// Throws if RFT pieces have multiple owners.872 /// @param to The new owner873 /// @param tokenId The RFT to transfer874 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]875 fn transfer_from_cross(876 &mut self,877 caller: caller,878 from: eth::CrossAddress,879 to: eth::CrossAddress,880 token_id: uint256,881 ) -> Result<void> {882 let caller = T::CrossAccountId::from_eth(caller);883 let from = from.into_sub_cross_account::<T>()?;884 let to = to.into_sub_cross_account::<T>()?;885 let token_id = token_id.try_into()?;886 let budget = self887 .recorder888 .weight_calls_budget(<StructureWeight<T>>::find_parent());889890 let balance = balance(self, token_id, &from)?;891 ensure_single_owner(self, token_id, balance)?;892893 Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)894 .map_err(dispatch_to_evm::<T>)?;895 Ok(())896 }897898 /// @notice Burns a specific ERC721 token.899 /// @dev Throws unless `msg.sender` is the current owner or an authorized900 /// operator for this RFT. Throws if `from` is not the current owner. Throws901 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.902 /// Throws if RFT pieces have multiple owners.903 /// @param from The current owner of the RFT904 /// @param tokenId The RFT to transfer905 #[solidity(hide)]906 #[weight(<SelfWeightOf<T>>::burn_from())]907 fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<void> {908 let caller = T::CrossAccountId::from_eth(caller);909 let from = T::CrossAccountId::from_eth(from);910 let token = token_id.try_into()?;911 let budget = self912 .recorder913 .weight_calls_budget(<StructureWeight<T>>::find_parent());914915 let balance = balance(self, token, &from)?;916 ensure_single_owner(self, token, balance)?;917918 <Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)919 .map_err(dispatch_to_evm::<T>)?;920 Ok(())921 }922923 /// @notice Burns a specific ERC721 token.924 /// @dev Throws unless `msg.sender` is the current owner or an authorized925 /// operator for this RFT. Throws if `from` is not the current owner. Throws926 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.927 /// Throws if RFT pieces have multiple owners.928 /// @param from The current owner of the RFT929 /// @param tokenId The RFT to transfer930 #[weight(<SelfWeightOf<T>>::burn_from())]931 fn burn_from_cross(932 &mut self,933 caller: caller,934 from: eth::CrossAddress,935 token_id: uint256,936 ) -> Result<void> {937 let caller = T::CrossAccountId::from_eth(caller);938 let from = from.into_sub_cross_account::<T>()?;939 let token = token_id.try_into()?;940 let budget = self941 .recorder942 .weight_calls_budget(<StructureWeight<T>>::find_parent());943944 let balance = balance(self, token, &from)?;945 ensure_single_owner(self, token, balance)?;946947 <Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)948 .map_err(dispatch_to_evm::<T>)?;949 Ok(())950 }951952 /// @notice Returns next free RFT ID.953 fn next_token_id(&self) -> Result<uint256> {954 self.consume_store_reads(1)?;955 Ok(<TokensMinted<T>>::get(self.id)956 .checked_add(1)957 .ok_or("item id overflow")?958 .into())959 }960961 /// @notice Function to mint multiple tokens.962 /// @dev `tokenIds` should be an array of consecutive numbers and first number963 /// should be obtained with `nextTokenId` method964 /// @param to The new owner965 /// @param tokenIds IDs of the minted RFTs966 #[solidity(hide)]967 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]968 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {969 let caller = T::CrossAccountId::from_eth(caller);970 let to = T::CrossAccountId::from_eth(to);971 let mut expected_index = <TokensMinted<T>>::get(self.id)972 .checked_add(1)973 .ok_or("item id overflow")?;974 let budget = self975 .recorder976 .weight_calls_budget(<StructureWeight<T>>::find_parent());977978 let total_tokens = token_ids.len();979 for id in token_ids.into_iter() {980 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;981 if id != expected_index {982 return Err("item id should be next".into());983 }984 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;985 }986 let users = [(to.clone(), 1)]987 .into_iter()988 .collect::<BTreeMap<_, _>>()989 .try_into()990 .unwrap();991 let create_item_data = CreateItemData::<T> {992 users,993 properties: CollectionPropertiesVec::default(),994 };995 let data = (0..total_tokens)996 .map(|_| create_item_data.clone())997 .collect();998999 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1000 .map_err(dispatch_to_evm::<T>)?;1001 Ok(true)1002 }10031004 /// @notice Function to mint multiple tokens with the given tokenUris.1005 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive1006 /// numbers and first number should be obtained with `nextTokenId` method1007 /// @param to The new owner1008 /// @param tokens array of pairs of token ID and token URI for minted tokens1009 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]1010 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]1011 fn mint_bulk_with_token_uri(1012 &mut self,1013 caller: caller,1014 to: address,1015 tokens: Vec<(uint256, string)>,1016 ) -> Result<bool> {1017 let key = key::url();1018 let caller = T::CrossAccountId::from_eth(caller);1019 let to = T::CrossAccountId::from_eth(to);1020 let mut expected_index = <TokensMinted<T>>::get(self.id)1021 .checked_add(1)1022 .ok_or("item id overflow")?;1023 let budget = self1024 .recorder1025 .weight_calls_budget(<StructureWeight<T>>::find_parent());10261027 let mut data = Vec::with_capacity(tokens.len());1028 let users: BoundedBTreeMap<_, _, _> = [(to.clone(), 1)]1029 .into_iter()1030 .collect::<BTreeMap<_, _>>()1031 .try_into()1032 .unwrap();1033 for (id, token_uri) in tokens {1034 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;1035 if id != expected_index {1036 return Err("item id should be next".into());1037 }1038 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;10391040 let mut properties = CollectionPropertiesVec::default();1041 properties1042 .try_push(Property {1043 key: key.clone(),1044 value: token_uri1045 .into_bytes()1046 .try_into()1047 .map_err(|_| "token uri is too long")?,1048 })1049 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;10501051 let create_item_data = CreateItemData::<T> {1052 users: users.clone(),1053 properties,1054 };1055 data.push(create_item_data);1056 }10571058 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1059 .map_err(dispatch_to_evm::<T>)?;1060 Ok(true)1061 }10621063 /// @notice Function to mint a token.1064 /// @param to The new owner crossAccountId1065 /// @param properties Properties of minted token1066 /// @return uint256 The id of the newly minted token1067 #[weight(<SelfWeightOf<T>>::create_item())]1068 fn mint_cross(1069 &mut self,1070 caller: caller,1071 to: eth::CrossAddress,1072 properties: Vec<eth::Property>,1073 ) -> Result<uint256> {1074 let token_id = <TokensMinted<T>>::get(self.id)1075 .checked_add(1)1076 .ok_or("item id overflow")?;10771078 let to = to.into_sub_cross_account::<T>()?;10791080 let properties = properties1081 .into_iter()1082 .map(eth::Property::try_into)1083 .collect::<Result<Vec<_>>>()?1084 .try_into()1085 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;10861087 let caller = T::CrossAccountId::from_eth(caller);10881089 let budget = self1090 .recorder1091 .weight_calls_budget(<StructureWeight<T>>::find_parent());10921093 let users = [(to, 1)]1094 .into_iter()1095 .collect::<BTreeMap<_, _>>()1096 .try_into()1097 .unwrap();1098 <Pallet<T>>::create_item(1099 self,1100 &caller,1101 CreateItemData::<T> { users, properties },1102 &budget,1103 )1104 .map_err(dispatch_to_evm::<T>)?;11051106 Ok(token_id.into())1107 }11081109 /// Returns EVM address for refungible token1110 ///1111 /// @param token ID of the token1112 fn token_contract_address(&self, token: uint256) -> Result<address> {1113 Ok(T::EvmTokenAddressMapping::token_to_address(1114 self.id,1115 token.try_into().map_err(|_| "token id overflow")?,1116 ))1117 }11181119 /// @notice Returns collection helper contract address1120 fn collection_helper_address(&self) -> Result<address> {1121 Ok(T::ContractAddress::get())1122 }1123}11241125#[solidity_interface(1126 name = UniqueRefungible,1127 is(1128 ERC721,1129 ERC721Enumerable,1130 ERC721UniqueExtensions,1131 ERC721UniqueMintable,1132 ERC721Burnable,1133 ERC721Metadata(if(this.flags.erc721metadata)),1134 Collection(via(common_mut returns CollectionHandle<T>)),1135 TokenProperties,1136 )1137)]1138impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}11391140// Not a tests, but code generators1141generate_stubgen!(gen_impl, UniqueRefungibleCall<()>, true);1142generate_stubgen!(gen_iface, UniqueRefungibleCall<()>, false);11431144impl<T: Config> CommonEvmHandler for RefungibleHandle<T>1145where1146 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,1147{1148 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");1149 fn call(1150 self,1151 handle: &mut impl PrecompileHandle,1152 ) -> Option<pallet_common::erc::PrecompileResult> {1153 call::<T, UniqueRefungibleCall<T>, _, _>(handle, self)1154 }1155}pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -641,6 +641,8 @@
TransferEnabled
}
+/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
+/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
contract ERC721Metadata is Dummy, ERC165 {
// /// @notice A descriptive name for a collection of NFTs in this contract
@@ -783,7 +785,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xabf30dc2
+/// @dev the ERC-165 identifier for this interface is 0xb365c124
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,
@@ -985,6 +987,15 @@
dummy;
return 0x0000000000000000000000000000000000000000;
}
+
+ /// @notice Returns collection helper contract address
+ /// @dev EVM selector for this function is: 0x1896cce6,
+ /// or in textual repr: collectionHelperAddress()
+ function collectionHelperAddress() public view returns (address) {
+ require(false, stub_error);
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
}
/// @dev anonymous struct
@@ -1042,7 +1053,7 @@
/// @title ERC-721 Non-Fungible Token Standard
/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
-/// @dev the ERC-165 identifier for this interface is 0x4016cd87
+/// @dev the ERC-165 identifier for this interface is 0x80ac58cd
contract ERC721 is Dummy, ERC165, ERC721Events {
/// @notice Count all RFTs assigned to an owner
/// @dev RFTs assigned to the zero address are considered invalid, and this
@@ -1075,9 +1086,9 @@
}
/// @dev Not implemented
- /// @dev EVM selector for this function is: 0x60a11672,
- /// or in textual repr: safeTransferFromWithData(address,address,uint256,bytes)
- function safeTransferFromWithData(
+ /// @dev EVM selector for this function is: 0xb88d4fde,
+ /// or in textual repr: safeTransferFrom(address,address,uint256,bytes)
+ function safeTransferFrom(
address from,
address to,
uint256 tokenId,
@@ -1172,15 +1183,6 @@
operator;
dummy;
return false;
- }
-
- /// @notice Returns collection helper contract address
- /// @dev EVM selector for this function is: 0x1896cce6,
- /// or in textual repr: collectionHelperAddress()
- function collectionHelperAddress() public view returns (address) {
- require(false, stub_error);
- dummy;
- return 0x0000000000000000000000000000000000000000;
}
}
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -139,8 +139,7 @@
| BalanceOf { .. }
| OwnerOf { .. }
| GetApproved { .. }
- | IsApprovedForAll { .. }
- | CollectionHelperAddress => None,
+ | IsApprovedForAll { .. } => None,
// Not sponsored
SafeTransferFromWithData { .. }
@@ -230,7 +229,8 @@
| CrossOwnerOf { .. }
| Properties { .. }
| NextTokenId
- | TokenContractAddress { .. } => None,
+ | TokenContractAddress { .. }
+ | CollectionHelperAddress => None,
// Not sponsored
BurnFrom { .. }
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -451,7 +451,9 @@
}
fn account_code_at(address: H160) -> Vec<u8> {
- EVM::account_codes(address)
+ use pallet_evm::OnMethodCall;
+ <Runtime as pallet_evm::Config>::OnMethodCall::get_code(&address)
+ .unwrap_or_else(|| EVM::account_codes(address))
}
fn author() -> H160 {
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -51,6 +51,12 @@
},
{
"anonymous": false,
+ "inputs": [],
+ "name": "MintingFinished",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
"inputs": [
{
"indexed": true,
@@ -417,6 +423,13 @@
"type": "function"
},
{
+ "inputs": [],
+ "name": "finishMinting",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
@@ -504,6 +517,13 @@
},
{
"inputs": [],
+ "name": "mintingFinished",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -51,6 +51,12 @@
},
{
"anonymous": false,
+ "inputs": [],
+ "name": "MintingFinished",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
"inputs": [
{
"indexed": true,
@@ -399,6 +405,13 @@
"type": "function"
},
{
+ "inputs": [],
+ "name": "finishMinting",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
@@ -486,6 +499,13 @@
},
{
"inputs": [],
+ "name": "mintingFinished",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
@@ -596,7 +616,7 @@
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" },
{ "internalType": "bytes", "name": "data", "type": "bytes" }
],
- "name": "safeTransferFromWithData",
+ "name": "safeTransferFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
tests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungibleToken.json
+++ b/tests/src/eth/abi/reFungibleToken.json
@@ -98,6 +98,16 @@
},
{
"inputs": [
+ { "internalType": "address", "name": "from", "type": "address" },
+ { "internalType": "uint256", "name": "amount", "type": "uint256" }
+ ],
+ "name": "burnFrom",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
{
"components": [
{ "internalType": "address", "name": "eth", "type": "address" },
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -536,7 +536,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x0e48fdb4
+/// @dev the ERC-165 identifier for this interface is 0x16de3152
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,
@@ -661,6 +661,11 @@
/// @dev EVM selector for this function is: 0xb904db03,
/// or in textual repr: mintCross((address,uint256),(string,bytes)[])
function mintCross(CrossAddress memory to, Property[] memory properties) external returns (uint256);
+
+ /// @notice Returns collection helper contract address
+ /// @dev EVM selector for this function is: 0x1896cce6,
+ /// or in textual repr: collectionHelperAddress()
+ function collectionHelperAddress() external view returns (address);
}
/// @dev anonymous struct
@@ -703,7 +708,7 @@
/// @title ERC-721 Non-Fungible Token Standard
/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
-/// @dev the ERC-165 identifier for this interface is 0x983a942b
+/// @dev the ERC-165 identifier for this interface is 0x80ac58cd
interface ERC721 is Dummy, ERC165, ERC721Events {
/// @notice Count all NFTs assigned to an owner
/// @dev NFTs assigned to the zero address are considered invalid, and this
@@ -786,11 +791,6 @@
/// @dev EVM selector for this function is: 0xe985e9c5,
/// or in textual repr: isApprovedForAll(address,address)
function isApprovedForAll(address owner, address operator) external view returns (bool);
-
- /// @notice Returns collection helper contract address
- /// @dev EVM selector for this function is: 0x1896cce6,
- /// or in textual repr: collectionHelperAddress()
- function collectionHelperAddress() external view returns (address);
}
interface UniqueNFT is
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -441,6 +441,8 @@
TransferEnabled
}
+/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
+/// @dev See https://eips.ethereum.org/EIPS/eip-721
/// @dev the ERC-165 identifier for this interface is 0x5b5e139f
interface ERC721Metadata is Dummy, ERC165 {
// /// @notice A descriptive name for a collection of NFTs in this contract
@@ -534,7 +536,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xabf30dc2
+/// @dev the ERC-165 identifier for this interface is 0xb365c124
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,
@@ -660,6 +662,11 @@
/// @dev EVM selector for this function is: 0xab76fac6,
/// or in textual repr: tokenContractAddress(uint256)
function tokenContractAddress(uint256 token) external view returns (address);
+
+ /// @notice Returns collection helper contract address
+ /// @dev EVM selector for this function is: 0x1896cce6,
+ /// or in textual repr: collectionHelperAddress()
+ function collectionHelperAddress() external view returns (address);
}
/// @dev anonymous struct
@@ -702,7 +709,7 @@
/// @title ERC-721 Non-Fungible Token Standard
/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
-/// @dev the ERC-165 identifier for this interface is 0x4016cd87
+/// @dev the ERC-165 identifier for this interface is 0x80ac58cd
interface ERC721 is Dummy, ERC165, ERC721Events {
/// @notice Count all RFTs assigned to an owner
/// @dev RFTs assigned to the zero address are considered invalid, and this
@@ -725,9 +732,9 @@
function ownerOf(uint256 tokenId) external view returns (address);
/// @dev Not implemented
- /// @dev EVM selector for this function is: 0x60a11672,
- /// or in textual repr: safeTransferFromWithData(address,address,uint256,bytes)
- function safeTransferFromWithData(
+ /// @dev EVM selector for this function is: 0xb88d4fde,
+ /// or in textual repr: safeTransferFrom(address,address,uint256,bytes)
+ function safeTransferFrom(
address from,
address to,
uint256 tokenId,
@@ -783,11 +790,6 @@
/// @dev EVM selector for this function is: 0xe985e9c5,
/// or in textual repr: isApprovedForAll(address,address)
function isApprovedForAll(address owner, address operator) external view returns (bool);
-
- /// @notice Returns collection helper contract address
- /// @dev EVM selector for this function is: 0x1896cce6,
- /// or in textual repr: collectionHelperAddress()
- function collectionHelperAddress() external view returns (address);
}
interface UniqueRefungible is