mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-17 20:35:41 +00:00
e819fd03f9
* Uniques: An economically-secure basic-featured NFT pallet * force_transfer * freeze/thaw * team management * approvals * Fixes * force_asset_status * class_metadata * instance metadata * Fixes * use nmap * Fixes * class metadata has information field * Intiial mock/tests and a fix * Remove impl_non_fungibles * Docs * Update frame/uniques/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/uniques/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/uniques/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/uniques/src/lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * Reserve, don't transfer. * Fixes * Tests * Tests * refresh_deposit * Tests and proper handling of metdata destruction * test burn * Tests * Update impl_fungibles.rs * Initial benchmarking * benchmark * Fixes * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Attributes * Attribute metadata * Fixes * Update frame/uniques/README.md * Docs * Docs * Docs * Simple metadata * Use BoundedVec * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Update frame/uniques/src/lib.rs Co-authored-by: Lohann Paterno Coutinho Ferreira <developer@lohann.dev> * Update frame/uniques/src/lib.rs Co-authored-by: Lohann Paterno Coutinho Ferreira <developer@lohann.dev> * Update frame/uniques/src/lib.rs Co-authored-by: Lohann Paterno Coutinho Ferreira <developer@lohann.dev> * Update frame/uniques/src/lib.rs Co-authored-by: Lohann Paterno Coutinho Ferreira <developer@lohann.dev> * Update frame/uniques/src/lib.rs Co-authored-by: Lohann Paterno Coutinho Ferreira <developer@lohann.dev> * Fixes * Update frame/uniques/README.md Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Update frame/uniques/README.md Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Update frame/uniques/README.md Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Docs * Bump Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Lohann Paterno Coutinho Ferreira <developer@lohann.dev> Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
157 lines
4.5 KiB
Rust
157 lines
4.5 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//! Implementations for fungibles trait.
|
|
|
|
use super::*;
|
|
|
|
impl<T: Config<I>, I: 'static> fungibles::Inspect<<T as SystemConfig>::AccountId> for Pallet<T, I> {
|
|
type AssetId = T::AssetId;
|
|
type Balance = T::Balance;
|
|
|
|
fn total_issuance(asset: Self::AssetId) -> Self::Balance {
|
|
Asset::<T, I>::get(asset)
|
|
.map(|x| x.supply)
|
|
.unwrap_or_else(Zero::zero)
|
|
}
|
|
|
|
fn minimum_balance(asset: Self::AssetId) -> Self::Balance {
|
|
Asset::<T, I>::get(asset)
|
|
.map(|x| x.min_balance)
|
|
.unwrap_or_else(Zero::zero)
|
|
}
|
|
|
|
fn balance(asset: Self::AssetId, who: &<T as SystemConfig>::AccountId) -> Self::Balance {
|
|
Pallet::<T, I>::balance(asset, who)
|
|
}
|
|
|
|
fn reducible_balance(
|
|
asset: Self::AssetId,
|
|
who: &<T as SystemConfig>::AccountId,
|
|
keep_alive: bool,
|
|
) -> Self::Balance {
|
|
Pallet::<T, I>::reducible_balance(asset, who, keep_alive).unwrap_or(Zero::zero())
|
|
}
|
|
|
|
fn can_deposit(
|
|
asset: Self::AssetId,
|
|
who: &<T as SystemConfig>::AccountId,
|
|
amount: Self::Balance,
|
|
) -> DepositConsequence {
|
|
Pallet::<T, I>::can_increase(asset, who, amount)
|
|
}
|
|
|
|
fn can_withdraw(
|
|
asset: Self::AssetId,
|
|
who: &<T as SystemConfig>::AccountId,
|
|
amount: Self::Balance,
|
|
) -> WithdrawConsequence<Self::Balance> {
|
|
Pallet::<T, I>::can_decrease(asset, who, amount, false)
|
|
}
|
|
}
|
|
|
|
impl<T: Config<I>, I: 'static> fungibles::Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
|
|
fn mint_into(
|
|
asset: Self::AssetId,
|
|
who: &<T as SystemConfig>::AccountId,
|
|
amount: Self::Balance,
|
|
) -> DispatchResult {
|
|
Self::do_mint(asset, who, amount, None)
|
|
}
|
|
|
|
fn burn_from(
|
|
asset: Self::AssetId,
|
|
who: &<T as SystemConfig>::AccountId,
|
|
amount: Self::Balance,
|
|
) -> Result<Self::Balance, DispatchError> {
|
|
let f = DebitFlags {
|
|
keep_alive: false,
|
|
best_effort: false,
|
|
};
|
|
Self::do_burn(asset, who, amount, None, f)
|
|
}
|
|
|
|
fn slash(
|
|
asset: Self::AssetId,
|
|
who: &<T as SystemConfig>::AccountId,
|
|
amount: Self::Balance,
|
|
) -> Result<Self::Balance, DispatchError> {
|
|
let f = DebitFlags {
|
|
keep_alive: false,
|
|
best_effort: true,
|
|
};
|
|
Self::do_burn(asset, who, amount, None, f)
|
|
}
|
|
}
|
|
|
|
impl<T: Config<I>, I: 'static> fungibles::Transfer<T::AccountId> for Pallet<T, I> {
|
|
fn transfer(
|
|
asset: Self::AssetId,
|
|
source: &T::AccountId,
|
|
dest: &T::AccountId,
|
|
amount: T::Balance,
|
|
keep_alive: bool,
|
|
) -> Result<T::Balance, DispatchError> {
|
|
let f = TransferFlags {
|
|
keep_alive,
|
|
best_effort: false,
|
|
burn_dust: false
|
|
};
|
|
Self::do_transfer(asset, source, dest, amount, None, f)
|
|
}
|
|
}
|
|
|
|
impl<T: Config<I>, I: 'static> fungibles::Unbalanced<T::AccountId> for Pallet<T, I> {
|
|
fn set_balance(_: Self::AssetId, _: &T::AccountId, _: Self::Balance) -> DispatchResult {
|
|
unreachable!("set_balance is not used if other functions are impl'd");
|
|
}
|
|
fn set_total_issuance(id: T::AssetId, amount: Self::Balance) {
|
|
Asset::<T, I>::mutate_exists(id, |maybe_asset| {
|
|
if let Some(ref mut asset) = maybe_asset {
|
|
asset.supply = amount
|
|
}
|
|
});
|
|
}
|
|
fn decrease_balance(asset: T::AssetId, who: &T::AccountId, amount: Self::Balance)
|
|
-> Result<Self::Balance, DispatchError>
|
|
{
|
|
let f = DebitFlags { keep_alive: false, best_effort: false };
|
|
Self::decrease_balance(asset, who, amount, f, |_, _| Ok(()))
|
|
}
|
|
fn decrease_balance_at_most(asset: T::AssetId, who: &T::AccountId, amount: Self::Balance)
|
|
-> Self::Balance
|
|
{
|
|
let f = DebitFlags { keep_alive: false, best_effort: true };
|
|
Self::decrease_balance(asset, who, amount, f, |_, _| Ok(()))
|
|
.unwrap_or(Zero::zero())
|
|
}
|
|
fn increase_balance(asset: T::AssetId, who: &T::AccountId, amount: Self::Balance)
|
|
-> Result<Self::Balance, DispatchError>
|
|
{
|
|
Self::increase_balance(asset, who, amount, |_| Ok(()))?;
|
|
Ok(amount)
|
|
}
|
|
fn increase_balance_at_most(asset: T::AssetId, who: &T::AccountId, amount: Self::Balance)
|
|
-> Self::Balance
|
|
{
|
|
match Self::increase_balance(asset, who, amount, |_| Ok(())) {
|
|
Ok(()) => amount,
|
|
Err(_) => Zero::zero(),
|
|
}
|
|
}
|
|
}
|