difftreelog
chore generate stubs & types
in: master
11 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6342,7 +6342,7 @@
[[package]]
name = "pallet-nonfungible"
-version = "0.1.11"
+version = "0.1.12"
dependencies = [
"ethereum 0.14.0",
"evm-coder",
@@ -6501,7 +6501,7 @@
[[package]]
name = "pallet-refungible"
-version = "0.2.10"
+version = "0.2.11"
dependencies = [
"derivative",
"ethereum 0.14.0",
pallets/nonfungible/Cargo.tomldiffbeforeafterboth--- a/pallets/nonfungible/Cargo.toml
+++ b/pallets/nonfungible/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pallet-nonfungible"
-version = "0.1.11"
+version = "0.1.12"
license = "GPLv3"
edition = "2021"
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -42,7 +42,11 @@
/// @param permissions Permissions for keys.
/// @dev EVM selector for this function is: 0xbd92983a,
/// or in textual repr: setTokenPropertyPermissions((string,(uint8,bool)[])[])
+<<<<<<< HEAD
function setTokenPropertyPermissions(Tuple59[] memory permissions) public {
+=======
+ function setTokenPropertyPermissions(Tuple56[] memory permissions) public {
+>>>>>>> 9e929f90... chore: generate stubs & types
require(false, stub_error);
permissions;
dummy = 0;
@@ -51,10 +55,17 @@
/// @notice Get permissions for token properties.
/// @dev EVM selector for this function is: 0xf23d7790,
/// or in textual repr: tokenPropertyPermissions()
+<<<<<<< HEAD
function tokenPropertyPermissions() public view returns (Tuple59[] memory) {
require(false, stub_error);
dummy;
return new Tuple59[](0);
+=======
+ function tokenPropertyPermissions() public view returns (Tuple56[] memory) {
+ require(false, stub_error);
+ dummy;
+ return new Tuple56[](0);
+>>>>>>> 9e929f90... chore: generate stubs & types
}
// /// @notice Set token property value.
@@ -144,6 +155,7 @@
}
/// @dev anonymous struct
+<<<<<<< HEAD
struct Tuple59 {
string field_0;
Tuple57[] field_1;
@@ -151,6 +163,15 @@
/// @dev anonymous struct
struct Tuple57 {
+=======
+struct Tuple56 {
+ string field_0;
+ Tuple54[] field_1;
+}
+
+/// @dev anonymous struct
+struct Tuple54 {
+>>>>>>> 9e929f90... chore: generate stubs & types
EthTokenPermissions field_0;
bool field_1;
}
pallets/refungible/Cargo.tomldiffbeforeafterboth--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pallet-refungible"
-version = "0.2.10"
+version = "0.2.11"
license = "GPLv3"
edition = "2021"
pallets/refungible/src/lib.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 Pallet18//!19//! The Refungible pallet provides functionality for handling refungible collections and tokens.20//!21//! - [`Config`]22//! - [`RefungibleHandle`]23//! - [`Pallet`]24//! - [`CommonWeights`](common::CommonWeights)25//!26//! ## Overview27//!28//! The Refungible pallet provides functions for:29//!30//! - RFT collection creation and removal31//! - Minting and burning of RFT tokens32//! - Partition and repartition of RFT tokens33//! - Retrieving number of pieces of RFT token34//! - Retrieving account balances35//! - Transfering RFT token pieces36//! - Burning RFT token pieces37//! - Setting and checking allowance for RFT tokens38//!39//! ### Terminology40//!41//! - **RFT token:** Non fungible token that was partitioned to pieces. If an account owns all42//! of the RFT token pieces than it owns the RFT token and can repartition it.43//!44//! - **RFT Collection:** A collection of RFT tokens. All RFT tokens are part of a collection.45//! Each collection has its own settings and set of permissions.46//!47//! - **RFT token piece:** A fungible part of an RFT token.48//!49//! - **Balance:** RFT token pieces owned by an account50//!51//! - **Allowance:** Maximum number of RFT token pieces that one account is allowed to52//! transfer from the balance of another account53//!54//! - **Burning:** The process of “deleting” a token from a collection or removing token pieces from55//! an account balance.56//!57//! ### Implementations58//!59//! The Refungible pallet provides implementations for the following traits. If these traits provide60//! the functionality that you need, then you can avoid coupling with the Refungible pallet.61//!62//! - [`CommonWeightInfo`](pallet_common::CommonWeightInfo): Functions for retrieval of transaction weight63//! - [`CommonCollectionOperations`](pallet_common::CommonCollectionOperations): Functions for dealing64//! with collections65//! - [`RefungibleExtensions`](pallet_common::RefungibleExtensions): Functions specific for refungible66//! collection67//!68//! ## Interface69//!70//! ### Dispatchable Functions71//!72//! - `init_collection` - Create RFT collection. RFT collection can be configured to allow or deny access for73//! some accounts.74//! - `destroy_collection` - Destroy exising RFT collection. There should be no tokens in the collection.75//! - `burn` - Burn some amount of RFT token pieces owned by account. Burns the RFT token if no pieces left.76//! - `transfer` - Transfer some amount of RFT token pieces. Transfers should be enabled for RFT collection.77//! Nests the RFT token if RFT token pieces are sent to another token.78//! - `create_item` - Mint RFT token in collection. Sender should have permission to mint tokens.79//! - `set_allowance` - Set allowance for another account to transfer balance from sender's account.80//! - `repartition` - Repartition token to selected number of pieces. Sender should own all existing pieces.81//!82//! ## Assumptions83//!84//! * Total number of pieces for one token shouldn't exceed `up_data_structs::MAX_REFUNGIBLE_PIECES`.85//! * Total number of tokens of all types shouldn't be greater than `up_data_structs::MAX_TOKEN_PREFIX_LENGTH`.86//! * Sender should be in collection's allow list to perform operations on tokens.8788#![cfg_attr(not(feature = "std"), no_std)]8990use crate::erc_token::ERC20Events;91use crate::erc::ERC721Events;9293use codec::{Encode, Decode, MaxEncodedLen};94use core::ops::Deref;95use derivative::Derivative;96use evm_coder::ToLog;97use frame_support::{98 BoundedBTreeMap, BoundedVec, ensure, fail, storage::with_transaction, transactional,99 pallet_prelude::ConstU32,100};101use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};102use pallet_evm_coder_substrate::WithRecorder;103use pallet_common::{104 CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,105 Event as CommonEvent, Pallet as PalletCommon, erc::CollectionHelpersEvents,106};107use pallet_structure::Pallet as PalletStructure;108use scale_info::TypeInfo;109use sp_core::{Get, H160};110use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};111use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};112use up_data_structs::{113 AccessMode, budget::Budget, CollectionId, CollectionFlags, CollectionPropertiesVec,114 CreateCollectionData, CustomDataLimit, mapping::TokenAddressMapping, MAX_ITEMS_PER_BATCH,115 MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission, PropertyPermission,116 PropertyScope, PropertyValue, TokenId, TrySetProperty, PropertiesPermissionMap, CreateRefungibleExMultipleOwners,117};118119pub use pallet::*;120#[cfg(feature = "runtime-benchmarks")]121pub mod benchmarking;122pub mod common;123pub mod erc;124pub mod erc_token;125pub mod weights;126127pub type CreateItemData<T> =128 CreateRefungibleExMultipleOwners<<T as pallet_evm::Config>::CrossAccountId>;129pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;130131/// Token data, stored independently from other data used to describe it132/// for the convenience of database access. Notably contains the token metadata.133#[struct_versioning::versioned(version = 2, upper)]134#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]135pub struct ItemData {136 pub const_data: BoundedVec<u8, CustomDataLimit>,137138 #[version(..2)]139 pub variable_data: BoundedVec<u8, CustomDataLimit>,140}141142#[frame_support::pallet]143pub mod pallet {144 use super::*;145 use frame_support::{146 Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key,147 traits::StorageVersion,148 };149 use frame_system::pallet_prelude::*;150 use up_data_structs::{CollectionId, TokenId};151 use super::weights::WeightInfo;152153 #[pallet::error]154 pub enum Error<T> {155 /// Not Refungible item data used to mint in Refungible collection.156 NotRefungibleDataUsedToMintFungibleCollectionToken,157 /// Maximum refungibility exceeded.158 WrongRefungiblePieces,159 /// Refungible token can't be repartitioned by user who isn't owns all pieces.160 RepartitionWhileNotOwningAllPieces,161 /// Refungible token can't nest other tokens.162 RefungibleDisallowsNesting,163 /// Setting item properties is not allowed.164 SettingPropertiesNotAllowed,165 }166167 #[pallet::config]168 pub trait Config:169 frame_system::Config + pallet_common::Config + pallet_structure::Config170 {171 type WeightInfo: WeightInfo;172 }173174 const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);175176 #[pallet::pallet]177 #[pallet::storage_version(STORAGE_VERSION)]178 #[pallet::generate_store(pub(super) trait Store)]179 pub struct Pallet<T>(_);180181 /// Total amount of minted tokens in a collection.182 #[pallet::storage]183 pub type TokensMinted<T: Config> =184 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;185186 /// Amount of tokens burnt in a collection.187 #[pallet::storage]188 pub type TokensBurnt<T: Config> =189 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;190191 /// Token data, used to partially describe a token.192 // TODO: remove193 #[pallet::storage]194 #[deprecated(since = "0.2.0", note = "ItemData is no more contains usefull data")]195 pub type TokenData<T: Config> = StorageNMap<196 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),197 Value = ItemData,198 QueryKind = ValueQuery,199 >;200201 /// Amount of pieces a refungible token is split into.202 #[pallet::storage]203 #[pallet::getter(fn token_properties)]204 pub type TokenProperties<T: Config> = StorageNMap<205 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),206 Value = up_data_structs::Properties,207 QueryKind = ValueQuery,208 OnEmpty = up_data_structs::TokenProperties,209 >;210211 /// Total amount of pieces for token212 #[pallet::storage]213 pub type TotalSupply<T: Config> = StorageNMap<214 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),215 Value = u128,216 QueryKind = ValueQuery,217 >;218219 /// Used to enumerate tokens owned by account.220 #[pallet::storage]221 pub type Owned<T: Config> = StorageNMap<222 Key = (223 Key<Twox64Concat, CollectionId>,224 Key<Blake2_128Concat, T::CrossAccountId>,225 Key<Twox64Concat, TokenId>,226 ),227 Value = bool,228 QueryKind = ValueQuery,229 >;230231 /// Amount of tokens (not pieces) partially owned by an account within a collection.232 #[pallet::storage]233 pub type AccountBalance<T: Config> = StorageNMap<234 Key = (235 Key<Twox64Concat, CollectionId>,236 // Owner237 Key<Blake2_128Concat, T::CrossAccountId>,238 ),239 Value = u32,240 QueryKind = ValueQuery,241 >;242243 /// Amount of token pieces owned by account.244 #[pallet::storage]245 pub type Balance<T: Config> = StorageNMap<246 Key = (247 Key<Twox64Concat, CollectionId>,248 Key<Twox64Concat, TokenId>,249 // Owner250 Key<Blake2_128Concat, T::CrossAccountId>,251 ),252 Value = u128,253 QueryKind = ValueQuery,254 >;255256 /// Allowance set by a token owner for another user to perform one of certain transactions on a number of pieces of a token.257 #[pallet::storage]258 pub type Allowance<T: Config> = StorageNMap<259 Key = (260 Key<Twox64Concat, CollectionId>,261 Key<Twox64Concat, TokenId>,262 // Owner263 Key<Blake2_128, T::CrossAccountId>,264 // Spender265 Key<Blake2_128Concat, T::CrossAccountId>,266 ),267 Value = u128,268 QueryKind = ValueQuery,269 >;270271 /// Operator set by a wallet owner that could perform certain transactions on all tokens in the wallet.272 #[pallet::storage]273 pub type CollectionAllowance<T: Config> = StorageNMap<274 Key = (275 Key<Twox64Concat, CollectionId>,276 Key<Blake2_128Concat, T::CrossAccountId>,277 Key<Blake2_128Concat, T::CrossAccountId>,278 ),279 Value = bool,280 QueryKind = ValueQuery,281 >;282283 #[pallet::hooks]284 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {285 fn on_runtime_upgrade() -> Weight {286 let storage_version = StorageVersion::get::<Pallet<T>>();287 if storage_version < StorageVersion::new(2) {288 #[allow(deprecated)]289 let _ = <TokenData<T>>::clear(u32::MAX, None);290 }291 StorageVersion::new(2).put::<Pallet<T>>();292293 Weight::zero()294 }295 }296}297298pub struct RefungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);299impl<T: Config> RefungibleHandle<T> {300 pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {301 Self(inner)302 }303 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {304 self.0305 }306 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {307 &mut self.0308 }309}310311impl<T: Config> Deref for RefungibleHandle<T> {312 type Target = pallet_common::CollectionHandle<T>;313314 fn deref(&self) -> &Self::Target {315 &self.0316 }317}318319impl<T: Config> WithRecorder<T> for RefungibleHandle<T> {320 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {321 self.0.recorder()322 }323 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {324 self.0.into_recorder()325 }326}327328impl<T: Config> Pallet<T> {329 /// Get number of RFT tokens in collection330 pub fn total_supply(collection: &RefungibleHandle<T>) -> u32 {331 <TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)332 }333334 /// Check that RFT token exists335 ///336 /// - `token`: Token ID.337 pub fn token_exists(collection: &RefungibleHandle<T>, token: TokenId) -> bool {338 <TotalSupply<T>>::contains_key((collection.id, token))339 }340341 pub fn set_scoped_token_property(342 collection_id: CollectionId,343 token_id: TokenId,344 scope: PropertyScope,345 property: Property,346 ) -> DispatchResult {347 TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {348 properties.try_scoped_set(scope, property.key, property.value)349 })350 .map_err(<CommonError<T>>::from)?;351352 Ok(())353 }354355 pub fn set_scoped_token_properties(356 collection_id: CollectionId,357 token_id: TokenId,358 scope: PropertyScope,359 properties: impl Iterator<Item = Property>,360 ) -> DispatchResult {361 TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {362 stored_properties.try_scoped_set_from_iter(scope, properties)363 })364 .map_err(<CommonError<T>>::from)?;365366 Ok(())367 }368}369370// unchecked calls skips any permission checks371impl<T: Config> Pallet<T> {372 /// Create RFT collection373 ///374 /// `init_collection` will take non-refundable deposit for collection creation.375 ///376 /// - `data`: Contains settings for collection limits and permissions.377 pub fn init_collection(378 owner: T::CrossAccountId,379 payer: T::CrossAccountId,380 data: CreateCollectionData<T::AccountId>,381 flags: CollectionFlags,382 ) -> Result<CollectionId, DispatchError> {383 <PalletCommon<T>>::init_collection(owner, payer, data, flags)384 }385386 /// Destroy RFT collection387 ///388 /// `destroy_collection` will throw error if collection contains any tokens.389 /// Only owner can destroy collection.390 pub fn destroy_collection(391 collection: RefungibleHandle<T>,392 sender: &T::CrossAccountId,393 ) -> DispatchResult {394 let id = collection.id;395396 if Self::collection_has_tokens(id) {397 return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());398 }399400 // =========401402 PalletCommon::destroy_collection(collection.0, sender)?;403404 <TokensMinted<T>>::remove(id);405 <TokensBurnt<T>>::remove(id);406 let _ = <TotalSupply<T>>::clear_prefix((id,), u32::MAX, None);407 let _ = <Balance<T>>::clear_prefix((id,), u32::MAX, None);408 let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);409 let _ = <Owned<T>>::clear_prefix((id,), u32::MAX, None);410 let _ = <AccountBalance<T>>::clear_prefix((id,), u32::MAX, None);411 Ok(())412 }413414 fn collection_has_tokens(collection_id: CollectionId) -> bool {415 <TotalSupply<T>>::iter_prefix((collection_id,))416 .next()417 .is_some()418 }419420 pub fn burn_token_unchecked(421 collection: &RefungibleHandle<T>,422 owner: &T::CrossAccountId,423 token_id: TokenId,424 ) -> DispatchResult {425 let burnt = <TokensBurnt<T>>::get(collection.id)426 .checked_add(1)427 .ok_or(ArithmeticError::Overflow)?;428429 <TokensBurnt<T>>::insert(collection.id, burnt);430 <TokenProperties<T>>::remove((collection.id, token_id));431 <TotalSupply<T>>::remove((collection.id, token_id));432 let _ = <Balance<T>>::clear_prefix((collection.id, token_id), u32::MAX, None);433 let _ = <Allowance<T>>::clear_prefix((collection.id, token_id), u32::MAX, None);434 <PalletEvm<T>>::deposit_log(435 ERC721Events::Transfer {436 from: *owner.as_eth(),437 to: H160::default(),438 token_id: token_id.into(),439 }440 .to_log(collection_id_to_address(collection.id)),441 );442 Ok(())443 }444445 /// Burn RFT token pieces446 ///447 /// `burn` will decrease total amount of token pieces and amount owned by sender.448 /// `burn` can be called even if there are multiple owners of the RFT token.449 /// If sender wouldn't have any pieces left after `burn` than she will stop being450 /// one of the owners of the token. If there is no account that owns any pieces of451 /// the token than token will be burned too.452 ///453 /// - `amount`: Amount of token pieces to burn.454 /// - `token`: Token who's pieces should be burned455 /// - `collection`: Collection that contains the token456 pub fn burn(457 collection: &RefungibleHandle<T>,458 owner: &T::CrossAccountId,459 token: TokenId,460 amount: u128,461 ) -> DispatchResult {462 if <Balance<T>>::get((collection.id, token, owner)) == 0 {463 return Err(<CommonError<T>>::TokenValueTooLow.into());464 }465466 let total_supply = <TotalSupply<T>>::get((collection.id, token))467 .checked_sub(amount)468 .ok_or(<CommonError<T>>::TokenValueTooLow)?;469470 // This was probally last owner of this token?471 if total_supply == 0 {472 // Ensure user actually owns this amount473 ensure!(474 <Balance<T>>::get((collection.id, token, owner)) == amount,475 <CommonError<T>>::TokenValueTooLow476 );477 let account_balance = <AccountBalance<T>>::get((collection.id, owner))478 .checked_sub(1)479 // Should not occur480 .ok_or(ArithmeticError::Underflow)?;481482 // =========483484 <Owned<T>>::remove((collection.id, owner, token));485 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);486 <AccountBalance<T>>::insert((collection.id, owner), account_balance);487 Self::burn_token_unchecked(collection, owner, token)?;488 <PalletEvm<T>>::deposit_log(489 ERC20Events::Transfer {490 from: *owner.as_eth(),491 to: H160::default(),492 value: amount.into(),493 }494 .to_log(collection_id_to_address(collection.id)),495 );496 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(497 collection.id,498 token,499 owner.clone(),500 amount,501 ));502 return Ok(());503 }504505 let balance = <Balance<T>>::get((collection.id, token, owner))506 .checked_sub(amount)507 .ok_or(<CommonError<T>>::TokenValueTooLow)?;508 let account_balance = if balance == 0 {509 <AccountBalance<T>>::get((collection.id, owner))510 .checked_sub(1)511 // Should not occur512 .ok_or(ArithmeticError::Underflow)?513 } else {514 0515 };516517 // =========518519 if balance == 0 {520 <Owned<T>>::remove((collection.id, owner, token));521 <PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);522 <Balance<T>>::remove((collection.id, token, owner));523 <AccountBalance<T>>::insert((collection.id, owner), account_balance);524525 if let Some(user) = Self::token_owner(collection.id, token) {526 <PalletEvm<T>>::deposit_log(527 ERC721Events::Transfer {528 from: erc::ADDRESS_FOR_PARTIALLY_OWNED_TOKENS,529 to: *user.as_eth(),530 token_id: token.into(),531 }532 .to_log(collection_id_to_address(collection.id)),533 );534 }535 } else {536 <Balance<T>>::insert((collection.id, token, owner), balance);537 }538 <TotalSupply<T>>::insert((collection.id, token), total_supply);539540 <PalletEvm<T>>::deposit_log(541 ERC20Events::Transfer {542 from: *owner.as_eth(),543 to: H160::default(),544 value: amount.into(),545 }546 .to_log(T::EvmTokenAddressMapping::token_to_address(547 collection.id,548 token,549 )),550 );551 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(552 collection.id,553 token,554 owner.clone(),555 amount,556 ));557 Ok(())558 }559560 #[transactional]561 fn modify_token_properties(562 collection: &RefungibleHandle<T>,563 sender: &T::CrossAccountId,564 token_id: TokenId,565 properties: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,566 is_token_create: bool,567 nesting_budget: &dyn Budget,568 ) -> DispatchResult {569 let is_collection_admin = || collection.is_owner_or_admin(sender);570 let is_token_owner = || -> Result<bool, DispatchError> {571 let balance = collection.balance(sender.clone(), token_id);572 let total_pieces: u128 =573 Self::total_pieces(collection.id, token_id).unwrap_or(u128::MAX);574 if balance != total_pieces {575 return Ok(false);576 }577578 let is_bundle_owner = <PalletStructure<T>>::check_indirectly_owned(579 sender.clone(),580 collection.id,581 token_id,582 None,583 nesting_budget,584 )?;585586 Ok(is_bundle_owner)587 };588589 for (key, value) in properties {590 let permission = <PalletCommon<T>>::property_permissions(collection.id)591 .get(&key)592 .cloned()593 .unwrap_or_else(PropertyPermission::none);594595 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))596 .get(&key)597 .is_some();598599 match permission {600 PropertyPermission { mutable: false, .. } if is_property_exists => {601 return Err(<CommonError<T>>::NoPermission.into());602 }603604 PropertyPermission {605 collection_admin,606 token_owner,607 ..608 } => {609 //TODO: investigate threats during public minting.610 let is_token_create =611 is_token_create && (collection_admin || token_owner) && value.is_some();612 if !(is_token_create613 || (collection_admin && is_collection_admin())614 || (token_owner && is_token_owner()?))615 {616 fail!(<CommonError<T>>::NoPermission);617 }618 }619 }620621 match value {622 Some(value) => {623 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {624 properties.try_set(key.clone(), value)625 })626 .map_err(<CommonError<T>>::from)?;627628 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(629 collection.id,630 token_id,631 key,632 ));633 }634 None => {635 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {636 properties.remove(&key)637 })638 .map_err(<CommonError<T>>::from)?;639640 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(641 collection.id,642 token_id,643 key,644 ));645 }646 }647648 <PalletEvm<T>>::deposit_log(649 CollectionHelpersEvents::TokenChanged {650 collection_id: collection_id_to_address(collection.id),651 token_id: token_id.into(),652 }653 .to_log(T::ContractAddress::get()),654 );655 }656657 Ok(())658 }659660 pub fn set_token_properties(661 collection: &RefungibleHandle<T>,662 sender: &T::CrossAccountId,663 token_id: TokenId,664 properties: impl Iterator<Item = Property>,665 is_token_create: bool,666 nesting_budget: &dyn Budget,667 ) -> DispatchResult {668 Self::modify_token_properties(669 collection,670 sender,671 token_id,672 properties.map(|p| (p.key, Some(p.value))),673 is_token_create,674 nesting_budget,675 )676 }677678 pub fn set_token_property(679 collection: &RefungibleHandle<T>,680 sender: &T::CrossAccountId,681 token_id: TokenId,682 property: Property,683 nesting_budget: &dyn Budget,684 ) -> DispatchResult {685 let is_token_create = false;686687 Self::set_token_properties(688 collection,689 sender,690 token_id,691 [property].into_iter(),692 is_token_create,693 nesting_budget,694 )695 }696697 pub fn delete_token_properties(698 collection: &RefungibleHandle<T>,699 sender: &T::CrossAccountId,700 token_id: TokenId,701 property_keys: impl Iterator<Item = PropertyKey>,702 nesting_budget: &dyn Budget,703 ) -> DispatchResult {704 let is_token_create = false;705706 Self::modify_token_properties(707 collection,708 sender,709 token_id,710 property_keys.into_iter().map(|key| (key, None)),711 is_token_create,712 nesting_budget,713 )714 }715716 pub fn delete_token_property(717 collection: &RefungibleHandle<T>,718 sender: &T::CrossAccountId,719 token_id: TokenId,720 property_key: PropertyKey,721 nesting_budget: &dyn Budget,722 ) -> DispatchResult {723 Self::delete_token_properties(724 collection,725 sender,726 token_id,727 [property_key].into_iter(),728 nesting_budget,729 )730 }731732 /// Transfer RFT token pieces from one account to another.733 ///734 /// If the sender is no longer owns any pieces after the `transfer` than she stops being an owner of the token.735 ///736 /// - `from`: Owner of token pieces to transfer.737 /// - `to`: Recepient of transfered token pieces.738 /// - `amount`: Amount of token pieces to transfer.739 /// - `token`: Token whos pieces should be transfered740 /// - `collection`: Collection that contains the token741 pub fn transfer(742 collection: &RefungibleHandle<T>,743 from: &T::CrossAccountId,744 to: &T::CrossAccountId,745 token: TokenId,746 amount: u128,747 nesting_budget: &dyn Budget,748 ) -> DispatchResult {749 ensure!(750 collection.limits.transfers_enabled(),751 <CommonError<T>>::TransferNotAllowed752 );753754 if collection.permissions.access() == AccessMode::AllowList {755 collection.check_allowlist(from)?;756 collection.check_allowlist(to)?;757 }758 <PalletCommon<T>>::ensure_correct_receiver(to)?;759760 let initial_balance_from = <Balance<T>>::get((collection.id, token, from));761762 if initial_balance_from == 0 {763 return Err(<CommonError<T>>::TokenValueTooLow.into());764 }765766 let updated_balance_from = initial_balance_from767 .checked_sub(amount)768 .ok_or(<CommonError<T>>::TokenValueTooLow)?;769 let mut create_target = false;770 let from_to_differ = from != to;771 let updated_balance_to = if from != to && amount != 0 {772 let old_balance = <Balance<T>>::get((collection.id, token, to));773 if old_balance == 0 {774 create_target = true;775 }776 Some(777 old_balance778 .checked_add(amount)779 .ok_or(ArithmeticError::Overflow)?,780 )781 } else {782 None783 };784785 let account_balance_from = if updated_balance_from == 0 {786 Some(787 <AccountBalance<T>>::get((collection.id, from))788 .checked_sub(1)789 // Should not occur790 .ok_or(ArithmeticError::Underflow)?,791 )792 } else {793 None794 };795 // Account data is created in token, AccountBalance should be increased796 // But only if from != to as we shouldn't check overflow in this case797 let account_balance_to = if create_target && from_to_differ {798 let account_balance_to = <AccountBalance<T>>::get((collection.id, to))799 .checked_add(1)800 .ok_or(ArithmeticError::Overflow)?;801 ensure!(802 account_balance_to < collection.limits.account_token_ownership_limit(),803 <CommonError<T>>::AccountTokenLimitExceeded,804 );805806 Some(account_balance_to)807 } else {808 None809 };810811 // =========812813 if let Some(updated_balance_to) = updated_balance_to {814 // from != to && amount != 0815816 <PalletStructure<T>>::nest_if_sent_to_token(817 from.clone(),818 to,819 collection.id,820 token,821 nesting_budget,822 )?;823824 if updated_balance_from == 0 {825 <Balance<T>>::remove((collection.id, token, from));826 <PalletStructure<T>>::unnest_if_nested(from, collection.id, token);827 } else {828 <Balance<T>>::insert((collection.id, token, from), updated_balance_from);829 }830 <Balance<T>>::insert((collection.id, token, to), updated_balance_to);831 if let Some(account_balance_from) = account_balance_from {832 <AccountBalance<T>>::insert((collection.id, from), account_balance_from);833 <Owned<T>>::remove((collection.id, from, token));834 }835 if let Some(account_balance_to) = account_balance_to {836 <AccountBalance<T>>::insert((collection.id, to), account_balance_to);837 <Owned<T>>::insert((collection.id, to, token), true);838 }839 }840841 <PalletEvm<T>>::deposit_log(842 ERC20Events::Transfer {843 from: *from.as_eth(),844 to: *to.as_eth(),845 value: amount.into(),846 }847 .to_log(T::EvmTokenAddressMapping::token_to_address(848 collection.id,849 token,850 )),851 );852853 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(854 collection.id,855 token,856 from.clone(),857 to.clone(),858 amount,859 ));860861 let total_supply = <TotalSupply<T>>::get((collection.id, token));862863 if amount == total_supply {864 // if token was fully owned by `from` and will be fully owned by `to` after transfer865 <PalletEvm<T>>::deposit_log(866 ERC721Events::Transfer {867 from: *from.as_eth(),868 to: *to.as_eth(),869 token_id: token.into(),870 }871 .to_log(collection_id_to_address(collection.id)),872 );873 } else if let Some(updated_balance_to) = updated_balance_to {874 // if `from` not equals `to`. This condition is needed to avoid sending event875 // when `from` fully owns token and sends part of token pieces to itself.876 if initial_balance_from == total_supply {877 // if token was fully owned by `from` and will be only partially owned by `to`878 // and `from` after transfer879 <PalletEvm<T>>::deposit_log(880 ERC721Events::Transfer {881 from: *from.as_eth(),882 to: erc::ADDRESS_FOR_PARTIALLY_OWNED_TOKENS,883 token_id: token.into(),884 }885 .to_log(collection_id_to_address(collection.id)),886 );887 } else if updated_balance_to == total_supply {888 // if token was partially owned by `from` and will be fully owned by `to` after transfer889 <PalletEvm<T>>::deposit_log(890 ERC721Events::Transfer {891 from: erc::ADDRESS_FOR_PARTIALLY_OWNED_TOKENS,892 to: *to.as_eth(),893 token_id: token.into(),894 }895 .to_log(collection_id_to_address(collection.id)),896 );897 }898 }899900 Ok(())901 }902903 /// Batched operation to create multiple RFT tokens.904 ///905 /// Same as `create_item` but creates multiple tokens.906 ///907 /// - `data`: Same as 'data` in `create_item` but contains data for multiple tokens.908 pub fn create_multiple_items(909 collection: &RefungibleHandle<T>,910 sender: &T::CrossAccountId,911 data: Vec<CreateItemData<T>>,912 nesting_budget: &dyn Budget,913 ) -> DispatchResult {914 if !collection.is_owner_or_admin(sender) {915 ensure!(916 collection.permissions.mint_mode(),917 <CommonError<T>>::PublicMintingNotAllowed918 );919 collection.check_allowlist(sender)?;920921 for item in data.iter() {922 for user in item.users.keys() {923 collection.check_allowlist(user)?;924 }925 }926 }927928 for item in data.iter() {929 for (owner, _) in item.users.iter() {930 <PalletCommon<T>>::ensure_correct_receiver(owner)?;931 }932 }933934 // Total pieces per tokens935 let totals = data936 .iter()937 .map(|data| {938 Ok(data939 .users940 .iter()941 .map(|u| u.1)942 .try_fold(0u128, |acc, v| acc.checked_add(*v))943 .ok_or(ArithmeticError::Overflow)?)944 })945 .collect::<Result<Vec<_>, DispatchError>>()?;946 for total in &totals {947 ensure!(948 *total <= MAX_REFUNGIBLE_PIECES,949 <Error<T>>::WrongRefungiblePieces950 );951 }952953 let first_token_id = <TokensMinted<T>>::get(collection.id);954 let tokens_minted = first_token_id955 .checked_add(data.len() as u32)956 .ok_or(ArithmeticError::Overflow)?;957 ensure!(958 tokens_minted < collection.limits.token_limit(),959 <CommonError<T>>::CollectionTokenLimitExceeded960 );961962 let mut balances = BTreeMap::new();963 for data in &data {964 for owner in data.users.keys() {965 let balance = balances966 .entry(owner)967 .or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));968 *balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;969970 ensure!(971 *balance <= collection.limits.account_token_ownership_limit(),972 <CommonError<T>>::AccountTokenLimitExceeded,973 );974 }975 }976977 for (i, token) in data.iter().enumerate() {978 let token_id = TokenId(first_token_id + i as u32 + 1);979 for (to, _) in token.users.iter() {980 <PalletStructure<T>>::check_nesting(981 sender.clone(),982 to,983 collection.id,984 token_id,985 nesting_budget,986 )?;987 }988 }989990 // =========991992 with_transaction(|| {993 for (i, data) in data.iter().enumerate() {994 let token_id = first_token_id + i as u32 + 1;995 <TotalSupply<T>>::insert((collection.id, token_id), totals[i]);996997 for (user, amount) in data.users.iter() {998 if *amount == 0 {999 continue;1000 }1001 <Balance<T>>::insert((collection.id, token_id, &user), amount);1002 <Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);1003 <PalletStructure<T>>::nest_if_sent_to_token_unchecked(1004 user,1005 collection.id,1006 TokenId(token_id),1007 );1008 }10091010 if let Err(e) = Self::set_token_properties(1011 collection,1012 sender,1013 TokenId(token_id),1014 data.properties.clone().into_iter(),1015 true,1016 nesting_budget,1017 ) {1018 return TransactionOutcome::Rollback(Err(e));1019 }1020 }1021 TransactionOutcome::Commit(Ok(()))1022 })?;10231024 <TokensMinted<T>>::insert(collection.id, tokens_minted);10251026 for (account, balance) in balances {1027 <AccountBalance<T>>::insert((collection.id, account), balance);1028 }10291030 for (i, token) in data.into_iter().enumerate() {1031 let token_id = first_token_id + i as u32 + 1;10321033 let receivers = token1034 .users1035 .into_iter()1036 .filter(|(_, amount)| *amount > 0)1037 .collect::<Vec<_>>();10381039 if let [(user, _)] = receivers.as_slice() {1040 // if there is exactly one receiver1041 <PalletEvm<T>>::deposit_log(1042 ERC721Events::Transfer {1043 from: H160::default(),1044 to: *user.as_eth(),1045 token_id: token_id.into(),1046 }1047 .to_log(collection_id_to_address(collection.id)),1048 );1049 } else if let [_, ..] = receivers.as_slice() {1050 // if there is more than one receiver1051 <PalletEvm<T>>::deposit_log(1052 ERC721Events::Transfer {1053 from: H160::default(),1054 to: erc::ADDRESS_FOR_PARTIALLY_OWNED_TOKENS,1055 token_id: token_id.into(),1056 }1057 .to_log(collection_id_to_address(collection.id)),1058 );1059 }10601061 for (user, amount) in receivers.into_iter() {1062 <PalletEvm<T>>::deposit_log(1063 ERC20Events::Transfer {1064 from: H160::default(),1065 to: *user.as_eth(),1066 value: amount.into(),1067 }1068 .to_log(T::EvmTokenAddressMapping::token_to_address(1069 collection.id,1070 TokenId(token_id),1071 )),1072 );1073 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(1074 collection.id,1075 TokenId(token_id),1076 user,1077 amount,1078 ));1079 }1080 }1081 Ok(())1082 }10831084 pub fn set_allowance_unchecked(1085 collection: &RefungibleHandle<T>,1086 sender: &T::CrossAccountId,1087 spender: &T::CrossAccountId,1088 token: TokenId,1089 amount: u128,1090 ) {1091 if amount == 0 {1092 <Allowance<T>>::remove((collection.id, token, sender, spender));1093 } else {1094 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);1095 }10961097 <PalletEvm<T>>::deposit_log(1098 ERC20Events::Approval {1099 owner: *sender.as_eth(),1100 spender: *spender.as_eth(),1101 value: amount.into(),1102 }1103 .to_log(T::EvmTokenAddressMapping::token_to_address(1104 collection.id,1105 token,1106 )),1107 );1108 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(1109 collection.id,1110 token,1111 sender.clone(),1112 spender.clone(),1113 amount,1114 ))1115 }11161117 /// Set allowance for the spender to `transfer` or `burn` sender's token pieces.1118 ///1119 /// - `amount`: Amount of token pieces the spender is allowed to `transfer` or `burn.1120 pub fn set_allowance(1121 collection: &RefungibleHandle<T>,1122 sender: &T::CrossAccountId,1123 spender: &T::CrossAccountId,1124 token: TokenId,1125 amount: u128,1126 ) -> DispatchResult {1127 if collection.permissions.access() == AccessMode::AllowList {1128 collection.check_allowlist(sender)?;1129 collection.check_allowlist(spender)?;1130 }11311132 <PalletCommon<T>>::ensure_correct_receiver(spender)?;11331134 if <Balance<T>>::get((collection.id, token, sender)) < amount {1135 ensure!(1136 collection.ignores_owned_amount(sender) && Self::token_exists(collection, token),1137 <CommonError<T>>::CantApproveMoreThanOwned1138 );1139 }11401141 // =========11421143 Self::set_allowance_unchecked(collection, sender, spender, token, amount);1144 Ok(())1145 }11461147 /// Returns allowance, which should be set after transaction1148 fn check_allowed(1149 collection: &RefungibleHandle<T>,1150 spender: &T::CrossAccountId,1151 from: &T::CrossAccountId,1152 token: TokenId,1153 amount: u128,1154 nesting_budget: &dyn Budget,1155 ) -> Result<Option<u128>, DispatchError> {1156 if spender.conv_eq(from) {1157 return Ok(None);1158 }1159 if collection.permissions.access() == AccessMode::AllowList {1160 // `from`, `to` checked in [`transfer`]1161 collection.check_allowlist(spender)?;1162 }1163 if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {1164 // TODO: should collection owner be allowed to perform this transfer?1165 ensure!(1166 <PalletStructure<T>>::check_indirectly_owned(1167 spender.clone(),1168 source.0,1169 source.1,1170 None,1171 nesting_budget1172 )?,1173 <CommonError<T>>::ApprovedValueTooLow,1174 );1175 return Ok(None);1176 }1177 let allowance =1178 <Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);11791180 // Allowance (if any) would be reduced if spender is also wallet operator1181 if <CollectionAllowance<T>>::get((collection.id, from, spender)) {1182 return Ok(allowance);1183 }11841185 if allowance.is_none() {1186 ensure!(1187 collection.ignores_allowance(spender),1188 <CommonError<T>>::ApprovedValueTooLow1189 );1190 }1191 Ok(allowance)1192 }11931194 /// Transfer RFT token pieces from one account to another.1195 ///1196 /// Same as the [`transfer`] but spender doesn't needs to be an owner of the token pieces.1197 /// The owner should set allowance for the spender to transfer pieces.1198 ///1199 /// [`transfer`]: struct.Pallet.html#method.transfer1200 pub fn transfer_from(1201 collection: &RefungibleHandle<T>,1202 spender: &T::CrossAccountId,1203 from: &T::CrossAccountId,1204 to: &T::CrossAccountId,1205 token: TokenId,1206 amount: u128,1207 nesting_budget: &dyn Budget,1208 ) -> DispatchResult {1209 let allowance =1210 Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;12111212 // =========12131214 Self::transfer(collection, from, to, token, amount, nesting_budget)?;1215 if let Some(allowance) = allowance {1216 Self::set_allowance_unchecked(collection, from, spender, token, allowance);1217 }1218 Ok(())1219 }12201221 /// Burn RFT token pieces from the account.1222 ///1223 /// Same as the [`burn`] but spender doesn't need to be an owner of the token pieces. The owner should1224 /// set allowance for the spender to burn pieces1225 ///1226 /// [`burn`]: struct.Pallet.html#method.burn1227 pub fn burn_from(1228 collection: &RefungibleHandle<T>,1229 spender: &T::CrossAccountId,1230 from: &T::CrossAccountId,1231 token: TokenId,1232 amount: u128,1233 nesting_budget: &dyn Budget,1234 ) -> DispatchResult {1235 let allowance =1236 Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;12371238 // =========12391240 Self::burn(collection, from, token, amount)?;1241 if let Some(allowance) = allowance {1242 Self::set_allowance_unchecked(collection, from, spender, token, allowance);1243 }1244 Ok(())1245 }12461247 /// Create RFT token.1248 ///1249 /// The sender should be the owner/admin of the collection or collection should be configured1250 /// to allow public minting.1251 ///1252 /// - `data`: Contains list of users who will become the owners of the token pieces and amount1253 /// of token pieces they will receive.1254 pub fn create_item(1255 collection: &RefungibleHandle<T>,1256 sender: &T::CrossAccountId,1257 data: CreateItemData<T>,1258 nesting_budget: &dyn Budget,1259 ) -> DispatchResult {1260 Self::create_multiple_items(collection, sender, vec![data], nesting_budget)1261 }12621263 /// Repartition RFT token.1264 ///1265 /// `repartition` will set token balance of the sender and total amount of token pieces.1266 /// Sender should own all of the token pieces. `repartition' could be done even if some1267 /// token pieces were burned before.1268 ///1269 /// - `amount`: Total amount of token pieces that the token will have after `repartition`.1270 pub fn repartition(1271 collection: &RefungibleHandle<T>,1272 owner: &T::CrossAccountId,1273 token: TokenId,1274 amount: u128,1275 ) -> DispatchResult {1276 ensure!(1277 amount <= MAX_REFUNGIBLE_PIECES,1278 <Error<T>>::WrongRefungiblePieces1279 );1280 ensure!(amount > 0, <CommonError<T>>::TokenValueTooLow);1281 // Ensure user owns all pieces1282 let total_pieces = Self::total_pieces(collection.id, token).unwrap_or(u128::MAX);1283 let balance = <Balance<T>>::get((collection.id, token, owner));1284 ensure!(1285 total_pieces == balance,1286 <Error<T>>::RepartitionWhileNotOwningAllPieces1287 );12881289 <Balance<T>>::insert((collection.id, token, owner), amount);1290 <TotalSupply<T>>::insert((collection.id, token), amount);12911292 if amount > total_pieces {1293 let mint_amount = amount - total_pieces;1294 <PalletEvm<T>>::deposit_log(1295 ERC20Events::Transfer {1296 from: H160::default(),1297 to: *owner.as_eth(),1298 value: mint_amount.into(),1299 }1300 .to_log(T::EvmTokenAddressMapping::token_to_address(1301 collection.id,1302 token,1303 )),1304 );1305 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(1306 collection.id,1307 token,1308 owner.clone(),1309 mint_amount,1310 ));1311 } else if total_pieces > amount {1312 let burn_amount = total_pieces - amount;1313 <PalletEvm<T>>::deposit_log(1314 ERC20Events::Transfer {1315 from: *owner.as_eth(),1316 to: H160::default(),1317 value: burn_amount.into(),1318 }1319 .to_log(T::EvmTokenAddressMapping::token_to_address(1320 collection.id,1321 token,1322 )),1323 );1324 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(1325 collection.id,1326 token,1327 owner.clone(),1328 burn_amount,1329 ));1330 }13311332 Ok(())1333 }13341335 fn token_owner(collection_id: CollectionId, token_id: TokenId) -> Option<T::CrossAccountId> {1336 let mut owner = None;1337 let mut count = 0;1338 for key in Balance::<T>::iter_key_prefix((collection_id, token_id)) {1339 count += 1;1340 if count > 1 {1341 return None;1342 }1343 owner = Some(key);1344 }1345 owner1346 }13471348 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128> {1349 <TotalSupply<T>>::try_get((collection_id, token_id)).ok()1350 }13511352 pub fn set_collection_properties(1353 collection: &RefungibleHandle<T>,1354 sender: &T::CrossAccountId,1355 properties: Vec<Property>,1356 ) -> DispatchResult {1357 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)1358 }13591360 pub fn delete_collection_properties(1361 collection: &RefungibleHandle<T>,1362 sender: &T::CrossAccountId,1363 property_keys: Vec<PropertyKey>,1364 ) -> DispatchResult {1365 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)1366 }13671368 pub fn set_token_property_permissions(1369 collection: &RefungibleHandle<T>,1370 sender: &T::CrossAccountId,1371 property_permissions: Vec<PropertyKeyPermission>,1372 ) -> DispatchResult {1373 <PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)1374 }13751376 pub fn token_property_permission(collection_id: CollectionId) -> PropertiesPermissionMap {1377 <PalletCommon<T>>::property_permissions(collection_id)1378 }13791380 pub fn set_scoped_token_property_permissions(1381 collection: &RefungibleHandle<T>,1382 sender: &T::CrossAccountId,1383 scope: PropertyScope,1384 property_permissions: Vec<PropertyKeyPermission>,1385 ) -> DispatchResult {1386 <PalletCommon<T>>::set_scoped_token_property_permissions(1387 collection,1388 sender,1389 scope,1390 property_permissions,1391 )1392 }13931394 /// Returns 10 token in no particular order.1395 ///1396 /// There is no direct way to get token holders in ascending order,1397 /// since `iter_prefix` returns values in no particular order.1398 /// Therefore, getting the 10 largest holders with a large value of holders1399 /// can lead to impact memory allocation + sorting with `n * log (n)`.1400 pub fn token_owners(1401 collection_id: CollectionId,1402 token: TokenId,1403 ) -> Option<Vec<T::CrossAccountId>> {1404 let res: Vec<T::CrossAccountId> = <Balance<T>>::iter_prefix((collection_id, token))1405 .map(|(owner, _amount)| owner)1406 .take(10)1407 .collect();14081409 if res.is_empty() {1410 None1411 } else {1412 Some(res)1413 }1414 }14151416 /// Sets or unsets the approval of a given operator.1417 ///1418 /// The `operator` is allowed to transfer all token pieces of the `owner` on their behalf.1419 /// - `owner`: Token owner1420 /// - `operator`: Operator1421 /// - `approve`: Should operator status be granted or revoked?1422 pub fn set_allowance_for_all(1423 collection: &RefungibleHandle<T>,1424 owner: &T::CrossAccountId,1425 operator: &T::CrossAccountId,1426 approve: bool,1427 ) -> DispatchResult {1428 if collection.permissions.access() == AccessMode::AllowList {1429 collection.check_allowlist(owner)?;1430 collection.check_allowlist(operator)?;1431 }14321433 <PalletCommon<T>>::ensure_correct_receiver(operator)?;14341435 // =========14361437 <CollectionAllowance<T>>::insert((collection.id, owner, operator), approve);1438 <PalletEvm<T>>::deposit_log(1439 ERC721Events::ApprovalForAll {1440 owner: *owner.as_eth(),1441 operator: *operator.as_eth(),1442 approved: approve,1443 }1444 .to_log(collection_id_to_address(collection.id)),1445 );1446 <PalletCommon<T>>::deposit_event(CommonEvent::ApprovedForAll(1447 collection.id,1448 owner.clone(),1449 operator.clone(),1450 approve,1451 ));1452 Ok(())1453 }14541455 /// Tells whether the given `owner` approves the `operator`.1456 pub fn allowance_for_all(1457 collection: &RefungibleHandle<T>,1458 owner: &T::CrossAccountId,1459 operator: &T::CrossAccountId,1460 ) -> bool {1461 <CollectionAllowance<T>>::get((collection.id, owner, operator))1462 }14631464 pub fn repair_item(collection: &RefungibleHandle<T>, token: TokenId) -> DispatchResult {1465 <TokenProperties<T>>::mutate((collection.id, token), |properties| {1466 properties.recompute_consumed_space();1467 });14681469 Ok(())1470 }1471}pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -42,7 +42,11 @@
/// @param permissions Permissions for keys.
/// @dev EVM selector for this function is: 0xbd92983a,
/// or in textual repr: setTokenPropertyPermissions((string,(uint8,bool)[])[])
+<<<<<<< HEAD
function setTokenPropertyPermissions(Tuple58[] memory permissions) public {
+=======
+ function setTokenPropertyPermissions(Tuple55[] memory permissions) public {
+>>>>>>> 9e929f90... chore: generate stubs & types
require(false, stub_error);
permissions;
dummy = 0;
@@ -51,10 +55,17 @@
/// @notice Get permissions for token properties.
/// @dev EVM selector for this function is: 0xf23d7790,
/// or in textual repr: tokenPropertyPermissions()
+<<<<<<< HEAD
function tokenPropertyPermissions() public view returns (Tuple58[] memory) {
require(false, stub_error);
dummy;
return new Tuple58[](0);
+=======
+ function tokenPropertyPermissions() public view returns (Tuple55[] memory) {
+ require(false, stub_error);
+ dummy;
+ return new Tuple55[](0);
+>>>>>>> 9e929f90... chore: generate stubs & types
}
// /// @notice Set token property value.
@@ -144,6 +155,7 @@
}
/// @dev anonymous struct
+<<<<<<< HEAD
struct Tuple58 {
string field_0;
Tuple56[] field_1;
@@ -151,6 +163,15 @@
/// @dev anonymous struct
struct Tuple56 {
+=======
+struct Tuple55 {
+ string field_0;
+ Tuple53[] field_1;
+}
+
+/// @dev anonymous struct
+struct Tuple53 {
+>>>>>>> 9e929f90... chore: generate stubs & types
EthTokenPermissions field_0;
bool field_1;
}
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -770,12 +770,20 @@
},
{ "internalType": "bool", "name": "field_1", "type": "bool" }
],
+<<<<<<< HEAD
"internalType": "struct Tuple57[]",
+=======
+ "internalType": "struct Tuple54[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "field_1",
"type": "tuple[]"
}
],
+<<<<<<< HEAD
"internalType": "struct Tuple59[]",
+=======
+ "internalType": "struct Tuple56[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "permissions",
"type": "tuple[]"
}
@@ -836,12 +844,20 @@
},
{ "internalType": "bool", "name": "field_1", "type": "bool" }
],
+<<<<<<< HEAD
"internalType": "struct Tuple57[]",
+=======
+ "internalType": "struct Tuple54[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "field_1",
"type": "tuple[]"
}
],
+<<<<<<< HEAD
"internalType": "struct Tuple59[]",
+=======
+ "internalType": "struct Tuple56[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "",
"type": "tuple[]"
}
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -752,12 +752,20 @@
},
{ "internalType": "bool", "name": "field_1", "type": "bool" }
],
+<<<<<<< HEAD
"internalType": "struct Tuple56[]",
+=======
+ "internalType": "struct Tuple53[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "field_1",
"type": "tuple[]"
}
],
+<<<<<<< HEAD
"internalType": "struct Tuple58[]",
+=======
+ "internalType": "struct Tuple55[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "permissions",
"type": "tuple[]"
}
@@ -827,12 +835,20 @@
},
{ "internalType": "bool", "name": "field_1", "type": "bool" }
],
+<<<<<<< HEAD
"internalType": "struct Tuple56[]",
+=======
+ "internalType": "struct Tuple53[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "field_1",
"type": "tuple[]"
}
],
+<<<<<<< HEAD
"internalType": "struct Tuple58[]",
+=======
+ "internalType": "struct Tuple55[]",
+>>>>>>> 9e929f90... chore: generate stubs & types
"name": "",
"type": "tuple[]"
}
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -30,12 +30,20 @@
/// @param permissions Permissions for keys.
/// @dev EVM selector for this function is: 0xbd92983a,
/// or in textual repr: setTokenPropertyPermissions((string,(uint8,bool)[])[])
+<<<<<<< HEAD
function setTokenPropertyPermissions(Tuple52[] memory permissions) external;
+=======
+ function setTokenPropertyPermissions(Tuple49[] memory permissions) external;
+>>>>>>> 9e929f90... chore: generate stubs & types
/// @notice Get permissions for token properties.
/// @dev EVM selector for this function is: 0xf23d7790,
/// or in textual repr: tokenPropertyPermissions()
+<<<<<<< HEAD
function tokenPropertyPermissions() external view returns (Tuple52[] memory);
+=======
+ function tokenPropertyPermissions() external view returns (Tuple49[] memory);
+>>>>>>> 9e929f90... chore: generate stubs & types
// /// @notice Set token property value.
// /// @dev Throws error if `msg.sender` has no permission to edit the property.
@@ -97,6 +105,7 @@
}
/// @dev anonymous struct
+<<<<<<< HEAD
struct Tuple52 {
string field_0;
Tuple50[] field_1;
@@ -104,6 +113,15 @@
/// @dev anonymous struct
struct Tuple50 {
+=======
+struct Tuple49 {
+ string field_0;
+ Tuple47[] field_1;
+}
+
+/// @dev anonymous struct
+struct Tuple47 {
+>>>>>>> 9e929f90... chore: generate stubs & types
EthTokenPermissions field_0;
bool field_1;
}
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -30,12 +30,20 @@
/// @param permissions Permissions for keys.
/// @dev EVM selector for this function is: 0xbd92983a,
/// or in textual repr: setTokenPropertyPermissions((string,(uint8,bool)[])[])
+<<<<<<< HEAD
function setTokenPropertyPermissions(Tuple51[] memory permissions) external;
+=======
+ function setTokenPropertyPermissions(Tuple48[] memory permissions) external;
+>>>>>>> 9e929f90... chore: generate stubs & types
/// @notice Get permissions for token properties.
/// @dev EVM selector for this function is: 0xf23d7790,
/// or in textual repr: tokenPropertyPermissions()
+<<<<<<< HEAD
function tokenPropertyPermissions() external view returns (Tuple51[] memory);
+=======
+ function tokenPropertyPermissions() external view returns (Tuple48[] memory);
+>>>>>>> 9e929f90... chore: generate stubs & types
// /// @notice Set token property value.
// /// @dev Throws error if `msg.sender` has no permission to edit the property.
@@ -97,6 +105,7 @@
}
/// @dev anonymous struct
+<<<<<<< HEAD
struct Tuple51 {
string field_0;
Tuple49[] field_1;
@@ -104,6 +113,15 @@
/// @dev anonymous struct
struct Tuple49 {
+=======
+struct Tuple48 {
+ string field_0;
+ Tuple46[] field_1;
+}
+
+/// @dev anonymous struct
+struct Tuple46 {
+>>>>>>> 9e929f90... chore: generate stubs & types
EthTokenPermissions field_0;
bool field_1;
}
tests/src/interfaces/augment-api-consts.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-consts.ts
+++ b/tests/src/interfaces/augment-api-consts.ts
@@ -83,7 +83,7 @@
dayRelayBlocks: u32 & AugmentedConst<ApiType>;
defaultMinGasPrice: u64 & AugmentedConst<ApiType>;
defaultWeightToFeeCoefficient: u32 & AugmentedConst<ApiType>;
- maxOverridedAllowedLocations: u32 & AugmentedConst<ApiType>;
+ maxXcmAllowedLocations: u32 & AugmentedConst<ApiType>;
/**
* Generic const
**/