From 825808a3d695e8176fc6b190f9719505e49bc3b8 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 15 Nov 2022 11:54:37 +0200 Subject: [PATCH 1/6] update docs formatting --- frame/support/src/traits/tokens/fungibles.rs | 44 ++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/frame/support/src/traits/tokens/fungibles.rs b/frame/support/src/traits/tokens/fungibles.rs index 9bdd5a10d7944..176fb1523b546 100644 --- a/frame/support/src/traits/tokens/fungibles.rs +++ b/frame/support/src/traits/tokens/fungibles.rs @@ -281,11 +281,41 @@ pub trait Destroy: Inspect { /// 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, - ) -> Result; + /// * `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; + + /// 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; + + /// 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; } From b613c3d1575659493b1c426f6f409dca462f7e36 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Fri, 11 Nov 2022 15:14:43 +0200 Subject: [PATCH 2/6] reintroduce the destroy trait --- frame/assets/src/impl_fungibles.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/frame/assets/src/impl_fungibles.rs b/frame/assets/src/impl_fungibles.rs index b005131176f49..d37ebf97e09ce 100644 --- a/frame/assets/src/impl_fungibles.rs +++ b/frame/assets/src/impl_fungibles.rs @@ -179,6 +179,28 @@ impl, I: 'static> fungibles::Create for Pallet } } +impl, I: 'static> fungibles::Destroy for Pallet { + fn start_destroy( + id: T::AssetId, + witness: Self::DestroyWitness, + maybe_check_owner: Option, + ) -> DispatchResult { + Self::do_start_destroy(id, maybe_check_owner) + } + + fn destroy_accounts(id: T::AssetId, max_items: u32) -> Result { + Self::do_destroy_accounts(id, max_items) + } + + fn destroy_approvals(id: T::AssetId, max_items: u32) -> Result { + Self::do_destroy_approvals(id, max_items) + } + + fn finish_destroy(id: T::AssetId) -> DispatchResult { + Self::do_finish_destroy(id) + } +} + impl, I: 'static> fungibles::metadata::Inspect<::AccountId> for Pallet { From 1e9572a4f86ff3d206b5b794803cba2d7d39abfc Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 15 Nov 2022 12:13:59 +0200 Subject: [PATCH 3/6] copy changes from original PR --- frame/support/src/traits/tokens/fungibles.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/frame/support/src/traits/tokens/fungibles.rs b/frame/support/src/traits/tokens/fungibles.rs index 176fb1523b546..8c370e9a0d8b5 100644 --- a/frame/support/src/traits/tokens/fungibles.rs +++ b/frame/support/src/traits/tokens/fungibles.rs @@ -267,19 +267,16 @@ pub trait Create: Inspect { /// Trait for providing the ability to destroy existing fungible assets. pub trait Destroy: Inspect { - /// 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; - - /// 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) -> 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 /// /// * `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 @@ -293,7 +290,6 @@ pub trait Destroy: Inspect { /// 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; - /// 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 From 786894230a846af9a867adf5f40831ebf087d62d Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 15 Nov 2022 12:20:00 +0200 Subject: [PATCH 4/6] remove witness --- Cargo.lock | 2 +- frame/assets/src/impl_fungibles.rs | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index beb234518041e..239395c95ccab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6329,8 +6329,8 @@ dependencies = [ "frame-support", "frame-system", "pallet-balances", - "pallet-root-testing", "pallet-collective", + "pallet-root-testing", "pallet-timestamp", "parity-scale-codec", "scale-info", diff --git a/frame/assets/src/impl_fungibles.rs b/frame/assets/src/impl_fungibles.rs index d37ebf97e09ce..6e0a9ac08ebb1 100644 --- a/frame/assets/src/impl_fungibles.rs +++ b/frame/assets/src/impl_fungibles.rs @@ -180,11 +180,7 @@ impl, I: 'static> fungibles::Create for Pallet } impl, I: 'static> fungibles::Destroy for Pallet { - fn start_destroy( - id: T::AssetId, - witness: Self::DestroyWitness, - maybe_check_owner: Option, - ) -> DispatchResult { + fn start_destroy(id: T::AssetId, maybe_check_owner: Option) -> DispatchResult { Self::do_start_destroy(id, maybe_check_owner) } From 1d8f82feaef8b58ea1b1f8bae587a8cf29a513b2 Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 15 Nov 2022 12:51:10 +0200 Subject: [PATCH 5/6] Trigger CI From 8f88c6bf06f5539694b7490eff0f629b93a7dc2f Mon Sep 17 00:00:00 2001 From: Anthony Alaribe Date: Tue, 15 Nov 2022 14:48:22 +0200 Subject: [PATCH 6/6] Trigger CI