git.delta.rocks / unique-network / refs/commits / 214592d86cdb

difftreelog

misc: change uint256 to U256

Trubnikov Sergey2023-01-17parent: #7aa4c58.patch.diff
in: master

10 files changed

modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
132 use primitive_types::{U256, H160, H256};132 use primitive_types::{U256, H160, H256};
133133
134 pub type address = H160;134 pub type address = H160;
135 pub type uint256 = U256;
136 pub type bytes4 = [u8; 4];135 pub type bytes4 = [u8; 4];
137 pub type topic = H256;136 pub type topic = H256;
138137
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
20use sp_std::{vec, vec::Vec};20use sp_std::{vec, vec::Vec};
21use evm_coder::{21use evm_coder::{AbiCoder, types::address};
22 AbiCoder,
23 types::{uint256, address},
24};
25pub use pallet_evm::{Config, account::CrossAccountId};22pub use pallet_evm::{Config, account::CrossAccountId};
26use sp_core::H160;23use sp_core::{H160, U256};
27use up_data_structs::CollectionId;24use up_data_structs::CollectionId;
2825
29// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 126// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 1
55 address[0..16] == ETH_COLLECTION_PREFIX52 address[0..16] == ETH_COLLECTION_PREFIX
56}53}
5754
58/// Convert `uint256` to `CrossAccountId`.55/// Convert `U256` to `CrossAccountId`.
59pub fn convert_uint256_to_cross_account<T: Config>(from: uint256) -> T::CrossAccountId56pub fn convert_uint256_to_cross_account<T: Config>(from: U256) -> T::CrossAccountId
60where57where
61 T::AccountId: From<[u8; 32]>,58 T::AccountId: From<[u8; 32]>,
62{59{
70#[derive(Debug, Default, AbiCoder)]67#[derive(Debug, Default, AbiCoder)]
71pub struct CrossAddress {68pub struct CrossAddress {
72 pub(crate) eth: address,69 pub(crate) eth: address,
73 pub(crate) sub: uint256,70 pub(crate) sub: U256,
74}71}
7572
76impl CrossAddress {73impl CrossAddress {
97 {94 {
98 Self {95 Self {
99 eth: Default::default(),96 eth: Default::default(),
100 sub: uint256::from_big_endian(account_id.as_ref()),97 sub: U256::from_big_endian(account_id.as_ref()),
101 }98 }
102 }99 }
103 /// Converts [`CrossAddress`] to `CrossAccountId`.100 /// Converts [`CrossAddress`] to `CrossAccountId`.
187#[derive(Debug, Default, AbiCoder)]184#[derive(Debug, Default, AbiCoder)]
188pub struct CollectionLimit {185pub struct CollectionLimit {
189 field: CollectionLimitField,186 field: CollectionLimitField,
190 value: Option<uint256>,187 value: Option<U256>,
191}188}
192189
193impl CollectionLimit {190impl CollectionLimit {
393#[derive(Debug, Default, AbiCoder)]390#[derive(Debug, Default, AbiCoder)]
394pub struct CollectionNesting {391pub struct CollectionNesting {
395 token_owner: bool,392 token_owner: bool,
396 ids: Vec<uint256>,393 ids: Vec<U256>,
397}394}
398395
399impl CollectionNesting {396impl CollectionNesting {
400 /// Create [`CollectionNesting`].397 /// Create [`CollectionNesting`].
401 pub fn new(token_owner: bool, ids: Vec<uint256>) -> Self {398 pub fn new(token_owner: bool, ids: Vec<U256>) -> Self {
402 Self { token_owner, ids }399 Self { token_owner, ids }
403 }400 }
404}401}
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
261 &mut self,261 &mut self,
262 caller: caller,262 caller: caller,
263 contract_address: address,263 contract_address: address,
264 fee_limit: uint256,264 fee_limit: U256,
265 ) -> Result<()> {265 ) -> Result<()> {
266 self.recorder().consume_sload()?;266 self.recorder().consume_sload()?;
267 self.recorder().consume_sstore()?;267 self.recorder().consume_sstore()?;
276 /// @param contractAddress Contract to get sponsoring fee limit of276 /// @param contractAddress Contract to get sponsoring fee limit of
277 /// @return uint256 Maximum amount of fee that could be spent by single277 /// @return uint256 Maximum amount of fee that could be spent by single
278 /// transaction278 /// transaction
279 fn sponsoring_fee_limit(&self, contract_address: address) -> Result<uint256> {279 fn sponsoring_fee_limit(&self, contract_address: address) -> Result<U256> {
280 self.recorder().consume_sload()?;280 self.recorder().consume_sload()?;
281281
282 Ok(get_sponsoring_fee_limit::<T>(contract_address))282 Ok(get_sponsoring_fee_limit::<T>(contract_address))
441 }441 }
442}442}
443443
444fn get_sponsoring_fee_limit<T: Config>(contract_address: address) -> uint256 {444fn get_sponsoring_fee_limit<T: Config>(contract_address: address) -> U256 {
445 <SponsoringFeeLimit<T>>::get(contract_address)445 <SponsoringFeeLimit<T>>::get(contract_address)
446 .get(&0xffffffff)446 .get(&0xffffffff)
447 .cloned()447 .cloned()
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
32use pallet_evm::{account::CrossAccountId, PrecompileHandle};32use pallet_evm::{account::CrossAccountId, PrecompileHandle};
33use pallet_evm_coder_substrate::{call, dispatch_to_evm};33use pallet_evm_coder_substrate::{call, dispatch_to_evm};
34use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};34use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
35use sp_core::Get;35use sp_core::{U256, Get};
3636
37use crate::{37use crate::{
38 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,38 Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,
46 from: address,46 from: address,
47 #[indexed]47 #[indexed]
48 to: address,48 to: address,
49 value: uint256,49 value: U256,
50 },50 },
51 Approval {51 Approval {
52 #[indexed]52 #[indexed]
53 owner: address,53 owner: address,
54 #[indexed]54 #[indexed]
55 spender: address,55 spender: address,
56 value: uint256,56 value: U256,
57 },57 },
58}58}
5959
67 fn symbol(&self) -> Result<string> {67 fn symbol(&self) -> Result<string> {
68 Ok(string::from_utf8_lossy(&self.token_prefix).into())68 Ok(string::from_utf8_lossy(&self.token_prefix).into())
69 }69 }
70 fn total_supply(&self) -> Result<uint256> {70 fn total_supply(&self) -> Result<U256> {
71 self.consume_store_reads(1)?;71 self.consume_store_reads(1)?;
72 Ok(<TotalSupply<T>>::get(self.id).into())72 Ok(<TotalSupply<T>>::get(self.id).into())
73 }73 }
79 unreachable!()79 unreachable!()
80 })80 })
81 }81 }
82 fn balance_of(&self, owner: address) -> Result<uint256> {82 fn balance_of(&self, owner: address) -> Result<U256> {
83 self.consume_store_reads(1)?;83 self.consume_store_reads(1)?;
84 let owner = T::CrossAccountId::from_eth(owner);84 let owner = T::CrossAccountId::from_eth(owner);
85 let balance = <Balance<T>>::get((self.id, owner));85 let balance = <Balance<T>>::get((self.id, owner));
86 Ok(balance.into())86 Ok(balance.into())
87 }87 }
88 #[weight(<SelfWeightOf<T>>::transfer())]88 #[weight(<SelfWeightOf<T>>::transfer())]
89 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {89 fn transfer(&mut self, caller: caller, to: address, amount: U256) -> Result<bool> {
90 let caller = T::CrossAccountId::from_eth(caller);90 let caller = T::CrossAccountId::from_eth(caller);
91 let to = T::CrossAccountId::from_eth(to);91 let to = T::CrossAccountId::from_eth(to);
92 let amount = amount.try_into().map_err(|_| "amount overflow")?;92 let amount = amount.try_into().map_err(|_| "amount overflow")?;
104 caller: caller,104 caller: caller,
105 from: address,105 from: address,
106 to: address,106 to: address,
107 amount: uint256,107 amount: U256,
108 ) -> Result<bool> {108 ) -> Result<bool> {
109 let caller = T::CrossAccountId::from_eth(caller);109 let caller = T::CrossAccountId::from_eth(caller);
110 let from = T::CrossAccountId::from_eth(from);110 let from = T::CrossAccountId::from_eth(from);
119 Ok(true)119 Ok(true)
120 }120 }
121 #[weight(<SelfWeightOf<T>>::approve())]121 #[weight(<SelfWeightOf<T>>::approve())]
122 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {122 fn approve(&mut self, caller: caller, spender: address, amount: U256) -> Result<bool> {
123 let caller = T::CrossAccountId::from_eth(caller);123 let caller = T::CrossAccountId::from_eth(caller);
124 let spender = T::CrossAccountId::from_eth(spender);124 let spender = T::CrossAccountId::from_eth(spender);
125 let amount = amount.try_into().map_err(|_| "amount overflow")?;125 let amount = amount.try_into().map_err(|_| "amount overflow")?;
128 .map_err(dispatch_to_evm::<T>)?;128 .map_err(dispatch_to_evm::<T>)?;
129 Ok(true)129 Ok(true)
130 }130 }
131 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {131 fn allowance(&self, owner: address, spender: address) -> Result<U256> {
132 self.consume_store_reads(1)?;132 self.consume_store_reads(1)?;
133 let owner = T::CrossAccountId::from_eth(owner);133 let owner = T::CrossAccountId::from_eth(owner);
134 let spender = T::CrossAccountId::from_eth(spender);134 let spender = T::CrossAccountId::from_eth(spender);
148 /// @param to account that will receive minted tokens148 /// @param to account that will receive minted tokens
149 /// @param amount amount of tokens to mint149 /// @param amount amount of tokens to mint
150 #[weight(<SelfWeightOf<T>>::create_item())]150 #[weight(<SelfWeightOf<T>>::create_item())]
151 fn mint(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {151 fn mint(&mut self, caller: caller, to: address, amount: U256) -> Result<bool> {
152 let caller = T::CrossAccountId::from_eth(caller);152 let caller = T::CrossAccountId::from_eth(caller);
153 let to = T::CrossAccountId::from_eth(to);153 let to = T::CrossAccountId::from_eth(to);
154 let amount = amount.try_into().map_err(|_| "amount overflow")?;154 let amount = amount.try_into().map_err(|_| "amount overflow")?;
178 &mut self,178 &mut self,
179 caller: caller,179 caller: caller,
180 to: pallet_common::eth::CrossAddress,180 to: pallet_common::eth::CrossAddress,
181 amount: uint256,181 amount: U256,
182 ) -> Result<bool> {182 ) -> Result<bool> {
183 let caller = T::CrossAccountId::from_eth(caller);183 let caller = T::CrossAccountId::from_eth(caller);
184 let to = to.into_sub_cross_account::<T>()?;184 let to = to.into_sub_cross_account::<T>()?;
196 &mut self,196 &mut self,
197 caller: caller,197 caller: caller,
198 spender: pallet_common::eth::CrossAddress,198 spender: pallet_common::eth::CrossAddress,
199 amount: uint256,199 amount: U256,
200 ) -> Result<bool> {200 ) -> Result<bool> {
201 let caller = T::CrossAccountId::from_eth(caller);201 let caller = T::CrossAccountId::from_eth(caller);
202 let spender = spender.into_sub_cross_account::<T>()?;202 let spender = spender.into_sub_cross_account::<T>()?;
214 /// @param amount The amount that will be burnt.214 /// @param amount The amount that will be burnt.
215 #[solidity(hide)]215 #[solidity(hide)]
216 #[weight(<SelfWeightOf<T>>::burn_from())]216 #[weight(<SelfWeightOf<T>>::burn_from())]
217 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {217 fn burn_from(&mut self, caller: caller, from: address, amount: U256) -> Result<bool> {
218 let caller = T::CrossAccountId::from_eth(caller);218 let caller = T::CrossAccountId::from_eth(caller);
219 let from = T::CrossAccountId::from_eth(from);219 let from = T::CrossAccountId::from_eth(from);
220 let amount = amount.try_into().map_err(|_| "amount overflow")?;220 let amount = amount.try_into().map_err(|_| "amount overflow")?;
237 &mut self,237 &mut self,
238 caller: caller,238 caller: caller,
239 from: pallet_common::eth::CrossAddress,239 from: pallet_common::eth::CrossAddress,
240 amount: uint256,240 amount: U256,
241 ) -> Result<bool> {241 ) -> Result<bool> {
242 let caller = T::CrossAccountId::from_eth(caller);242 let caller = T::CrossAccountId::from_eth(caller);
243 let from = from.into_sub_cross_account::<T>()?;243 let from = from.into_sub_cross_account::<T>()?;
254 /// Mint tokens for multiple accounts.254 /// Mint tokens for multiple accounts.
255 /// @param amounts array of pairs of account address and amount255 /// @param amounts array of pairs of account address and amount
256 #[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]256 #[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]
257 fn mint_bulk(&mut self, caller: caller, amounts: Vec<(address, uint256)>) -> Result<bool> {257 fn mint_bulk(&mut self, caller: caller, amounts: Vec<(address, U256)>) -> Result<bool> {
258 let caller = T::CrossAccountId::from_eth(caller);258 let caller = T::CrossAccountId::from_eth(caller);
259 let budget = self259 let budget = self
260 .recorder260 .recorder
279 &mut self,279 &mut self,
280 caller: caller,280 caller: caller,
281 to: pallet_common::eth::CrossAddress,281 to: pallet_common::eth::CrossAddress,
282 amount: uint256,282 amount: U256,
283 ) -> Result<bool> {283 ) -> Result<bool> {
284 let caller = T::CrossAccountId::from_eth(caller);284 let caller = T::CrossAccountId::from_eth(caller);
285 let to = to.into_sub_cross_account::<T>()?;285 let to = to.into_sub_cross_account::<T>()?;
298 caller: caller,298 caller: caller,
299 from: pallet_common::eth::CrossAddress,299 from: pallet_common::eth::CrossAddress,
300 to: pallet_common::eth::CrossAddress,300 to: pallet_common::eth::CrossAddress,
301 amount: uint256,301 amount: U256,
302 ) -> Result<bool> {302 ) -> Result<bool> {
303 let caller = T::CrossAccountId::from_eth(caller);303 let caller = T::CrossAccountId::from_eth(caller);
304 let from = from.into_sub_cross_account::<T>()?;304 let from = from.into_sub_cross_account::<T>()?;
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
43use pallet_evm::{account::CrossAccountId, PrecompileHandle};43use pallet_evm::{account::CrossAccountId, PrecompileHandle};
44use pallet_evm_coder_substrate::call;44use pallet_evm_coder_substrate::call;
45use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};45use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
46use sp_core::Get;46use sp_core::{U256, Get};
4747
48use crate::{48use crate::{
49 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,49 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
122 fn set_property(122 fn set_property(
123 &mut self,123 &mut self,
124 caller: caller,124 caller: caller,
125 token_id: uint256,125 token_id: U256,
126 key: string,126 key: string,
127 value: bytes,127 value: bytes,
128 ) -> Result<()> {128 ) -> Result<()> {
155 fn set_properties(155 fn set_properties(
156 &mut self,156 &mut self,
157 caller: caller,157 caller: caller,
158 token_id: uint256,158 token_id: U256,
159 properties: Vec<eth::Property>,159 properties: Vec<eth::Property>,
160 ) -> Result<()> {160 ) -> Result<()> {
161 let caller = T::CrossAccountId::from_eth(caller);161 let caller = T::CrossAccountId::from_eth(caller);
187 /// @param key Property key.187 /// @param key Property key.
188 #[solidity(hide)]188 #[solidity(hide)]
189 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]189 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
190 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {190 fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {
191 let caller = T::CrossAccountId::from_eth(caller);191 let caller = T::CrossAccountId::from_eth(caller);
192 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;192 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
193 let key = <Vec<u8>>::from(key)193 let key = <Vec<u8>>::from(key)
209 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]209 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]
210 fn delete_properties(210 fn delete_properties(
211 &mut self,211 &mut self,
212 token_id: uint256,212 token_id: U256,
213 caller: caller,213 caller: caller,
214 keys: Vec<string>,214 keys: Vec<string>,
215 ) -> Result<()> {215 ) -> Result<()> {
239 /// @param tokenId ID of the token.239 /// @param tokenId ID of the token.
240 /// @param key Property key.240 /// @param key Property key.
241 /// @return Property value bytes241 /// @return Property value bytes
242 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {242 fn property(&self, token_id: U256, key: string) -> Result<bytes> {
243 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;243 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
244 let key = <Vec<u8>>::from(key)244 let key = <Vec<u8>>::from(key)
245 .try_into()245 .try_into()
265 #[indexed]265 #[indexed]
266 to: address,266 to: address,
267 #[indexed]267 #[indexed]
268 token_id: uint256,268 token_id: U256,
269 },269 },
270 /// @dev This emits when the approved address for an NFT is changed or270 /// @dev This emits when the approved address for an NFT is changed or
271 /// reaffirmed. The zero address indicates there is no approved address.271 /// reaffirmed. The zero address indicates there is no approved address.
277 #[indexed]277 #[indexed]
278 approved: address,278 approved: address,
279 #[indexed]279 #[indexed]
280 token_id: uint256,280 token_id: U256,
281 },281 },
282 /// @dev This emits when an operator is enabled or disabled for an owner.282 /// @dev This emits when an operator is enabled or disabled for an owner.
283 /// The operator can manage all NFTs of the owner.283 /// The operator can manage all NFTs of the owner.
322 ///322 ///
323 /// @return token's const_metadata323 /// @return token's const_metadata
324 #[solidity(rename_selector = "tokenURI")]324 #[solidity(rename_selector = "tokenURI")]
325 fn token_uri(&self, token_id: uint256) -> Result<string> {325 fn token_uri(&self, token_id: U256) -> Result<string> {
326 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;326 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
327327
328 match get_token_property(self, token_id_u32, &key::url()).as_deref() {328 match get_token_property(self, token_id_u32, &key::url()).as_deref() {
368 /// @param index A counter less than `totalSupply()`368 /// @param index A counter less than `totalSupply()`
369 /// @return The token identifier for the `index`th NFT,369 /// @return The token identifier for the `index`th NFT,
370 /// (sort order not specified)370 /// (sort order not specified)
371 fn token_by_index(&self, index: uint256) -> Result<uint256> {371 fn token_by_index(&self, index: U256) -> Result<U256> {
372 Ok(index)372 Ok(index)
373 }373 }
374374
375 /// @dev Not implemented375 /// @dev Not implemented
376 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {376 fn token_of_owner_by_index(&self, _owner: address, _index: U256) -> Result<U256> {
377 // TODO: Not implemetable377 // TODO: Not implemetable
378 Err("not implemented".into())378 Err("not implemented".into())
379 }379 }
380380
381 /// @notice Count NFTs tracked by this contract381 /// @notice Count NFTs tracked by this contract
382 /// @return A count of valid NFTs tracked by this contract, where each one of382 /// @return A count of valid NFTs tracked by this contract, where each one of
383 /// them has an assigned and queryable owner not equal to the zero address383 /// them has an assigned and queryable owner not equal to the zero address
384 fn total_supply(&self) -> Result<uint256> {384 fn total_supply(&self) -> Result<U256> {
385 self.consume_store_reads(1)?;385 self.consume_store_reads(1)?;
386 Ok(<Pallet<T>>::total_supply(self).into())386 Ok(<Pallet<T>>::total_supply(self).into())
387 }387 }
396 /// function throws for queries about the zero address.396 /// function throws for queries about the zero address.
397 /// @param owner An address for whom to query the balance397 /// @param owner An address for whom to query the balance
398 /// @return The number of NFTs owned by `owner`, possibly zero398 /// @return The number of NFTs owned by `owner`, possibly zero
399 fn balance_of(&self, owner: address) -> Result<uint256> {399 fn balance_of(&self, owner: address) -> Result<U256> {
400 self.consume_store_reads(1)?;400 self.consume_store_reads(1)?;
401 let owner = T::CrossAccountId::from_eth(owner);401 let owner = T::CrossAccountId::from_eth(owner);
402 let balance = <AccountBalance<T>>::get((self.id, owner));402 let balance = <AccountBalance<T>>::get((self.id, owner));
407 /// about them do throw.407 /// about them do throw.
408 /// @param tokenId The identifier for an NFT408 /// @param tokenId The identifier for an NFT
409 /// @return The address of the owner of the NFT409 /// @return The address of the owner of the NFT
410 fn owner_of(&self, token_id: uint256) -> Result<address> {410 fn owner_of(&self, token_id: U256) -> Result<address> {
411 self.consume_store_reads(1)?;411 self.consume_store_reads(1)?;
412 let token: TokenId = token_id.try_into()?;412 let token: TokenId = token_id.try_into()?;
413 Ok(*<TokenData<T>>::get((self.id, token))413 Ok(*<TokenData<T>>::get((self.id, token))
421 &mut self,421 &mut self,
422 _from: address,422 _from: address,
423 _to: address,423 _to: address,
424 _token_id: uint256,424 _token_id: U256,
425 _data: bytes,425 _data: bytes,
426 ) -> Result<()> {426 ) -> Result<()> {
427 // TODO: Not implemetable427 // TODO: Not implemetable
428 Err("not implemented".into())428 Err("not implemented".into())
429 }429 }
430 /// @dev Not implemented430 /// @dev Not implemented
431 fn safe_transfer_from(431 fn safe_transfer_from(&mut self, _from: address, _to: address, _token_id: U256) -> Result<()> {
432 &mut self,
433 _from: address,
434 _to: address,
435 _token_id: uint256,
436 ) -> Result<()> {
437 // TODO: Not implemetable432 // TODO: Not implemetable
438 Err("not implemented".into())433 Err("not implemented".into())
453 caller: caller,448 caller: caller,
454 from: address,449 from: address,
455 to: address,450 to: address,
456 token_id: uint256,451 token_id: U256,
457 ) -> Result<()> {452 ) -> Result<()> {
458 let caller = T::CrossAccountId::from_eth(caller);453 let caller = T::CrossAccountId::from_eth(caller);
459 let from = T::CrossAccountId::from_eth(from);454 let from = T::CrossAccountId::from_eth(from);
475 /// @param approved The new approved NFT controller470 /// @param approved The new approved NFT controller
476 /// @param tokenId The NFT to approve471 /// @param tokenId The NFT to approve
477 #[weight(<SelfWeightOf<T>>::approve())]472 #[weight(<SelfWeightOf<T>>::approve())]
478 fn approve(&mut self, caller: caller, approved: address, token_id: uint256) -> Result<()> {473 fn approve(&mut self, caller: caller, approved: address, token_id: U256) -> Result<()> {
479 let caller = T::CrossAccountId::from_eth(caller);474 let caller = T::CrossAccountId::from_eth(caller);
480 let approved = T::CrossAccountId::from_eth(approved);475 let approved = T::CrossAccountId::from_eth(approved);
481 let token = token_id.try_into()?;476 let token = token_id.try_into()?;
505 }500 }
506501
507 /// @dev Not implemented502 /// @dev Not implemented
508 fn get_approved(&self, _token_id: uint256) -> Result<address> {503 fn get_approved(&self, _token_id: U256) -> Result<address> {
509 // TODO: Not implemetable504 // TODO: Not implemetable
510 Err("not implemented".into())505 Err("not implemented".into())
511 }506 }
528 /// operator of the current owner.523 /// operator of the current owner.
529 /// @param tokenId The NFT to approve524 /// @param tokenId The NFT to approve
530 #[weight(<SelfWeightOf<T>>::burn_item())]525 #[weight(<SelfWeightOf<T>>::burn_item())]
531 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<()> {526 fn burn(&mut self, caller: caller, token_id: U256) -> Result<()> {
532 let caller = T::CrossAccountId::from_eth(caller);527 let caller = T::CrossAccountId::from_eth(caller);
533 let token = token_id.try_into()?;528 let token = token_id.try_into()?;
534529
544 /// @param to The new owner539 /// @param to The new owner
545 /// @return uint256 The id of the newly minted token540 /// @return uint256 The id of the newly minted token
546 #[weight(<SelfWeightOf<T>>::create_item())]541 #[weight(<SelfWeightOf<T>>::create_item())]
547 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {542 fn mint(&mut self, caller: caller, to: address) -> Result<U256> {
548 let token_id: uint256 = <TokensMinted<T>>::get(self.id)543 let token_id: U256 = <TokensMinted<T>>::get(self.id)
549 .checked_add(1)544 .checked_add(1)
550 .ok_or("item id overflow")?545 .ok_or("item id overflow")?
551 .into();546 .into();
560 /// @param tokenId ID of the minted NFT555 /// @param tokenId ID of the minted NFT
561 #[solidity(hide, rename_selector = "mint")]556 #[solidity(hide, rename_selector = "mint")]
562 #[weight(<SelfWeightOf<T>>::create_item())]557 #[weight(<SelfWeightOf<T>>::create_item())]
563 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {558 fn mint_check_id(&mut self, caller: caller, to: address, token_id: U256) -> Result<bool> {
564 let caller = T::CrossAccountId::from_eth(caller);559 let caller = T::CrossAccountId::from_eth(caller);
565 let to = T::CrossAccountId::from_eth(to);560 let to = T::CrossAccountId::from_eth(to);
566 let token_id: u32 = token_id.try_into()?;561 let token_id: u32 = token_id.try_into()?;
601 caller: caller,596 caller: caller,
602 to: address,597 to: address,
603 token_uri: string,598 token_uri: string,
604 ) -> Result<uint256> {599 ) -> Result<U256> {
605 let token_id: uint256 = <TokensMinted<T>>::get(self.id)600 let token_id: U256 = <TokensMinted<T>>::get(self.id)
606 .checked_add(1)601 .checked_add(1)
607 .ok_or("item id overflow")?602 .ok_or("item id overflow")?
608 .into();603 .into();
622 &mut self,617 &mut self,
623 caller: caller,618 caller: caller,
624 to: address,619 to: address,
625 token_id: uint256,620 token_id: U256,
626 token_uri: string,621 token_uri: string,
627 ) -> Result<bool> {622 ) -> Result<bool> {
628 let key = key::url();623 let key = key::url();
730 /// Returns the owner (in cross format) of the token.725 /// Returns the owner (in cross format) of the token.
731 ///726 ///
732 /// @param tokenId Id for the token.727 /// @param tokenId Id for the token.
733 fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {728 fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {
734 Self::token_owner(&self, token_id.try_into()?)729 Self::token_owner(&self, token_id.try_into()?)
735 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))730 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
736 .ok_or(Error::Revert("key too large".into()))731 .ok_or(Error::Revert("key too large".into()))
741 /// @param tokenId Id for the token.736 /// @param tokenId Id for the token.
742 /// @param keys Properties keys. Empty keys for all propertyes.737 /// @param keys Properties keys. Empty keys for all propertyes.
743 /// @return Vector of properties key/value pairs.738 /// @return Vector of properties key/value pairs.
744 fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {739 fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
745 let keys = keys740 let keys = keys
746 .into_iter()741 .into_iter()
747 .map(|key| {742 .map(|key| {
772 &mut self,767 &mut self,
773 caller: caller,768 caller: caller,
774 approved: eth::CrossAddress,769 approved: eth::CrossAddress,
775 token_id: uint256,770 token_id: U256,
776 ) -> Result<()> {771 ) -> Result<()> {
777 let caller = T::CrossAccountId::from_eth(caller);772 let caller = T::CrossAccountId::from_eth(caller);
778 let approved = approved.into_sub_cross_account::<T>()?;773 let approved = approved.into_sub_cross_account::<T>()?;
789 /// @param to The new owner784 /// @param to The new owner
790 /// @param tokenId The NFT to transfer785 /// @param tokenId The NFT to transfer
791 #[weight(<SelfWeightOf<T>>::transfer())]786 #[weight(<SelfWeightOf<T>>::transfer())]
792 fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<()> {787 fn transfer(&mut self, caller: caller, to: address, token_id: U256) -> Result<()> {
793 let caller = T::CrossAccountId::from_eth(caller);788 let caller = T::CrossAccountId::from_eth(caller);
794 let to = T::CrossAccountId::from_eth(to);789 let to = T::CrossAccountId::from_eth(to);
795 let token = token_id.try_into()?;790 let token = token_id.try_into()?;
811 &mut self,806 &mut self,
812 caller: caller,807 caller: caller,
813 to: eth::CrossAddress,808 to: eth::CrossAddress,
814 token_id: uint256,809 token_id: U256,
815 ) -> Result<()> {810 ) -> Result<()> {
816 let caller = T::CrossAccountId::from_eth(caller);811 let caller = T::CrossAccountId::from_eth(caller);
817 let to = to.into_sub_cross_account::<T>()?;812 let to = to.into_sub_cross_account::<T>()?;
836 caller: caller,831 caller: caller,
837 from: eth::CrossAddress,832 from: eth::CrossAddress,
838 to: eth::CrossAddress,833 to: eth::CrossAddress,
839 token_id: uint256,834 token_id: U256,
840 ) -> Result<()> {835 ) -> Result<()> {
841 let caller = T::CrossAccountId::from_eth(caller);836 let caller = T::CrossAccountId::from_eth(caller);
842 let from = from.into_sub_cross_account::<T>()?;837 let from = from.into_sub_cross_account::<T>()?;
858 /// @param tokenId The NFT to transfer853 /// @param tokenId The NFT to transfer
859 #[solidity(hide)]854 #[solidity(hide)]
860 #[weight(<SelfWeightOf<T>>::burn_from())]855 #[weight(<SelfWeightOf<T>>::burn_from())]
861 fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<()> {856 fn burn_from(&mut self, caller: caller, from: address, token_id: U256) -> Result<()> {
862 let caller = T::CrossAccountId::from_eth(caller);857 let caller = T::CrossAccountId::from_eth(caller);
863 let from = T::CrossAccountId::from_eth(from);858 let from = T::CrossAccountId::from_eth(from);
864 let token = token_id.try_into()?;859 let token = token_id.try_into()?;
882 &mut self,877 &mut self,
883 caller: caller,878 caller: caller,
884 from: eth::CrossAddress,879 from: eth::CrossAddress,
885 token_id: uint256,880 token_id: U256,
886 ) -> Result<()> {881 ) -> Result<()> {
887 let caller = T::CrossAccountId::from_eth(caller);882 let caller = T::CrossAccountId::from_eth(caller);
888 let from = from.into_sub_cross_account::<T>()?;883 let from = from.into_sub_cross_account::<T>()?;
897 }892 }
898893
899 /// @notice Returns next free NFT ID.894 /// @notice Returns next free NFT ID.
900 fn next_token_id(&self) -> Result<uint256> {895 fn next_token_id(&self) -> Result<U256> {
901 self.consume_store_reads(1)?;896 self.consume_store_reads(1)?;
902 Ok(<TokensMinted<T>>::get(self.id)897 Ok(<TokensMinted<T>>::get(self.id)
903 .checked_add(1)898 .checked_add(1)
912 /// @param tokenIds IDs of the minted NFTs907 /// @param tokenIds IDs of the minted NFTs
913 #[solidity(hide)]908 #[solidity(hide)]
914 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]909 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]
915 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {910 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<U256>) -> Result<bool> {
916 let caller = T::CrossAccountId::from_eth(caller);911 let caller = T::CrossAccountId::from_eth(caller);
917 let to = T::CrossAccountId::from_eth(to);912 let to = T::CrossAccountId::from_eth(to);
918 let mut expected_index = <TokensMinted<T>>::get(self.id)913 let mut expected_index = <TokensMinted<T>>::get(self.id)
953 &mut self,948 &mut self,
954 caller: caller,949 caller: caller,
955 to: address,950 to: address,
956 tokens: Vec<(uint256, string)>,951 tokens: Vec<(U256, string)>,
957 ) -> Result<bool> {952 ) -> Result<bool> {
958 let key = key::url();953 let key = key::url();
959 let caller = T::CrossAccountId::from_eth(caller);954 let caller = T::CrossAccountId::from_eth(caller);
1005 caller: caller,1000 caller: caller,
1006 to: eth::CrossAddress,1001 to: eth::CrossAddress,
1007 properties: Vec<eth::Property>,1002 properties: Vec<eth::Property>,
1008 ) -> Result<uint256> {1003 ) -> Result<U256> {
1009 let token_id = <TokensMinted<T>>::get(self.id)1004 let token_id = <TokensMinted<T>>::get(self.id)
1010 .checked_add(1)1005 .checked_add(1)
1011 .ok_or("item id overflow")?;1006 .ok_or("item id overflow")?;
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
39use pallet_evm::{account::CrossAccountId, PrecompileHandle};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};
40use pallet_evm_coder_substrate::{call, dispatch_to_evm};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};
41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
42use sp_core::{H160, Get};42use sp_core::{H160, U256, Get};
43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};
44use up_data_structs::{44use up_data_structs::{
45 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,45 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,
125 fn set_property(125 fn set_property(
126 &mut self,126 &mut self,
127 caller: caller,127 caller: caller,
128 token_id: uint256,128 token_id: U256,
129 key: string,129 key: string,
130 value: bytes,130 value: bytes,
131 ) -> Result<()> {131 ) -> Result<()> {
158 fn set_properties(158 fn set_properties(
159 &mut self,159 &mut self,
160 caller: caller,160 caller: caller,
161 token_id: uint256,161 token_id: U256,
162 properties: Vec<eth::Property>,162 properties: Vec<eth::Property>,
163 ) -> Result<()> {163 ) -> Result<()> {
164 let caller = T::CrossAccountId::from_eth(caller);164 let caller = T::CrossAccountId::from_eth(caller);
190 /// @param key Property key.190 /// @param key Property key.
191 #[solidity(hide)]191 #[solidity(hide)]
192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
193 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {193 fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {
194 let caller = T::CrossAccountId::from_eth(caller);194 let caller = T::CrossAccountId::from_eth(caller);
195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
196 let key = <Vec<u8>>::from(key)196 let key = <Vec<u8>>::from(key)
212 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]212 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]
213 fn delete_properties(213 fn delete_properties(
214 &mut self,214 &mut self,
215 token_id: uint256,215 token_id: U256,
216 caller: caller,216 caller: caller,
217 keys: Vec<string>,217 keys: Vec<string>,
218 ) -> Result<()> {218 ) -> Result<()> {
242 /// @param tokenId ID of the token.242 /// @param tokenId ID of the token.
243 /// @param key Property key.243 /// @param key Property key.
244 /// @return Property value bytes244 /// @return Property value bytes
245 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {245 fn property(&self, token_id: U256, key: string) -> Result<bytes> {
246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
247 let key = <Vec<u8>>::from(key)247 let key = <Vec<u8>>::from(key)
248 .try_into()248 .try_into()
266 #[indexed]266 #[indexed]
267 to: address,267 to: address,
268 #[indexed]268 #[indexed]
269 token_id: uint256,269 token_id: U256,
270 },270 },
271 /// @dev Not supported271 /// @dev Not supported
272 Approval {272 Approval {
275 #[indexed]275 #[indexed]
276 approved: address,276 approved: address,
277 #[indexed]277 #[indexed]
278 token_id: uint256,278 token_id: U256,
279 },279 },
280 /// @dev Not supported280 /// @dev Not supported
281 #[allow(dead_code)]281 #[allow(dead_code)]
319 ///319 ///
320 /// @return token's const_metadata320 /// @return token's const_metadata
321 #[solidity(rename_selector = "tokenURI")]321 #[solidity(rename_selector = "tokenURI")]
322 fn token_uri(&self, token_id: uint256) -> Result<string> {322 fn token_uri(&self, token_id: U256) -> Result<string> {
323 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;323 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
324324
325 match get_token_property(self, token_id_u32, &key::url()).as_deref() {325 match get_token_property(self, token_id_u32, &key::url()).as_deref() {
365 /// @param index A counter less than `totalSupply()`365 /// @param index A counter less than `totalSupply()`
366 /// @return The token identifier for the `index`th NFT,366 /// @return The token identifier for the `index`th NFT,
367 /// (sort order not specified)367 /// (sort order not specified)
368 fn token_by_index(&self, index: uint256) -> Result<uint256> {368 fn token_by_index(&self, index: U256) -> Result<U256> {
369 Ok(index)369 Ok(index)
370 }370 }
371371
372 /// Not implemented372 /// Not implemented
373 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {373 fn token_of_owner_by_index(&self, _owner: address, _index: U256) -> Result<U256> {
374 // TODO: Not implemetable374 // TODO: Not implemetable
375 Err("not implemented".into())375 Err("not implemented".into())
376 }376 }
377377
378 /// @notice Count RFTs tracked by this contract378 /// @notice Count RFTs tracked by this contract
379 /// @return A count of valid RFTs tracked by this contract, where each one of379 /// @return A count of valid RFTs tracked by this contract, where each one of
380 /// them has an assigned and queryable owner not equal to the zero address380 /// them has an assigned and queryable owner not equal to the zero address
381 fn total_supply(&self) -> Result<uint256> {381 fn total_supply(&self) -> Result<U256> {
382 self.consume_store_reads(1)?;382 self.consume_store_reads(1)?;
383 Ok(<Pallet<T>>::total_supply(self).into())383 Ok(<Pallet<T>>::total_supply(self).into())
384 }384 }
393 /// function throws for queries about the zero address.393 /// function throws for queries about the zero address.
394 /// @param owner An address for whom to query the balance394 /// @param owner An address for whom to query the balance
395 /// @return The number of RFTs owned by `owner`, possibly zero395 /// @return The number of RFTs owned by `owner`, possibly zero
396 fn balance_of(&self, owner: address) -> Result<uint256> {396 fn balance_of(&self, owner: address) -> Result<U256> {
397 self.consume_store_reads(1)?;397 self.consume_store_reads(1)?;
398 let owner = T::CrossAccountId::from_eth(owner);398 let owner = T::CrossAccountId::from_eth(owner);
399 let balance = <AccountBalance<T>>::get((self.id, owner));399 let balance = <AccountBalance<T>>::get((self.id, owner));
407 /// the tokens that are partially owned.407 /// the tokens that are partially owned.
408 /// @param tokenId The identifier for an RFT408 /// @param tokenId The identifier for an RFT
409 /// @return The address of the owner of the RFT409 /// @return The address of the owner of the RFT
410 fn owner_of(&self, token_id: uint256) -> Result<address> {410 fn owner_of(&self, token_id: U256) -> Result<address> {
411 self.consume_store_reads(2)?;411 self.consume_store_reads(2)?;
412 let token = token_id.try_into()?;412 let token = token_id.try_into()?;
413 let owner = <Pallet<T>>::token_owner(self.id, token);413 let owner = <Pallet<T>>::token_owner(self.id, token);
422 &mut self,422 &mut self,
423 _from: address,423 _from: address,
424 _to: address,424 _to: address,
425 _token_id: uint256,425 _token_id: U256,
426 _data: bytes,426 _data: bytes,
427 ) -> Result<()> {427 ) -> Result<()> {
428 // TODO: Not implemetable428 // TODO: Not implemetable
431431
432 /// @dev Not implemented432 /// @dev Not implemented
433 #[solidity(rename_selector = "safeTransferFrom")]433 #[solidity(rename_selector = "safeTransferFrom")]
434 fn safe_transfer_from(434 fn safe_transfer_from(&mut self, _from: address, _to: address, _token_id: U256) -> Result<()> {
435 &mut self,
436 _from: address,
437 _to: address,
438 _token_id: uint256,
439 ) -> Result<()> {
440 // TODO: Not implemetable435 // TODO: Not implemetable
441 Err("not implemented".into())436 Err("not implemented".into())
457 caller: caller,452 caller: caller,
458 from: address,453 from: address,
459 to: address,454 to: address,
460 token_id: uint256,455 token_id: U256,
461 ) -> Result<()> {456 ) -> Result<()> {
462 let caller = T::CrossAccountId::from_eth(caller);457 let caller = T::CrossAccountId::from_eth(caller);
463 let from = T::CrossAccountId::from_eth(from);458 let from = T::CrossAccountId::from_eth(from);
477 }472 }
478473
479 /// @dev Not implemented474 /// @dev Not implemented
480 fn approve(&mut self, _caller: caller, _approved: address, _token_id: uint256) -> Result<()> {475 fn approve(&mut self, _caller: caller, _approved: address, _token_id: U256) -> Result<()> {
481 Err("not implemented".into())476 Err("not implemented".into())
482 }477 }
483478
501 }496 }
502497
503 /// @dev Not implemented498 /// @dev Not implemented
504 fn get_approved(&self, _token_id: uint256) -> Result<address> {499 fn get_approved(&self, _token_id: U256) -> Result<address> {
505 // TODO: Not implemetable500 // TODO: Not implemetable
506 Err("not implemented".into())501 Err("not implemented".into())
507 }502 }
556 /// operator of the current owner.551 /// operator of the current owner.
557 /// @param tokenId The RFT to approve552 /// @param tokenId The RFT to approve
558 #[weight(<SelfWeightOf<T>>::burn_item_fully())]553 #[weight(<SelfWeightOf<T>>::burn_item_fully())]
559 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<()> {554 fn burn(&mut self, caller: caller, token_id: U256) -> Result<()> {
560 let caller = T::CrossAccountId::from_eth(caller);555 let caller = T::CrossAccountId::from_eth(caller);
561 let token = token_id.try_into()?;556 let token = token_id.try_into()?;
562557
575 /// @param to The new owner570 /// @param to The new owner
576 /// @return uint256 The id of the newly minted token571 /// @return uint256 The id of the newly minted token
577 #[weight(<SelfWeightOf<T>>::create_item())]572 #[weight(<SelfWeightOf<T>>::create_item())]
578 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {573 fn mint(&mut self, caller: caller, to: address) -> Result<U256> {
579 let token_id: uint256 = <TokensMinted<T>>::get(self.id)574 let token_id: U256 = <TokensMinted<T>>::get(self.id)
580 .checked_add(1)575 .checked_add(1)
581 .ok_or("item id overflow")?576 .ok_or("item id overflow")?
582 .into();577 .into();
591 /// @param tokenId ID of the minted RFT586 /// @param tokenId ID of the minted RFT
592 #[solidity(hide, rename_selector = "mint")]587 #[solidity(hide, rename_selector = "mint")]
593 #[weight(<SelfWeightOf<T>>::create_item())]588 #[weight(<SelfWeightOf<T>>::create_item())]
594 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {589 fn mint_check_id(&mut self, caller: caller, to: address, token_id: U256) -> Result<bool> {
595 let caller = T::CrossAccountId::from_eth(caller);590 let caller = T::CrossAccountId::from_eth(caller);
596 let to = T::CrossAccountId::from_eth(to);591 let to = T::CrossAccountId::from_eth(to);
597 let token_id: u32 = token_id.try_into()?;592 let token_id: u32 = token_id.try_into()?;
637 caller: caller,632 caller: caller,
638 to: address,633 to: address,
639 token_uri: string,634 token_uri: string,
640 ) -> Result<uint256> {635 ) -> Result<U256> {
641 let token_id: uint256 = <TokensMinted<T>>::get(self.id)636 let token_id: U256 = <TokensMinted<T>>::get(self.id)
642 .checked_add(1)637 .checked_add(1)
643 .ok_or("item id overflow")?638 .ok_or("item id overflow")?
644 .into();639 .into();
658 &mut self,653 &mut self,
659 caller: caller,654 caller: caller,
660 to: address,655 to: address,
661 token_id: uint256,656 token_id: U256,
662 token_uri: string,657 token_uri: string,
663 ) -> Result<bool> {658 ) -> Result<bool> {
664 let key = key::url();659 let key = key::url();
768 /// Returns the owner (in cross format) of the token.763 /// Returns the owner (in cross format) of the token.
769 ///764 ///
770 /// @param tokenId Id for the token.765 /// @param tokenId Id for the token.
771 fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {766 fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {
772 Self::token_owner(&self, token_id.try_into()?)767 Self::token_owner(&self, token_id.try_into()?)
773 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))768 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
774 .ok_or(Error::Revert("key too large".into()))769 .ok_or(Error::Revert("key too large".into()))
779 /// @param tokenId Id for the token.774 /// @param tokenId Id for the token.
780 /// @param keys Properties keys. Empty keys for all propertyes.775 /// @param keys Properties keys. Empty keys for all propertyes.
781 /// @return Vector of properties key/value pairs.776 /// @return Vector of properties key/value pairs.
782 fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {777 fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
783 let keys = keys778 let keys = keys
784 .into_iter()779 .into_iter()
785 .map(|key| {780 .map(|key| {
805 /// @param to The new owner800 /// @param to The new owner
806 /// @param tokenId The RFT to transfer801 /// @param tokenId The RFT to transfer
807 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]802 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]
808 fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<()> {803 fn transfer(&mut self, caller: caller, to: address, token_id: U256) -> Result<()> {
809 let caller = T::CrossAccountId::from_eth(caller);804 let caller = T::CrossAccountId::from_eth(caller);
810 let to = T::CrossAccountId::from_eth(to);805 let to = T::CrossAccountId::from_eth(to);
811 let token = token_id.try_into()?;806 let token = token_id.try_into()?;
832 &mut self,827 &mut self,
833 caller: caller,828 caller: caller,
834 to: eth::CrossAddress,829 to: eth::CrossAddress,
835 token_id: uint256,830 token_id: U256,
836 ) -> Result<()> {831 ) -> Result<()> {
837 let caller = T::CrossAccountId::from_eth(caller);832 let caller = T::CrossAccountId::from_eth(caller);
838 let to = to.into_sub_cross_account::<T>()?;833 let to = to.into_sub_cross_account::<T>()?;
861 caller: caller,856 caller: caller,
862 from: eth::CrossAddress,857 from: eth::CrossAddress,
863 to: eth::CrossAddress,858 to: eth::CrossAddress,
864 token_id: uint256,859 token_id: U256,
865 ) -> Result<()> {860 ) -> Result<()> {
866 let caller = T::CrossAccountId::from_eth(caller);861 let caller = T::CrossAccountId::from_eth(caller);
867 let from = from.into_sub_cross_account::<T>()?;862 let from = from.into_sub_cross_account::<T>()?;
888 /// @param tokenId The RFT to transfer883 /// @param tokenId The RFT to transfer
889 #[solidity(hide)]884 #[solidity(hide)]
890 #[weight(<SelfWeightOf<T>>::burn_from())]885 #[weight(<SelfWeightOf<T>>::burn_from())]
891 fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<()> {886 fn burn_from(&mut self, caller: caller, from: address, token_id: U256) -> Result<()> {
892 let caller = T::CrossAccountId::from_eth(caller);887 let caller = T::CrossAccountId::from_eth(caller);
893 let from = T::CrossAccountId::from_eth(from);888 let from = T::CrossAccountId::from_eth(from);
894 let token = token_id.try_into()?;889 let token = token_id.try_into()?;
916 &mut self,911 &mut self,
917 caller: caller,912 caller: caller,
918 from: eth::CrossAddress,913 from: eth::CrossAddress,
919 token_id: uint256,914 token_id: U256,
920 ) -> Result<()> {915 ) -> Result<()> {
921 let caller = T::CrossAccountId::from_eth(caller);916 let caller = T::CrossAccountId::from_eth(caller);
922 let from = from.into_sub_cross_account::<T>()?;917 let from = from.into_sub_cross_account::<T>()?;
934 }929 }
935930
936 /// @notice Returns next free RFT ID.931 /// @notice Returns next free RFT ID.
937 fn next_token_id(&self) -> Result<uint256> {932 fn next_token_id(&self) -> Result<U256> {
938 self.consume_store_reads(1)?;933 self.consume_store_reads(1)?;
939 Ok(<TokensMinted<T>>::get(self.id)934 Ok(<TokensMinted<T>>::get(self.id)
940 .checked_add(1)935 .checked_add(1)
949 /// @param tokenIds IDs of the minted RFTs944 /// @param tokenIds IDs of the minted RFTs
950 #[solidity(hide)]945 #[solidity(hide)]
951 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]946 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]
952 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {947 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<U256>) -> Result<bool> {
953 let caller = T::CrossAccountId::from_eth(caller);948 let caller = T::CrossAccountId::from_eth(caller);
954 let to = T::CrossAccountId::from_eth(to);949 let to = T::CrossAccountId::from_eth(to);
955 let mut expected_index = <TokensMinted<T>>::get(self.id)950 let mut expected_index = <TokensMinted<T>>::get(self.id)
996 &mut self,991 &mut self,
997 caller: caller,992 caller: caller,
998 to: address,993 to: address,
999 tokens: Vec<(uint256, string)>,994 tokens: Vec<(U256, string)>,
1000 ) -> Result<bool> {995 ) -> Result<bool> {
1001 let key = key::url();996 let key = key::url();
1002 let caller = T::CrossAccountId::from_eth(caller);997 let caller = T::CrossAccountId::from_eth(caller);
1054 caller: caller,1049 caller: caller,
1055 to: eth::CrossAddress,1050 to: eth::CrossAddress,
1056 properties: Vec<eth::Property>,1051 properties: Vec<eth::Property>,
1057 ) -> Result<uint256> {1052 ) -> Result<U256> {
1058 let token_id = <TokensMinted<T>>::get(self.id)1053 let token_id = <TokensMinted<T>>::get(self.id)
1059 .checked_add(1)1054 .checked_add(1)
1060 .ok_or("item id overflow")?;1055 .ok_or("item id overflow")?;
1093 /// Returns EVM address for refungible token1088 /// Returns EVM address for refungible token
1094 ///1089 ///
1095 /// @param token ID of the token1090 /// @param token ID of the token
1096 fn token_contract_address(&self, token: uint256) -> Result<address> {1091 fn token_contract_address(&self, token: U256) -> Result<address> {
1097 Ok(T::EvmTokenAddressMapping::token_to_address(1092 Ok(T::EvmTokenAddressMapping::token_to_address(
1098 self.id,1093 self.id,
1099 token.try_into().map_err(|_| "token id overflow")?,1094 token.try_into().map_err(|_| "token id overflow")?,
modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
37use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};37use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};
38use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};38use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
39use sp_std::vec::Vec;39use sp_std::vec::Vec;
40use sp_core::U256;
40use up_data_structs::TokenId;41use up_data_structs::TokenId;
4142
42use crate::{43use crate::{
55 Ok(collection_id_to_address(self.id))56 Ok(collection_id_to_address(self.id))
56 }57 }
5758
58 fn parent_token_id(&self) -> Result<uint256> {59 fn parent_token_id(&self) -> Result<U256> {
59 Ok(self.1.into())60 Ok(self.1.into())
60 }61 }
61}62}
71 from: address,72 from: address,
72 #[indexed]73 #[indexed]
73 to: address,74 to: address,
74 value: uint256,75 value: U256,
75 },76 },
76 /// @dev This event is emitted when the amount of tokens (value) is approved77 /// @dev This event is emitted when the amount of tokens (value) is approved
77 /// by the owner to be used by the spender.78 /// by the owner to be used by the spender.
80 owner: address,81 owner: address,
81 #[indexed]82 #[indexed]
82 spender: address,83 spender: address,
83 value: uint256,84 value: U256,
84 },85 },
85}86}
8687
103 }104 }
104105
105 /// @dev Total number of tokens in existence106 /// @dev Total number of tokens in existence
106 fn total_supply(&self) -> Result<uint256> {107 fn total_supply(&self) -> Result<U256> {
107 self.consume_store_reads(1)?;108 self.consume_store_reads(1)?;
108 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())109 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())
109 }110 }
117 /// @dev Gets the balance of the specified address.118 /// @dev Gets the balance of the specified address.
118 /// @param owner The address to query the balance of.119 /// @param owner The address to query the balance of.
119 /// @return An uint256 representing the amount owned by the passed address.120 /// @return An uint256 representing the amount owned by the passed address.
120 fn balance_of(&self, owner: address) -> Result<uint256> {121 fn balance_of(&self, owner: address) -> Result<U256> {
121 self.consume_store_reads(1)?;122 self.consume_store_reads(1)?;
122 let owner = T::CrossAccountId::from_eth(owner);123 let owner = T::CrossAccountId::from_eth(owner);
123 let balance = <Balance<T>>::get((self.id, self.1, owner));124 let balance = <Balance<T>>::get((self.id, self.1, owner));
128 /// @param to The address to transfer to.129 /// @param to The address to transfer to.
129 /// @param amount The amount to be transferred.130 /// @param amount The amount to be transferred.
130 #[weight(<CommonWeights<T>>::transfer())]131 #[weight(<CommonWeights<T>>::transfer())]
131 fn transfer(&mut self, caller: caller, to: address, amount: uint256) -> Result<bool> {132 fn transfer(&mut self, caller: caller, to: address, amount: U256) -> Result<bool> {
132 let caller = T::CrossAccountId::from_eth(caller);133 let caller = T::CrossAccountId::from_eth(caller);
133 let to = T::CrossAccountId::from_eth(to);134 let to = T::CrossAccountId::from_eth(to);
134 let amount = amount.try_into().map_err(|_| "amount overflow")?;135 let amount = amount.try_into().map_err(|_| "amount overflow")?;
151 caller: caller,152 caller: caller,
152 from: address,153 from: address,
153 to: address,154 to: address,
154 amount: uint256,155 amount: U256,
155 ) -> Result<bool> {156 ) -> Result<bool> {
156 let caller = T::CrossAccountId::from_eth(caller);157 let caller = T::CrossAccountId::from_eth(caller);
157 let from = T::CrossAccountId::from_eth(from);158 let from = T::CrossAccountId::from_eth(from);
174 /// @param spender The address which will spend the funds.175 /// @param spender The address which will spend the funds.
175 /// @param amount The amount of tokens to be spent.176 /// @param amount The amount of tokens to be spent.
176 #[weight(<SelfWeightOf<T>>::approve())]177 #[weight(<SelfWeightOf<T>>::approve())]
177 fn approve(&mut self, caller: caller, spender: address, amount: uint256) -> Result<bool> {178 fn approve(&mut self, caller: caller, spender: address, amount: U256) -> Result<bool> {
178 let caller = T::CrossAccountId::from_eth(caller);179 let caller = T::CrossAccountId::from_eth(caller);
179 let spender = T::CrossAccountId::from_eth(spender);180 let spender = T::CrossAccountId::from_eth(spender);
180 let amount = amount.try_into().map_err(|_| "amount overflow")?;181 let amount = amount.try_into().map_err(|_| "amount overflow")?;
188 /// @param owner address The address which owns the funds.189 /// @param owner address The address which owns the funds.
189 /// @param spender address The address which will spend the funds.190 /// @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 /// @return A uint256 specifying the amount of tokens still available for the spender.
191 fn allowance(&self, owner: address, spender: address) -> Result<uint256> {192 fn allowance(&self, owner: address, spender: address) -> Result<U256> {
192 self.consume_store_reads(1)?;193 self.consume_store_reads(1)?;
193 let owner = T::CrossAccountId::from_eth(owner);194 let owner = T::CrossAccountId::from_eth(owner);
194 let spender = T::CrossAccountId::from_eth(spender);195 let spender = T::CrossAccountId::from_eth(spender);
208 /// @param amount The amount that will be burnt.209 /// @param amount The amount that will be burnt.
209 #[weight(<SelfWeightOf<T>>::burn_from())]210 #[weight(<SelfWeightOf<T>>::burn_from())]
210 #[solidity(hide)]211 #[solidity(hide)]
211 fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {212 fn burn_from(&mut self, caller: caller, from: address, amount: U256) -> Result<bool> {
212 let caller = T::CrossAccountId::from_eth(caller);213 let caller = T::CrossAccountId::from_eth(caller);
213 let from = T::CrossAccountId::from_eth(from);214 let from = T::CrossAccountId::from_eth(from);
214 let amount = amount.try_into().map_err(|_| "amount overflow")?;215 let amount = amount.try_into().map_err(|_| "amount overflow")?;
230 &mut self,231 &mut self,
231 caller: caller,232 caller: caller,
232 from: pallet_common::eth::CrossAddress,233 from: pallet_common::eth::CrossAddress,
233 amount: uint256,234 amount: U256,
234 ) -> Result<bool> {235 ) -> Result<bool> {
235 let caller = T::CrossAccountId::from_eth(caller);236 let caller = T::CrossAccountId::from_eth(caller);
236 let from = from.into_sub_cross_account::<T>()?;237 let from = from.into_sub_cross_account::<T>()?;
256 &mut self,257 &mut self,
257 caller: caller,258 caller: caller,
258 spender: pallet_common::eth::CrossAddress,259 spender: pallet_common::eth::CrossAddress,
259 amount: uint256,260 amount: U256,
260 ) -> Result<bool> {261 ) -> Result<bool> {
261 let caller = T::CrossAccountId::from_eth(caller);262 let caller = T::CrossAccountId::from_eth(caller);
262 let spender = spender.into_sub_cross_account::<T>()?;263 let spender = spender.into_sub_cross_account::<T>()?;
270 /// Throws if `msg.sender` doesn't owns all of the tokens.271 /// Throws if `msg.sender` doesn't owns all of the tokens.
271 /// @param amount New total amount of the tokens.272 /// @param amount New total amount of the tokens.
272 #[weight(<SelfWeightOf<T>>::repartition_item())]273 #[weight(<SelfWeightOf<T>>::repartition_item())]
273 fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {274 fn repartition(&mut self, caller: caller, amount: U256) -> Result<bool> {
274 let caller = T::CrossAccountId::from_eth(caller);275 let caller = T::CrossAccountId::from_eth(caller);
275 let amount = amount.try_into().map_err(|_| "amount overflow")?;276 let amount = amount.try_into().map_err(|_| "amount overflow")?;
276277
286 &mut self,287 &mut self,
287 caller: caller,288 caller: caller,
288 to: pallet_common::eth::CrossAddress,289 to: pallet_common::eth::CrossAddress,
289 amount: uint256,290 amount: U256,
290 ) -> Result<bool> {291 ) -> Result<bool> {
291 let caller = T::CrossAccountId::from_eth(caller);292 let caller = T::CrossAccountId::from_eth(caller);
292 let to = to.into_sub_cross_account::<T>()?;293 let to = to.into_sub_cross_account::<T>()?;
310 caller: caller,311 caller: caller,
311 from: pallet_common::eth::CrossAddress,312 from: pallet_common::eth::CrossAddress,
312 to: pallet_common::eth::CrossAddress,313 to: pallet_common::eth::CrossAddress,
313 amount: uint256,314 amount: U256,
314 ) -> Result<bool> {315 ) -> Result<bool> {
315 let caller = T::CrossAccountId::from_eth(caller);316 let caller = T::CrossAccountId::from_eth(caller);
316 let from = from.into_sub_cross_account::<T>()?;317 let from = from.into_sub_cross_account::<T>()?;
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
49 "name": "ApprovalForAll",49 "name": "ApprovalForAll",
50 "type": "event"50 "type": "event"
51 },51 },
52 {
53 "anonymous": false,
54 "inputs": [],
55 "name": "MintingFinished",
56 "type": "event"
57 },
52 {58 {
53 "anonymous": false,59 "anonymous": false,
54 "inputs": [60 "inputs": [
416 "stateMutability": "view",422 "stateMutability": "view",
417 "type": "function"423 "type": "function"
418 },424 },
425 {
426 "inputs": [],
427 "name": "finishMinting",
428 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
429 "stateMutability": "nonpayable",
430 "type": "function"
431 },
419 {432 {
420 "inputs": [433 "inputs": [
421 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }434 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
502 "stateMutability": "nonpayable",515 "stateMutability": "nonpayable",
503 "type": "function"516 "type": "function"
504 },517 },
518 {
519 "inputs": [],
520 "name": "mintingFinished",
521 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
522 "stateMutability": "view",
523 "type": "function"
524 },
505 {525 {
506 "inputs": [],526 "inputs": [],
507 "name": "name",527 "name": "name",
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
49 "name": "ApprovalForAll",49 "name": "ApprovalForAll",
50 "type": "event"50 "type": "event"
51 },51 },
52 {
53 "anonymous": false,
54 "inputs": [],
55 "name": "MintingFinished",
56 "type": "event"
57 },
52 {58 {
53 "anonymous": false,59 "anonymous": false,
54 "inputs": [60 "inputs": [
398 "stateMutability": "view",404 "stateMutability": "view",
399 "type": "function"405 "type": "function"
400 },406 },
407 {
408 "inputs": [],
409 "name": "finishMinting",
410 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
411 "stateMutability": "nonpayable",
412 "type": "function"
413 },
401 {414 {
402 "inputs": [415 "inputs": [
403 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }416 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
484 "stateMutability": "nonpayable",497 "stateMutability": "nonpayable",
485 "type": "function"498 "type": "function"
486 },499 },
500 {
501 "inputs": [],
502 "name": "mintingFinished",
503 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
504 "stateMutability": "view",
505 "type": "function"
506 },
487 {507 {
488 "inputs": [],508 "inputs": [],
489 "name": "name",509 "name": "name",
modifiedtests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth
96 "stateMutability": "view",96 "stateMutability": "view",
97 "type": "function"97 "type": "function"
98 },98 },
99 {
100 "inputs": [
101 { "internalType": "address", "name": "from", "type": "address" },
102 { "internalType": "uint256", "name": "amount", "type": "uint256" }
103 ],
104 "name": "burnFrom",
105 "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
106 "stateMutability": "nonpayable",
107 "type": "function"
108 },
99 {109 {
100 "inputs": [110 "inputs": [
101 {111 {