Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Assets Pallet: reintroduce fungibles::Destroy trait (#12708)
Browse files Browse the repository at this point in the history
* update docs formatting

* reintroduce the destroy trait

* copy changes from original PR

* remove witness

* Trigger CI

* Trigger CI
  • Loading branch information
tonyalaribe committed Nov 30, 2022
1 parent 2dff067 commit bd029fc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,20 @@ impl<T: Config<I>, I: 'static> fungibles::Create<T::AccountId> for Pallet<T, I>
}

impl<T: Config<I>, I: 'static> fungibles::Destroy<T::AccountId> for Pallet<T, I> {
type DestroyWitness = DestroyWitness;
fn start_destroy(id: T::AssetId, maybe_check_owner: Option<T::AccountId>) -> DispatchResult {
Self::do_start_destroy(id, maybe_check_owner)
}

fn get_destroy_witness(asset: &T::AssetId) -> Option<Self::DestroyWitness> {
Asset::<T, I>::get(asset).map(|asset_details| asset_details.destroy_witness())
fn destroy_accounts(id: T::AssetId, max_items: u32) -> Result<u32, DispatchError> {
Self::do_destroy_accounts(id, max_items)
}

fn destroy(
id: T::AssetId,
witness: Self::DestroyWitness,
maybe_check_owner: Option<T::AccountId>,
) -> Result<Self::DestroyWitness, DispatchError> {
Self::do_destroy(id, witness, maybe_check_owner)
fn destroy_approvals(id: T::AssetId, max_items: u32) -> Result<u32, DispatchError> {
Self::do_destroy_approvals(id, max_items)
}

fn finish_destroy(id: T::AssetId) -> DispatchResult {
Self::do_finish_destroy(id)
}
}

Expand Down
62 changes: 44 additions & 18 deletions frame/support/src/traits/tokens/fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,51 @@ pub trait Create<AccountId>: Inspect<AccountId> {

/// 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.
/// Start the destruction an existing fungible asset.
/// * `id`: The `AssetId` to be destroyed. 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
/// command. If not provided, no authorization checks will be performed before destroying
/// asset.
fn start_destroy(id: Self::AssetId, maybe_check_owner: Option<AccountId>) -> DispatchResult;

/// Destroy all accounts associated with a given asset.
/// `destroy_accounts` should only be called after `start_destroy` has been called, and the
/// asset is in a `Destroying` state
///
/// 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>;
/// * `id`: The identifier of the asset to be destroyed. This must identify an existing asset.
/// * `max_items`: The maximum number of accounts to be destroyed for a given call of the
/// function. This value should be small enough to allow the operation fit into a logical
/// block.
///
/// Response:
/// * u32: Total number of approvals which were actually destroyed
///
/// Due to weight restrictions, this function may need to be called multiple
/// times to fully destroy all approvals. It will destroy `max_items` approvals at a
/// time.
fn destroy_accounts(id: Self::AssetId, max_items: u32) -> Result<u32, DispatchError>;
/// Destroy all approvals associated with a given asset up to the `max_items`
/// `destroy_approvals` should only be called after `start_destroy` has been called, and the
/// asset is in a `Destroying` state
///
/// * `id`: The identifier of the asset to be destroyed. This must identify an existing asset.
/// * `max_items`: The maximum number of accounts to be destroyed for a given call of the
/// function. This value should be small enough to allow the operation fit into a logical
/// block.
///
/// Response:
/// * u32: Total number of approvals which were actually destroyed
///
/// Due to weight restrictions, this function may need to be called multiple
/// times to fully destroy all approvals. It will destroy `max_items` approvals at a
/// time.
fn destroy_approvals(id: Self::AssetId, max_items: u32) -> Result<u32, DispatchError>;

/// Complete destroying asset and unreserve currency.
/// `finish_destroy` should only be called after `start_destroy` has been called, and the
/// asset is in a `Destroying` state. All accounts or approvals should be destroyed before
/// hand.
///
/// * `id`: The identifier of the asset to be destroyed. This must identify an existing asset.
fn finish_destroy(id: Self::AssetId) -> DispatchResult;
}

0 comments on commit bd029fc

Please sign in to comment.