Skip to content

Commit

Permalink
new burn_from_caller tx for assets pallet to allow burn asset on caller
Browse files Browse the repository at this point in the history
add logic to validate that for native asset id should stay alive according to caller preference
  • Loading branch information
RustNinja committed Jul 24, 2024
1 parent 2c39f61 commit 7ae0e44
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
35 changes: 35 additions & 0 deletions code/parachain/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>,
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 = <Self as Inspect<T::AccountId>>::reducible_balance(
asset_id,
&who,
keep_alive,
Fortitude::Polite,
);
//want to keep alive account.
if amount > reducible_balance {
return Err(Error::<T>::InvalidCurrency.into());
}
}

<Self as Mutate<T::AccountId>>::burn_from(
asset_id,
&who,
amount,
Precision::BestEffort,
Fortitude::Polite,
)?;
Ok(().into())
}
}

pub(crate) fn valid_asset_id<T: Config>(asset_id: T::AssetId) -> Option<T::AssetId> {
Expand Down
2 changes: 1 addition & 1 deletion code/parachain/runtime/composable/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion code/parachain/runtime/picasso/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7ae0e44

Please sign in to comment.