difftreelog
remove warnings
in: master
8 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -12,12 +12,12 @@
pub struct CommonWeights<T: Config>(PhantomData<T>);
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
- fn create_multiple_items(amount: &[up_data_structs::CreateItemData]) -> Weight {
+ fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {
Weight::default()
}
fn create_multiple_items_ex(
- cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,
+ _cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,
) -> Weight {
Weight::default()
}
@@ -26,23 +26,23 @@
Weight::default()
}
- fn set_collection_properties(amount: u32) -> Weight {
+ fn set_collection_properties(_amount: u32) -> Weight {
Weight::default()
}
- fn delete_collection_properties(amount: u32) -> Weight {
+ fn delete_collection_properties(_amount: u32) -> Weight {
Weight::default()
}
- fn set_token_properties(amount: u32) -> Weight {
+ fn set_token_properties(_amount: u32) -> Weight {
Weight::default()
}
- fn delete_token_properties(amount: u32) -> Weight {
+ fn delete_token_properties(_amount: u32) -> Weight {
Weight::default()
}
- fn set_token_property_permissions(amount: u32) -> Weight {
+ fn set_token_property_permissions(_amount: u32) -> Weight {
Weight::default()
}
@@ -70,7 +70,7 @@
Weight::default()
}
- fn burn_recursively_breadth_raw(amount: u32) -> Weight {
+ fn burn_recursively_breadth_raw(_amount: u32) -> Weight {
Weight::default()
}
@@ -92,92 +92,92 @@
impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {
fn create_item(
&self,
- sender: <T>::CrossAccountId,
- to: <T>::CrossAccountId,
- data: up_data_structs::CreateItemData,
- nesting_budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _to: <T>::CrossAccountId,
+ _data: up_data_structs::CreateItemData,
+ _nesting_budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn create_multiple_items(
&self,
- sender: <T>::CrossAccountId,
- to: <T>::CrossAccountId,
- data: Vec<up_data_structs::CreateItemData>,
- nesting_budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _to: <T>::CrossAccountId,
+ _data: Vec<up_data_structs::CreateItemData>,
+ _nesting_budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn create_multiple_items_ex(
&self,
- sender: <T>::CrossAccountId,
- data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
- nesting_budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
+ _nesting_budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn burn_item(
&self,
- sender: <T>::CrossAccountId,
- token: TokenId,
- amount: u128,
+ _sender: <T>::CrossAccountId,
+ _token: TokenId,
+ _amount: u128,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn burn_item_recursively(
&self,
- sender: <T>::CrossAccountId,
- token: TokenId,
- self_budget: &dyn up_data_structs::budget::Budget,
- breadth_budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _token: TokenId,
+ _self_budget: &dyn up_data_structs::budget::Budget,
+ _breadth_budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn set_collection_properties(
&self,
- sender: <T>::CrossAccountId,
- properties: Vec<up_data_structs::Property>,
+ _sender: <T>::CrossAccountId,
+ _properties: Vec<up_data_structs::Property>,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn delete_collection_properties(
&self,
- sender: &<T>::CrossAccountId,
- property_keys: Vec<up_data_structs::PropertyKey>,
+ _sender: &<T>::CrossAccountId,
+ _property_keys: Vec<up_data_structs::PropertyKey>,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn set_token_properties(
&self,
- sender: <T>::CrossAccountId,
- token_id: TokenId,
- properties: Vec<up_data_structs::Property>,
- budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _token_id: TokenId,
+ _properties: Vec<up_data_structs::Property>,
+ _budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn delete_token_properties(
&self,
- sender: <T>::CrossAccountId,
- token_id: TokenId,
- property_keys: Vec<up_data_structs::PropertyKey>,
- budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _token_id: TokenId,
+ _property_keys: Vec<up_data_structs::PropertyKey>,
+ _budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn set_token_property_permissions(
&self,
- sender: &<T>::CrossAccountId,
- property_permissions: Vec<up_data_structs::PropertyKeyPermission>,
+ _sender: &<T>::CrossAccountId,
+ _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
@@ -186,9 +186,9 @@
&self,
sender: <T>::CrossAccountId,
to: <T>::CrossAccountId,
- token: TokenId,
+ _token: TokenId,
amount: u128,
- budget: &dyn up_data_structs::budget::Budget,
+ _budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
with_weight(
<T as Config>::Currency::transfer(
@@ -203,21 +203,21 @@
fn approve(
&self,
- sender: <T>::CrossAccountId,
- spender: <T>::CrossAccountId,
- token: TokenId,
- amount: u128,
+ _sender: <T>::CrossAccountId,
+ _spender: <T>::CrossAccountId,
+ _token: TokenId,
+ _amount: u128,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn approve_from(
&self,
- sender: <T>::CrossAccountId,
- from: <T>::CrossAccountId,
- to: <T>::CrossAccountId,
- token: TokenId,
- amount: u128,
+ _sender: <T>::CrossAccountId,
+ _from: <T>::CrossAccountId,
+ _to: <T>::CrossAccountId,
+ _token: TokenId,
+ _amount: u128,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
@@ -227,9 +227,9 @@
sender: <T>::CrossAccountId,
from: <T>::CrossAccountId,
to: <T>::CrossAccountId,
- token: TokenId,
+ _token: TokenId,
amount: u128,
- budget: &dyn up_data_structs::budget::Budget,
+ _budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
if sender != from {
fail!(<pallet_common::Error<T>>::NoPermission);
@@ -247,28 +247,28 @@
fn burn_from(
&self,
- sender: <T>::CrossAccountId,
- from: <T>::CrossAccountId,
- token: TokenId,
- amount: u128,
- budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _from: <T>::CrossAccountId,
+ _token: TokenId,
+ _amount: u128,
+ _budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
fn check_nesting(
&self,
- sender: <T>::CrossAccountId,
- from: (up_data_structs::CollectionId, TokenId),
- under: TokenId,
- budget: &dyn up_data_structs::budget::Budget,
+ _sender: <T>::CrossAccountId,
+ _from: (up_data_structs::CollectionId, TokenId),
+ _under: TokenId,
+ _budget: &dyn up_data_structs::budget::Budget,
) -> frame_support::sp_runtime::DispatchResult {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
- fn nest(&self, under: TokenId, to_nest: (up_data_structs::CollectionId, TokenId)) {}
+ fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}
- fn unnest(&self, under: TokenId, to_nest: (up_data_structs::CollectionId, TokenId)) {}
+ fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}
fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {
let balance = <T as Config>::Currency::total_balance(account.as_sub());
@@ -293,27 +293,27 @@
fn token_owner(
&self,
- token: TokenId,
+ _token: TokenId,
) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {
Err(up_data_structs::TokenOwnerError::MultipleOwners)
}
- fn token_owners(&self, token: TokenId) -> Vec<<T>::CrossAccountId> {
+ fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {
vec![]
}
fn token_property(
&self,
- token_id: TokenId,
- key: &up_data_structs::PropertyKey,
+ _token_id: TokenId,
+ _key: &up_data_structs::PropertyKey,
) -> Option<up_data_structs::PropertyValue> {
None
}
fn token_properties(
&self,
- token: TokenId,
- keys: Option<Vec<up_data_structs::PropertyKey>>,
+ _token: TokenId,
+ _keys: Option<Vec<up_data_structs::PropertyKey>>,
) -> Vec<up_data_structs::Property> {
vec![]
}
@@ -344,9 +344,9 @@
fn allowance(
&self,
- sender: <T>::CrossAccountId,
- spender: <T>::CrossAccountId,
- token: TokenId,
+ _sender: <T>::CrossAccountId,
+ _spender: <T>::CrossAccountId,
+ _token: TokenId,
) -> u128 {
0
}
@@ -357,20 +357,24 @@
fn set_allowance_for_all(
&self,
- owner: <T>::CrossAccountId,
- operator: <T>::CrossAccountId,
- approve: bool,
+ _owner: <T>::CrossAccountId,
+ _operator: <T>::CrossAccountId,
+ _approve: bool,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
- fn allowance_for_all(&self, owner: <T>::CrossAccountId, operator: <T>::CrossAccountId) -> bool {
+ fn allowance_for_all(
+ &self,
+ _owner: <T>::CrossAccountId,
+ _operator: <T>::CrossAccountId,
+ ) -> bool {
false
}
fn repair_item(
&self,
- token: TokenId,
+ _token: TokenId,
) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -9,7 +9,7 @@
use pallet_evm_coder_substrate::{
call, dispatch_to_evm,
execution::{PreDispatch, Result},
- frontier_contract, WithRecorder, SubstrateRecorder,
+ frontier_contract,
};
use sp_core::{U256, Get};
use sp_std::vec::Vec;
@@ -26,13 +26,6 @@
from: Address,
#[indexed]
to: Address,
- value: U256,
- },
- Approval {
- #[indexed]
- owner: Address,
- #[indexed]
- spender: Address,
value: U256,
},
}
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -1,11 +1,9 @@
// #![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
-#![warn(missing_docs)]
extern crate alloc;
use frame_support::sp_runtime::DispatchResult;
pub use pallet::*;
-use pallet_common::CollectionHandle;
use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};
pub mod common;
@@ -13,12 +11,15 @@
pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
+/// Handle for native fungible collection
pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
impl<T: Config> NativeFungibleHandle<T> {
+ /// Creates a handle
pub fn new() -> NativeFungibleHandle<T> {
Self(SubstrateRecorder::new(u64::MAX))
}
+ /// Check if the collection is internal
pub fn check_is_internal(&self) -> DispatchResult {
Ok(())
}
@@ -35,7 +36,7 @@
#[frame_support::pallet]
pub mod pallet {
use alloc::string::String;
- use frame_support::{traits::Get, sp_runtime::DispatchResult};
+ use frame_support::{traits::Get};
use pallet_balances::WeightInfo;
use sp_core::U256;
@@ -43,25 +44,24 @@
pub trait Config:
frame_system::Config + pallet_evm_coder_substrate::Config + pallet_common::Config
{
+ /// Currency from `pallet_balances`
type Currency: frame_support::traits::Currency<
Self::AccountId,
Balance = Self::CurrencyBalance,
>;
+ /// Balance type of chain
type CurrencyBalance: Into<U256> + TryFrom<U256> + PartialEq<u128> + From<u128> + Into<u128>;
+ /// Decimals of balance
type Decimals: Get<u8>;
+ /// Collection name
type Name: Get<String>;
+ /// Collection symbol
type Symbol: Get<String>;
+ /// Weight information
type WeightInfo: WeightInfo;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
-
- // #[pallet::call]
- impl<T: Config> Pallet<T> {
- pub fn dummy() -> DispatchResult {
- Ok(())
- }
- }
}
pallets/common/src/dispatch.rsdiffbeforeafterboth--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -11,7 +11,7 @@
use sp_runtime::DispatchError;
use up_data_structs::{CollectionId, CreateCollectionData, CollectionFlags};
-use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
+use crate::{pallet::Config, CommonCollectionOperations};
// TODO: move to benchmarking
/// Price of [`dispatch_tx`] call with noop `call` argument
@@ -66,6 +66,7 @@
/// Interface for working with different collections through the dispatcher.
pub trait CollectionDispatch<T: Config> {
+ /// Check if the collection is internal.
fn check_is_internal(&self) -> DispatchResult;
/// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -80,7 +80,7 @@
impl CommonEvmHandler for () {
const CODE: &'static [u8] = &[];
- fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
+ fn call(self, _handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
None
}
}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -462,6 +462,7 @@
}
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
+ /// Collection id for native fungible collction.
pub const NATIVE_FINGIBLE_COLLECTION_ID: CollectionId = CollectionId(0);
#[pallet::pallet]
pallets/structure/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//! # Structure Pallet18//!19//! The Structure pallet provides functionality for handling tokens nesting an unnesting.20//!21//! - [`Config`]22//! - [`Pallet`]23//!24//! ## Overview25//!26//! The Structure pallet provides functions for:27//!28//! - Searching for token parents, children and owners. Actual implementation of searching for29//! parent/child is done by pallets corresponding to token's collection type.30//! - Nesting and unnesting tokens. Actual implementation of nesting is done by pallets corresponding31//! to token's collection type.32//!33//! ### Terminology34//!35//! - **Nesting:** Setting up parent-child relationship between tokens. Nested tokens are inhereting36//! owner from their parent. There could be multiple levels of nesting. Token couldn't be nested in37//! it's child token i.e. parent-child relationship graph shouldn't have38//!39//! - **Parent:** Token that current token is nested in.40//!41//! - **Owner:** Account that owns the token and all nested tokens.42//!43//! ## Interface44//!45//! ### Available Functions46//!47//! - `find_parent` - Find parent of the token. It could be an account or another token.48//! - `parent_chain` - Find chain of parents of the token.49//! - `find_topmost_owner` - Find account or token in the end of the chain of parents.50//! - `check_nesting` - Check if the token could be nested in the other token51//! - `nest_if_sent_to_token` - Nest the token in the other token52//! - `unnest_if_nested` - Unnest the token from the other token5354#![cfg_attr(not(feature = "std"), no_std)]5556use pallet_common::CommonCollectionOperations;57use pallet_common::{erc::CrossAccountId, eth::is_collection};58use sp_std::collections::btree_set::BTreeSet;5960use frame_support::dispatch::{DispatchError, DispatchResult, DispatchResultWithPostInfo};61use frame_support::fail;62pub use pallet::*;63use pallet_common::{dispatch::CollectionDispatch, CollectionHandle};64use up_data_structs::{65 CollectionId, TokenId, mapping::TokenAddressMapping, budget::Budget, TokenOwnerError,66};6768#[cfg(feature = "runtime-benchmarks")]69pub mod benchmarking;70pub mod weights;7172pub type SelfWeightOf<T> = <T as crate::Config>::WeightInfo;7374#[frame_support::pallet]75pub mod pallet {76 use frame_support::Parameter;77 use frame_support::dispatch::{GetDispatchInfo, UnfilteredDispatchable};78 use frame_support::pallet_prelude::*;7980 use super::*;8182 #[pallet::error]83 pub enum Error<T> {84 /// While nesting, encountered an already checked account, detecting a loop.85 OuroborosDetected,86 /// While nesting, reached the depth limit of nesting, exceeding the provided budget.87 DepthLimit,88 /// While nesting, reached the breadth limit of nesting, exceeding the provided budget.89 BreadthLimit,90 /// Couldn't find the token owner that is itself a token.91 TokenNotFound,92 /// Tried to nest token under collection contract address, instead of token address93 CantNestTokenUnderCollection,94 }9596 #[pallet::event]97 pub enum Event<T> {98 /// Executed call on behalf of the token.99 Executed(DispatchResult),100 }101102 #[pallet::config]103 pub trait Config: frame_system::Config + pallet_common::Config {104 type WeightInfo: weights::WeightInfo;105 type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;106 type RuntimeCall: Parameter107 + UnfilteredDispatchable<RuntimeOrigin = Self::RuntimeOrigin>108 + GetDispatchInfo;109 }110111 #[pallet::pallet]112 pub struct Pallet<T>(_);113114 #[pallet::call]115 impl<T: Config> Pallet<T> {116 // #[pallet::weight({117 // let dispatch_info = call.get_dispatch_info();118119 // (120 // dispatch_info.weight121 // // Cost of dereferencing parent122 // .saturating_add(T::DbWeight::get().reads(2 * *max_depth as Weight))123 // .saturating_add(4000 * *max_depth as Weight),124 // dispatch_info.class)125 // })]126 // pub fn execute(127 // origin: OriginFor<T>,128 // call: Box<<T as Config>::Call>,129 // max_depth: u32,130 // ) -> DispatchResult {131 }132}133134#[derive(PartialEq)]135pub enum Parent<CrossAccountId> {136 /// Token owned by a normal account.137 User(CrossAccountId),138 /// Could not find the token provided as the owner.139 TokenNotFound,140 /// Nested token has multiple owners.141 MultipleOwners,142 /// Token owner is another token (still, the target token may not exist).143 Token(CollectionId, TokenId),144}145146impl<T: Config> Pallet<T> {147 /// Find account owning the `token` or a token that the `token` is nested in.148 ///149 /// Returns the enum that have three variants:150 /// - [`User`](crate::Parent<T>::User): Contains account.151 /// - [`Token`](crate::Parent<T>::Token): Contains token id and collection id.152 /// - [`TokenNotFound`](crate::Parent<T>::TokenNotFound): Indicates that parent was not found153 pub fn find_parent(154 collection: CollectionId,155 token: TokenId,156 ) -> Result<Parent<T::CrossAccountId>, DispatchError> {157 // TODO: Reduce cost by not reading collection config158 let handle = match T::CollectionDispatch::dispatch(collection) {159 Ok(v) => v,160 Err(_) => return Ok(Parent::TokenNotFound),161 };162 let handle = handle.as_dyn();163164 Ok(match handle.token_owner(token) {165 Ok(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {166 Some((collection, token)) => Parent::Token(collection, token),167 None => Parent::User(owner),168 },169 Err(TokenOwnerError::MultipleOwners) => Parent::MultipleOwners,170 Err(TokenOwnerError::NotFound) => Parent::TokenNotFound,171 })172 }173174 /// Get the chain of parents of a token in the nesting hierarchy175 ///176 /// Returns an iterator of addresses of the owning tokens and the owning account,177 /// starting from the immediate parent token, ending with the account.178 /// Returns error if cycle is detected.179 pub fn parent_chain(180 mut collection: CollectionId,181 mut token: TokenId,182 ) -> impl Iterator<Item = Result<Parent<T::CrossAccountId>, DispatchError>> {183 let mut finished = false;184 let mut visited = BTreeSet::new();185 visited.insert((collection, token));186 core::iter::from_fn(move || {187 if finished {188 return None;189 }190 let parent = Self::find_parent(collection, token);191 match parent {192 Ok(Parent::Token(new_collection, new_token)) => {193 collection = new_collection;194 token = new_token;195 if !visited.insert((new_collection, new_token)) {196 finished = true;197 return Some(Err(<Error<T>>::OuroborosDetected.into()));198 }199 }200 _ => finished = true,201 }202 Some(parent as Result<_, DispatchError>)203 })204 }205206 /// Try to dereference address, until finding top level owner207 ///208 /// May return token address if parent token not yet exists209 ///210 /// Returns `None` if the token has multiple owners.211 ///212 /// - `budget`: Limit for searching parents in depth.213 pub fn find_topmost_owner(214 collection: CollectionId,215 token: TokenId,216 budget: &dyn Budget,217 ) -> Result<Option<T::CrossAccountId>, DispatchError> {218 let owner = Self::parent_chain(collection, token)219 .take_while(|_| budget.consume())220 .find(|p| {221 matches!(222 p,223 Ok(Parent::User(_) | Parent::TokenNotFound | Parent::MultipleOwners)224 )225 })226 .ok_or(<Error<T>>::DepthLimit)??;227228 Ok(match owner {229 Parent::User(v) => Some(v),230 Parent::MultipleOwners => None,231 _ => fail!(<Error<T>>::TokenNotFound),232 })233 }234235 /// Find the topmost parent and check that assigning `for_nest` token as a child for236 /// `token` wouldn't create a cycle.237 ///238 /// Returns `None` if the token has multiple owners.239 ///240 /// - `budget`: Limit for searching parents in depth.241 pub fn get_checked_topmost_owner(242 collection: CollectionId,243 token: TokenId,244 for_nest: Option<(CollectionId, TokenId)>,245 budget: &dyn Budget,246 ) -> Result<Option<T::CrossAccountId>, DispatchError> {247 // Tried to nest token in itself248 if Some((collection, token)) == for_nest {249 return Err(<Error<T>>::OuroborosDetected.into());250 }251252 for parent in Self::parent_chain(collection, token).take_while(|_| budget.consume()) {253 match parent? {254 // Tried to nest token in chain, which has this token as one of parents255 Parent::Token(collection, token) if Some((collection, token)) == for_nest => {256 return Err(<Error<T>>::OuroborosDetected.into())257 }258 // Token is owned by other user259 Parent::User(user) => return Ok(Some(user)),260 Parent::TokenNotFound => return Err(<Error<T>>::TokenNotFound.into()),261 Parent::MultipleOwners => return Ok(None),262 // Continue parent chain263 Parent::Token(_, _) => {}264 }265 }266267 Err(<Error<T>>::DepthLimit.into())268 }269270 /// Burn token and all of it's nested tokens271 ///272 /// - `self_budget`: Limit for searching children in depth.273 /// - `breadth_budget`: Limit of breadth of searching children.274 pub fn burn_item_recursively(275 from: T::CrossAccountId,276 collection: CollectionId,277 token: TokenId,278 self_budget: &dyn Budget,279 breadth_budget: &dyn Budget,280 ) -> DispatchResultWithPostInfo {281 let dispatch = T::CollectionDispatch::dispatch(collection)?;282 let dispatch = dispatch.as_dyn();283 dispatch.burn_item_recursively(from.clone(), token, self_budget, breadth_budget)284 }285286 /// Check if `token` indirectly owned by `user`287 ///288 /// Returns `true` if `user` is `token`'s owner. Or If token is provided as `user` then289 /// check that `user` and `token` have same owner.290 /// Checks that assigning `for_nest` token as a child for `token` wouldn't create a cycle.291 ///292 /// - `budget`: Limit for searching parents in depth.293 pub fn check_indirectly_owned(294 user: T::CrossAccountId,295 collection: CollectionId,296 token: TokenId,297 for_nest: Option<(CollectionId, TokenId)>,298 budget: &dyn Budget,299 ) -> Result<bool, DispatchError> {300 let target_parent = match T::CrossTokenAddressMapping::address_to_token(&user) {301 Some((collection, token)) => match Self::find_topmost_owner(collection, token, budget)?302 {303 Some(topmost_owner) => topmost_owner,304 None => return Ok(false),305 },306 None => user,307 };308309 Self::get_checked_topmost_owner(collection, token, for_nest, budget).map(|indirect_owner| {310 indirect_owner.map_or(false, |indirect_owner| indirect_owner == target_parent)311 })312 }313314 /// Checks that `under` is valid token and that `token_id` could be nested under it315 /// and that `from` is `under`'s owner316 ///317 /// Returns OK if `under` is not a token318 ///319 /// - `nesting_budget`: Limit for searching parents in depth.320 pub fn check_nesting(321 from: T::CrossAccountId,322 under: &T::CrossAccountId,323 collection_id: CollectionId,324 token_id: TokenId,325 nesting_budget: &dyn Budget,326 ) -> DispatchResult {327 Self::try_exec_if_token(under, |collection, parent_id| {328 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)329 })330 }331332 /// Nests `token_id` under `under` token333 ///334 /// Returns OK if `under` is not a token. Checks that nesting is possible.335 ///336 /// - `nesting_budget`: Limit for searching parents in depth.337 pub fn nest_if_sent_to_token(338 from: T::CrossAccountId,339 under: &T::CrossAccountId,340 collection_id: CollectionId,341 token_id: TokenId,342 nesting_budget: &dyn Budget,343 ) -> DispatchResult {344 Self::try_exec_if_token(under, |collection, parent_id| {345 collection.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;346347 collection.nest(parent_id, (collection_id, token_id));348349 Ok(())350 })351 }352353 /// Nests `token_id` under `owner` token354 ///355 /// Caller should check that nesting wouldn't cause recursion in nesting356 pub fn nest_if_sent_to_token_unchecked(357 owner: &T::CrossAccountId,358 collection_id: CollectionId,359 token_id: TokenId,360 ) {361 Self::exec_if_token(owner, |collection, parent_id| {362 collection.nest(parent_id, (collection_id, token_id))363 });364 }365366 /// Unnests `token_id` from `owner`.367 pub fn unnest_if_nested(368 owner: &T::CrossAccountId,369 collection_id: CollectionId,370 token_id: TokenId,371 ) {372 if let Err(e) = Self::try_exec_if_token(owner, |collection, parent_id| {373 collection.unnest(parent_id, (collection_id, token_id));374 Ok(())375 }) {376 log::warn!("unnest precondition failed: {e:?}")377 }378 }379380 /// # Panics381 /// If [`Self::try_exec_if_token`] fails382 fn exec_if_token(383 account: &T::CrossAccountId,384 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),385 ) {386 Self::try_exec_if_token(account, |collection, id| {387 action(collection, id);388 Ok(())389 })390 .unwrap();391 }392393 /// If `account` is a token address, execute `action` providing found collection as an argument394 /// Token may not exist, it is expected it will be checked in the callback.395 fn try_exec_if_token(396 account: &T::CrossAccountId,397 action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId) -> DispatchResult,398 ) -> DispatchResult {399 if is_collection(&account.as_eth()) {400 fail!(<Error<T>>::CantNestTokenUnderCollection);401 }402 let Some((collection, token)) = T::CrossTokenAddressMapping::address_to_token(account) else {403 return Ok(())404 };405406 let dispatch = T::CollectionDispatch::dispatch(collection)?;407 let dispatch = dispatch.as_dyn();408409 action(dispatch, token)410 }411}runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -25,7 +25,7 @@
};
pub use pallet_common::dispatch::CollectionDispatch;
use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
-use pallet_balances_adapter::{Pallet as PalletNativeFungible, NativeFungibleHandle};
+use pallet_balances_adapter::{NativeFungibleHandle};
use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};
use pallet_refungible::{
Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,