From 7ae0e44f14189791bc9e8122b307d84841a4d3e1 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 24 Jul 2024 22:32:32 +0100 Subject: [PATCH] new burn_from_caller tx for assets pallet to allow burn asset on caller add logic to validate that for native asset id should stay alive according to caller preference --- code/parachain/frame/assets/src/lib.rs | 35 +++++++++++++++++++ .../runtime/composable/src/version.rs | 2 +- code/parachain/runtime/picasso/src/version.rs | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/code/parachain/frame/assets/src/lib.rs b/code/parachain/frame/assets/src/lib.rs index 4e82a81085..fff5cc3b39 100644 --- a/code/parachain/frame/assets/src/lib.rs +++ b/code/parachain/frame/assets/src/lib.rs @@ -376,6 +376,41 @@ pub mod pallet { )?; Ok(()) } + + #[pallet::call_index(12)] + #[pallet::weight(T::WeightInfo::burn_from())] + pub fn burn_from_caller( + origin: OriginFor, + asset_id: T::AssetId, + #[pallet::compact] amount: T::Balance, + keep_alive: bool, + ) -> DispatchResultWithPostInfo { + let who = ensure_signed(origin)?; + let is_native = T::NativeAssetId::get() == asset_id; + if keep_alive && is_native{ + let keep_alive = + if keep_alive { Preservation::Preserve } else { Preservation::Expendable }; + let reducible_balance = >::reducible_balance( + asset_id, + &who, + keep_alive, + Fortitude::Polite, + ); + //want to keep alive account. + if amount > reducible_balance { + return Err(Error::::InvalidCurrency.into()); + } + } + + >::burn_from( + asset_id, + &who, + amount, + Precision::BestEffort, + Fortitude::Polite, + )?; + Ok(().into()) + } } pub(crate) fn valid_asset_id(asset_id: T::AssetId) -> Option { diff --git a/code/parachain/runtime/composable/src/version.rs b/code/parachain/runtime/composable/src/version.rs index 46607fd491..ea6c556b75 100644 --- a/code/parachain/runtime/composable/src/version.rs +++ b/code/parachain/runtime/composable/src/version.rs @@ -13,7 +13,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // The version of the runtime specification. A full node will not attempt to use its native // runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, // `spec_version`, and `authoring_version` are the same between Wasm and native. - spec_version: 10045, + spec_version: 10046, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/code/parachain/runtime/picasso/src/version.rs b/code/parachain/runtime/picasso/src/version.rs index b858287e04..f376c38a16 100644 --- a/code/parachain/runtime/picasso/src/version.rs +++ b/code/parachain/runtime/picasso/src/version.rs @@ -16,7 +16,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // The version of the runtime specification. A full node will not attempt to use its native // runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, // `spec_version`, and `authoring_version` are the same between Wasm and native. - spec_version: 10045, + spec_version: 10046, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,