Rename Uniques Error::Unknown to something more sensible (#10895)

* Rename Uniques Error::Unknown to something more sensible

* Typos

* Typos

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Gavin Wood
2022-02-22 11:42:46 +01:00
committed by GitHub
parent eb5f07a2e5
commit 939d1b089c
3 changed files with 58 additions and 39 deletions
+28 -23
View File
@@ -303,7 +303,7 @@ pub mod pallet {
/// The signing account has no permission to do the operation.
NoPermission,
/// The given asset ID is unknown.
Unknown,
UnknownClass,
/// The asset instance ID has already been used for an asset.
AlreadyExists,
/// The owner turned out to be different to what was expected.
@@ -561,7 +561,8 @@ pub mod pallet {
) -> DispatchResult {
let origin = ensure_signed(origin)?;
let mut class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let mut class_details =
Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
ensure!(class_details.owner == origin, Error::<T, I>::NoPermission);
let deposit = match class_details.free_holding {
true => Zero::zero(),
@@ -621,8 +622,8 @@ pub mod pallet {
let origin = ensure_signed(origin)?;
let mut details =
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::Unknown)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
ensure!(class_details.freezer == origin, Error::<T, I>::NoPermission);
details.is_frozen = true;
@@ -651,8 +652,8 @@ pub mod pallet {
let origin = ensure_signed(origin)?;
let mut details =
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::Unknown)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
ensure!(class_details.admin == origin, Error::<T, I>::NoPermission);
details.is_frozen = false;
@@ -679,7 +680,7 @@ pub mod pallet {
let origin = ensure_signed(origin)?;
Class::<T, I>::try_mutate(class, |maybe_details| {
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
let details = maybe_details.as_mut().ok_or(Error::<T, I>::UnknownClass)?;
ensure!(&origin == &details.freezer, Error::<T, I>::NoPermission);
details.is_frozen = true;
@@ -706,7 +707,7 @@ pub mod pallet {
let origin = ensure_signed(origin)?;
Class::<T, I>::try_mutate(class, |maybe_details| {
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
let details = maybe_details.as_mut().ok_or(Error::<T, I>::UnknownClass)?;
ensure!(&origin == &details.admin, Error::<T, I>::NoPermission);
details.is_frozen = false;
@@ -736,7 +737,7 @@ pub mod pallet {
let owner = T::Lookup::lookup(owner)?;
Class::<T, I>::try_mutate(class, |maybe_details| {
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
let details = maybe_details.as_mut().ok_or(Error::<T, I>::UnknownClass)?;
ensure!(&origin == &details.owner, Error::<T, I>::NoPermission);
if details.owner == owner {
return Ok(())
@@ -784,7 +785,7 @@ pub mod pallet {
let freezer = T::Lookup::lookup(freezer)?;
Class::<T, I>::try_mutate(class, |maybe_details| {
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
let details = maybe_details.as_mut().ok_or(Error::<T, I>::UnknownClass)?;
ensure!(&origin == &details.owner, Error::<T, I>::NoPermission);
details.issuer = issuer.clone();
@@ -820,9 +821,9 @@ pub mod pallet {
let delegate = T::Lookup::lookup(delegate)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
let mut details =
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::Unknown)?;
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check) = maybe_check {
let permitted = &check == &class_details.admin || &check == &details.owner;
@@ -870,9 +871,9 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
let mut details =
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::Unknown)?;
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check) = maybe_check {
let permitted = &check == &class_details.admin || &check == &details.owner;
ensure!(permitted, Error::<T, I>::NoPermission);
@@ -925,7 +926,7 @@ pub mod pallet {
T::ForceOrigin::ensure_origin(origin)?;
Class::<T, I>::try_mutate(class, |maybe_asset| {
let mut asset = maybe_asset.take().ok_or(Error::<T, I>::Unknown)?;
let mut asset = maybe_asset.take().ok_or(Error::<T, I>::UnknownClass)?;
let old_owner = asset.owner;
let new_owner = T::Lookup::lookup(owner)?;
asset.owner = new_owner.clone();
@@ -972,7 +973,8 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some))?;
let mut class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let mut class_details =
Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check_owner) = &maybe_check_owner {
ensure!(check_owner == &class_details.owner, Error::<T, I>::NoPermission);
}
@@ -1033,7 +1035,8 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some))?;
let mut class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let mut class_details =
Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check_owner) = &maybe_check_owner {
ensure!(check_owner == &class_details.owner, Error::<T, I>::NoPermission);
}
@@ -1083,7 +1086,8 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some))?;
let mut class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let mut class_details =
Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check_owner) = &maybe_check_owner {
ensure!(check_owner == &class_details.owner, Error::<T, I>::NoPermission);
@@ -1142,7 +1146,8 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some))?;
let mut class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let mut class_details =
Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check_owner) = &maybe_check_owner {
ensure!(check_owner == &class_details.owner, Error::<T, I>::NoPermission);
}
@@ -1154,7 +1159,7 @@ pub mod pallet {
if metadata.is_some() {
class_details.instance_metadatas.saturating_dec();
}
let deposit = metadata.take().ok_or(Error::<T, I>::Unknown)?.deposit;
let deposit = metadata.take().ok_or(Error::<T, I>::UnknownClass)?.deposit;
T::Currency::unreserve(&class_details.owner, deposit);
class_details.total_deposit.saturating_reduce(deposit);
@@ -1191,7 +1196,7 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some))?;
let mut details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let mut details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check_owner) = &maybe_check_owner {
ensure!(check_owner == &details.owner, Error::<T, I>::NoPermission);
}
@@ -1245,7 +1250,7 @@ pub mod pallet {
.map(|_| None)
.or_else(|origin| ensure_signed(origin).map(Some))?;
let details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::Unknown)?;
let details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
if let Some(check_owner) = &maybe_check_owner {
ensure!(check_owner == &details.owner, Error::<T, I>::NoPermission);
}
@@ -1254,7 +1259,7 @@ pub mod pallet {
let was_frozen = metadata.as_ref().map_or(false, |m| m.is_frozen);
ensure!(maybe_check_owner.is_none() || !was_frozen, Error::<T, I>::Frozen);
let deposit = metadata.take().ok_or(Error::<T, I>::Unknown)?.deposit;
let deposit = metadata.take().ok_or(Error::<T, I>::UnknownClass)?.deposit;
T::Currency::unreserve(&details.owner, deposit);
Self::deposit_event(Event::ClassMetadataCleared { class });
Ok(())