mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 08:51:09 +00:00
Fungibles and Non-Fungibles Create and Destroy Traits + Assets and Uniques Implementation (#9844)
* refactor `do_destroy` * destroy trait * refactor do_force_create * impl create trait * do not bleed weight into api * Do the same for uniques * add docs
This commit is contained in:
@@ -227,3 +227,39 @@ impl<AccountId, T: Balanced<AccountId> + MutateHold<AccountId>> BalancedHold<Acc
|
||||
<Self as fungibles::Balanced<AccountId>>::slash(asset, who, actual)
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for providing the ability to create new fungible assets.
|
||||
pub trait Create<AccountId>: Inspect<AccountId> {
|
||||
/// Create a new fungible asset.
|
||||
fn create(
|
||||
id: Self::AssetId,
|
||||
admin: AccountId,
|
||||
is_sufficient: bool,
|
||||
min_balance: Self::Balance,
|
||||
) -> DispatchResult;
|
||||
}
|
||||
|
||||
/// Trait for providing the ability to destroy existing fungible assets.
|
||||
pub trait Destroy<AccountId>: Inspect<AccountId> {
|
||||
/// The witness data needed to destroy an asset.
|
||||
type DestroyWitness;
|
||||
|
||||
/// Provide the appropriate witness data needed to destroy an asset.
|
||||
fn get_destroy_witness(id: &Self::AssetId) -> Option<Self::DestroyWitness>;
|
||||
|
||||
/// Destroy an existing fungible asset.
|
||||
/// * `id`: The `AssetId` to be destroyed.
|
||||
/// * `witness`: Any witness data that needs to be provided to complete the operation
|
||||
/// successfully.
|
||||
/// * `maybe_check_owner`: An optional account id that can be used to authorize the destroy
|
||||
/// command. If not provided, we will not do any authorization checks before destroying the
|
||||
/// asset.
|
||||
///
|
||||
/// If successful, this function will return the actual witness data from the destroyed asset.
|
||||
/// This may be different than the witness data provided, and can be used to refund weight.
|
||||
fn destroy(
|
||||
id: Self::AssetId,
|
||||
witness: Self::DestroyWitness,
|
||||
maybe_check_owner: Option<AccountId>,
|
||||
) -> Result<Self::DestroyWitness, DispatchError>;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//! Implementations of these traits may be converted to implementations of corresponding
|
||||
//! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter.
|
||||
|
||||
use crate::dispatch::DispatchResult;
|
||||
use crate::dispatch::{DispatchError, DispatchResult};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_runtime::TokenError;
|
||||
use sp_std::prelude::*;
|
||||
@@ -123,6 +123,31 @@ pub trait Create<AccountId>: Inspect<AccountId> {
|
||||
fn create_class(class: &Self::ClassId, who: &AccountId, admin: &AccountId) -> DispatchResult;
|
||||
}
|
||||
|
||||
/// Trait for providing the ability to destroy classes of nonfungible assets.
|
||||
pub trait Destroy<AccountId>: Inspect<AccountId> {
|
||||
/// The witness data needed to destroy an asset.
|
||||
type DestroyWitness;
|
||||
|
||||
/// Provide the appropriate witness data needed to destroy an asset.
|
||||
fn get_destroy_witness(class: &Self::ClassId) -> Option<Self::DestroyWitness>;
|
||||
|
||||
/// Destroy an existing fungible asset.
|
||||
/// * `class`: The `ClassId` to be destroyed.
|
||||
/// * `witness`: Any witness data that needs to be provided to complete the operation
|
||||
/// successfully.
|
||||
/// * `maybe_check_owner`: An optional account id that can be used to authorize the destroy
|
||||
/// command. If not provided, we will not do any authorization checks before destroying the
|
||||
/// asset.
|
||||
///
|
||||
/// If successful, this function will return the actual witness data from the destroyed asset.
|
||||
/// This may be different than the witness data provided, and can be used to refund weight.
|
||||
fn destroy(
|
||||
class: Self::ClassId,
|
||||
witness: Self::DestroyWitness,
|
||||
maybe_check_owner: Option<AccountId>,
|
||||
) -> Result<Self::DestroyWitness, DispatchError>;
|
||||
}
|
||||
|
||||
/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted,
|
||||
/// burned and/or have attributes set on them.
|
||||
pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
|
||||
Reference in New Issue
Block a user