Skip to content

Commit

Permalink
pallet assets: Fix errors (#4118)
Browse files Browse the repository at this point in the history
`LiveAsset` is an error to be returned when an asset is not supposed to
be live.
And `AssetNotLive` is an error to be returned when an asset is supposed
to be live, I don't think frozen qualifies as live.
  • Loading branch information
gui1117 committed Apr 15, 2024
1 parent 0c9ad53 commit a8f4f4f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

13 changes: 13 additions & 0 deletions prdoc/pr_4118.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: "pallet assets: minor improvement on errors returned for some calls"

doc:
- audience: Runtime Dev
description: |
Some calls in pallet assets have better errors. No new error is introduced, only more sensible choice are made.
- audience: Runtime User
description: |
Some calls in pallet assets have better errors. No new error is introduced, only more sensible choice are made.

crates:
- name: pallet-assets
bump: minor
2 changes: 1 addition & 1 deletion substrate/frame/assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-assets"
version = "29.0.0"
version = "29.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let d = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
d.status == AssetStatus::Live || d.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);

let actual = Self::decrease_balance(id.clone(), target, amount, f, |actual, details| {
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ pub mod pallet {
let d = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
d.status == AssetStatus::Live || d.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);
ensure!(origin == d.freezer, Error::<T, I>::NoPermission);
let who = T::Lookup::lookup(who)?;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ pub mod pallet {
let details = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
details.status == AssetStatus::Live || details.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);
ensure!(origin == details.admin, Error::<T, I>::NoPermission);
let who = T::Lookup::lookup(who)?;
Expand Down Expand Up @@ -1113,7 +1113,7 @@ pub mod pallet {

Asset::<T, I>::try_mutate(id.clone(), |maybe_details| {
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
ensure!(details.status == AssetStatus::Live, Error::<T, I>::LiveAsset);
ensure!(details.status == AssetStatus::Live, Error::<T, I>::AssetNotLive);
ensure!(origin == details.owner, Error::<T, I>::NoPermission);
if details.owner == owner {
return Ok(())
Expand Down Expand Up @@ -1669,7 +1669,7 @@ pub mod pallet {
let d = Asset::<T, I>::get(&id).ok_or(Error::<T, I>::Unknown)?;
ensure!(
d.status == AssetStatus::Live || d.status == AssetStatus::Frozen,
Error::<T, I>::AssetNotLive
Error::<T, I>::IncorrectStatus
);
ensure!(origin == d.freezer, Error::<T, I>::NoPermission);
let who = T::Lookup::lookup(who)?;
Expand Down

0 comments on commit a8f4f4f

Please sign in to comment.