mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Make pallet Assets instantiable (#8483)
* Make pallet Assets instantiable * use instantiable benchmarks Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
+141
-114
@@ -165,13 +165,13 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(_);
|
||||
pub struct Pallet<T, I = ()>(_);
|
||||
|
||||
#[pallet::config]
|
||||
/// The module configuration trait.
|
||||
pub trait Config: frame_system::Config {
|
||||
pub trait Config<I: 'static = ()>: frame_system::Config {
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// The units in which we record balances.
|
||||
type Balance: Member + Parameter + AtLeast32BitUnsigned + Default + Copy;
|
||||
@@ -187,17 +187,17 @@ pub mod pallet {
|
||||
type ForceOrigin: EnsureOrigin<Self::Origin>;
|
||||
|
||||
/// The basic amount of funds that must be reserved for an asset.
|
||||
type AssetDeposit: Get<DepositBalanceOf<Self>>;
|
||||
type AssetDeposit: Get<DepositBalanceOf<Self, I>>;
|
||||
|
||||
/// The basic amount of funds that must be reserved when adding metadata to your asset.
|
||||
type MetadataDepositBase: Get<DepositBalanceOf<Self>>;
|
||||
type MetadataDepositBase: Get<DepositBalanceOf<Self, I>>;
|
||||
|
||||
/// The additional funds that must be reserved for the number of bytes you store in your
|
||||
/// metadata.
|
||||
type MetadataDepositPerByte: Get<DepositBalanceOf<Self>>;
|
||||
type MetadataDepositPerByte: Get<DepositBalanceOf<Self, I>>;
|
||||
|
||||
/// The amount of funds that must be reserved when creating a new approval.
|
||||
type ApprovalDeposit: Get<DepositBalanceOf<Self>>;
|
||||
type ApprovalDeposit: Get<DepositBalanceOf<Self, I>>;
|
||||
|
||||
/// The maximum length of a name or symbol stored on-chain.
|
||||
type StringLimit: Get<u32>;
|
||||
@@ -215,16 +215,16 @@ pub mod pallet {
|
||||
|
||||
#[pallet::storage]
|
||||
/// Details of an asset.
|
||||
pub(super) type Asset<T: Config> = StorageMap<
|
||||
pub(super) type Asset<T: Config<I>, I: 'static = ()> = StorageMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
T::AssetId,
|
||||
AssetDetails<T::Balance, T::AccountId, DepositBalanceOf<T>>,
|
||||
AssetDetails<T::Balance, T::AccountId, DepositBalanceOf<T, I>>,
|
||||
>;
|
||||
|
||||
#[pallet::storage]
|
||||
/// The number of units of assets held by any given account.
|
||||
pub(super) type Account<T: Config> = StorageDoubleMap<
|
||||
pub(super) type Account<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
T::AssetId,
|
||||
@@ -237,30 +237,34 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
/// Approved balance transfers. First balance is the amount approved for transfer. Second
|
||||
/// is the amount of `T::Currency` reserved for storing this.
|
||||
pub(super) type Approvals<T: Config> = StorageDoubleMap<
|
||||
pub(super) type Approvals<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
T::AssetId,
|
||||
Blake2_128Concat,
|
||||
ApprovalKey<T::AccountId>,
|
||||
Approval<T::Balance, DepositBalanceOf<T>>,
|
||||
Approval<T::Balance, DepositBalanceOf<T, I>>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
#[pallet::storage]
|
||||
/// Metadata of an asset.
|
||||
pub(super) type Metadata<T: Config> = StorageMap<
|
||||
pub(super) type Metadata<T: Config<I>, I: 'static = ()> = StorageMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
T::AssetId,
|
||||
AssetMetadata<DepositBalanceOf<T>>,
|
||||
AssetMetadata<DepositBalanceOf<T, I>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pallet::metadata(T::AccountId = "AccountId", T::Balance = "Balance", T::AssetId = "AssetId")]
|
||||
pub enum Event<T: Config> {
|
||||
#[pallet::metadata(
|
||||
T::AccountId = "AccountId",
|
||||
T::Balance = "Balance",
|
||||
T::AssetId = "AssetId"
|
||||
)]
|
||||
pub enum Event<T: Config<I>, I: 'static = ()> {
|
||||
/// Some asset class was created. \[asset_id, creator, owner\]
|
||||
Created(T::AssetId, T::AccountId, T::AccountId),
|
||||
/// Some assets were issued. \[asset_id, owner, total_supply\]
|
||||
@@ -305,7 +309,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
pub enum Error<T, I = ()> {
|
||||
/// Account balance must be greater than or equal to the transfer amount.
|
||||
BalanceLow,
|
||||
/// Balance should be non-zero.
|
||||
@@ -335,10 +339,10 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// Issue a new class of fungible assets from a public origin.
|
||||
///
|
||||
/// This new asset class has no assets initially and its owner is the origin.
|
||||
@@ -368,26 +372,29 @@ pub mod pallet {
|
||||
let owner = ensure_signed(origin)?;
|
||||
let admin = T::Lookup::lookup(admin)?;
|
||||
|
||||
ensure!(!Asset::<T>::contains_key(id), Error::<T>::InUse);
|
||||
ensure!(!min_balance.is_zero(), Error::<T>::MinBalanceZero);
|
||||
ensure!(!Asset::<T, I>::contains_key(id), Error::<T, I>::InUse);
|
||||
ensure!(!min_balance.is_zero(), Error::<T, I>::MinBalanceZero);
|
||||
|
||||
let deposit = T::AssetDeposit::get();
|
||||
T::Currency::reserve(&owner, deposit)?;
|
||||
|
||||
Asset::<T>::insert(id, AssetDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: admin.clone(),
|
||||
admin: admin.clone(),
|
||||
freezer: admin.clone(),
|
||||
supply: Zero::zero(),
|
||||
deposit,
|
||||
min_balance,
|
||||
is_sufficient: false,
|
||||
accounts: 0,
|
||||
sufficients: 0,
|
||||
approvals: 0,
|
||||
is_frozen: false,
|
||||
});
|
||||
Asset::<T, I>::insert(
|
||||
id,
|
||||
AssetDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: admin.clone(),
|
||||
admin: admin.clone(),
|
||||
freezer: admin.clone(),
|
||||
supply: Zero::zero(),
|
||||
deposit,
|
||||
min_balance,
|
||||
is_sufficient: false,
|
||||
accounts: 0,
|
||||
sufficients: 0,
|
||||
approvals: 0,
|
||||
is_frozen: false,
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::Created(id, owner, admin));
|
||||
Ok(())
|
||||
}
|
||||
@@ -424,23 +431,26 @@ pub mod pallet {
|
||||
T::ForceOrigin::ensure_origin(origin)?;
|
||||
let owner = T::Lookup::lookup(owner)?;
|
||||
|
||||
ensure!(!Asset::<T>::contains_key(id), Error::<T>::InUse);
|
||||
ensure!(!min_balance.is_zero(), Error::<T>::MinBalanceZero);
|
||||
ensure!(!Asset::<T, I>::contains_key(id), Error::<T, I>::InUse);
|
||||
ensure!(!min_balance.is_zero(), Error::<T, I>::MinBalanceZero);
|
||||
|
||||
Asset::<T>::insert(id, AssetDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: owner.clone(),
|
||||
admin: owner.clone(),
|
||||
freezer: owner.clone(),
|
||||
supply: Zero::zero(),
|
||||
deposit: Zero::zero(),
|
||||
min_balance,
|
||||
is_sufficient,
|
||||
accounts: 0,
|
||||
sufficients: 0,
|
||||
approvals: 0,
|
||||
is_frozen: false,
|
||||
});
|
||||
Asset::<T, I>::insert(
|
||||
id,
|
||||
AssetDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: owner.clone(),
|
||||
admin: owner.clone(),
|
||||
freezer: owner.clone(),
|
||||
supply: Zero::zero(),
|
||||
deposit: Zero::zero(),
|
||||
min_balance,
|
||||
is_sufficient,
|
||||
accounts: 0,
|
||||
sufficients: 0,
|
||||
approvals: 0,
|
||||
is_frozen: false,
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::ForceCreated(id, owner));
|
||||
Ok(())
|
||||
}
|
||||
@@ -473,25 +483,28 @@ pub mod pallet {
|
||||
Ok(_) => None,
|
||||
Err(origin) => Some(ensure_signed(origin)?),
|
||||
};
|
||||
Asset::<T>::try_mutate_exists(id, |maybe_details| {
|
||||
let mut details = maybe_details.take().ok_or(Error::<T>::Unknown)?;
|
||||
Asset::<T, I>::try_mutate_exists(id, |maybe_details| {
|
||||
let mut details = maybe_details.take().ok_or(Error::<T, I>::Unknown)?;
|
||||
if let Some(check_owner) = maybe_check_owner {
|
||||
ensure!(details.owner == check_owner, Error::<T>::NoPermission);
|
||||
ensure!(details.owner == check_owner, Error::<T, I>::NoPermission);
|
||||
}
|
||||
ensure!(details.accounts == witness.accounts, Error::<T>::BadWitness);
|
||||
ensure!(details.sufficients == witness.sufficients, Error::<T>::BadWitness);
|
||||
ensure!(details.approvals == witness.approvals, Error::<T>::BadWitness);
|
||||
ensure!(details.accounts == witness.accounts, Error::<T, I>::BadWitness);
|
||||
ensure!(details.sufficients == witness.sufficients, Error::<T, I>::BadWitness);
|
||||
ensure!(details.approvals == witness.approvals, Error::<T, I>::BadWitness);
|
||||
|
||||
for (who, v) in Account::<T>::drain_prefix(id) {
|
||||
for (who, v) in Account::<T, I>::drain_prefix(id) {
|
||||
Self::dead_account(id, &who, &mut details, v.sufficient);
|
||||
}
|
||||
debug_assert_eq!(details.accounts, 0);
|
||||
debug_assert_eq!(details.sufficients, 0);
|
||||
|
||||
let metadata = Metadata::<T>::take(&id);
|
||||
T::Currency::unreserve(&details.owner, details.deposit.saturating_add(metadata.deposit));
|
||||
let metadata = Metadata::<T, I>::take(&id);
|
||||
T::Currency::unreserve(
|
||||
&details.owner,
|
||||
details.deposit.saturating_add(metadata.deposit),
|
||||
);
|
||||
|
||||
Approvals::<T>::remove_prefix(&id);
|
||||
Approvals::<T, I>::remove_prefix(&id);
|
||||
Self::deposit_event(Event::Destroyed(id));
|
||||
|
||||
// NOTE: could use postinfo to reflect the actual number of accounts/sufficient/approvals
|
||||
@@ -685,14 +698,17 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
let d = Asset::<T>::get(id).ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &d.freezer, Error::<T>::NoPermission);
|
||||
let d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &d.freezer, Error::<T, I>::NoPermission);
|
||||
let who = T::Lookup::lookup(who)?;
|
||||
ensure!(Account::<T>::contains_key(id, &who), Error::<T>::BalanceZero);
|
||||
ensure!(
|
||||
Account::<T, I>::contains_key(id, &who),
|
||||
Error::<T, I>::BalanceZero
|
||||
);
|
||||
|
||||
Account::<T>::mutate(id, &who, |a| a.is_frozen = true);
|
||||
Account::<T, I>::mutate(id, &who, |a| a.is_frozen = true);
|
||||
|
||||
Self::deposit_event(Event::<T>::Frozen(id, who));
|
||||
Self::deposit_event(Event::<T, I>::Frozen(id, who));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -715,14 +731,17 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
let details = Asset::<T>::get(id).ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &details.admin, Error::<T>::NoPermission);
|
||||
let details = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &details.admin, Error::<T, I>::NoPermission);
|
||||
let who = T::Lookup::lookup(who)?;
|
||||
ensure!(Account::<T>::contains_key(id, &who), Error::<T>::BalanceZero);
|
||||
ensure!(
|
||||
Account::<T, I>::contains_key(id, &who),
|
||||
Error::<T, I>::BalanceZero
|
||||
);
|
||||
|
||||
Account::<T>::mutate(id, &who, |a| a.is_frozen = false);
|
||||
Account::<T, I>::mutate(id, &who, |a| a.is_frozen = false);
|
||||
|
||||
Self::deposit_event(Event::<T>::Thawed(id, who));
|
||||
Self::deposit_event(Event::<T, I>::Thawed(id, who));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -742,13 +761,13 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
Asset::<T>::try_mutate(id, |maybe_details| {
|
||||
let d = maybe_details.as_mut().ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &d.freezer, Error::<T>::NoPermission);
|
||||
Asset::<T, I>::try_mutate(id, |maybe_details| {
|
||||
let d = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &d.freezer, Error::<T, I>::NoPermission);
|
||||
|
||||
d.is_frozen = true;
|
||||
|
||||
Self::deposit_event(Event::<T>::AssetFrozen(id));
|
||||
Self::deposit_event(Event::<T, I>::AssetFrozen(id));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -769,13 +788,13 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
Asset::<T>::try_mutate(id, |maybe_details| {
|
||||
let d = maybe_details.as_mut().ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &d.admin, Error::<T>::NoPermission);
|
||||
Asset::<T, I>::try_mutate(id, |maybe_details| {
|
||||
let d = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &d.admin, Error::<T, I>::NoPermission);
|
||||
|
||||
d.is_frozen = false;
|
||||
|
||||
Self::deposit_event(Event::<T>::AssetThawed(id));
|
||||
Self::deposit_event(Event::<T, I>::AssetThawed(id));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -799,12 +818,14 @@ pub mod pallet {
|
||||
let origin = ensure_signed(origin)?;
|
||||
let owner = T::Lookup::lookup(owner)?;
|
||||
|
||||
Asset::<T>::try_mutate(id, |maybe_details| {
|
||||
let details = maybe_details.as_mut().ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &details.owner, Error::<T>::NoPermission);
|
||||
if details.owner == owner { return Ok(()) }
|
||||
Asset::<T, I>::try_mutate(id, |maybe_details| {
|
||||
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &details.owner, Error::<T, I>::NoPermission);
|
||||
if details.owner == owner {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let metadata_deposit = Metadata::<T>::get(id).deposit;
|
||||
let metadata_deposit = Metadata::<T, I>::get(id).deposit;
|
||||
let deposit = details.deposit + metadata_deposit;
|
||||
|
||||
// Move the deposit to the new owner.
|
||||
@@ -842,9 +863,9 @@ pub mod pallet {
|
||||
let admin = T::Lookup::lookup(admin)?;
|
||||
let freezer = T::Lookup::lookup(freezer)?;
|
||||
|
||||
Asset::<T>::try_mutate(id, |maybe_details| {
|
||||
let details = maybe_details.as_mut().ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &details.owner, Error::<T>::NoPermission);
|
||||
Asset::<T, I>::try_mutate(id, |maybe_details| {
|
||||
let details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &details.owner, Error::<T, I>::NoPermission);
|
||||
|
||||
details.issuer = issuer.clone();
|
||||
details.admin = admin.clone();
|
||||
@@ -881,14 +902,17 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
ensure!(name.len() <= T::StringLimit::get() as usize, Error::<T>::BadMetadata);
|
||||
ensure!(symbol.len() <= T::StringLimit::get() as usize, Error::<T>::BadMetadata);
|
||||
ensure!(name.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata);
|
||||
ensure!(symbol.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata);
|
||||
|
||||
let d = Asset::<T>::get(id).ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &d.owner, Error::<T>::NoPermission);
|
||||
let d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &d.owner, Error::<T, I>::NoPermission);
|
||||
|
||||
Metadata::<T>::try_mutate_exists(id, |metadata| {
|
||||
ensure!(metadata.as_ref().map_or(true, |m| !m.is_frozen), Error::<T>::NoPermission);
|
||||
Metadata::<T, I>::try_mutate_exists(id, |metadata| {
|
||||
ensure!(
|
||||
metadata.as_ref().map_or(true, |m| !m.is_frozen),
|
||||
Error::<T, I>::NoPermission
|
||||
);
|
||||
|
||||
let old_deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit);
|
||||
let new_deposit = T::MetadataDepositPerByte::get()
|
||||
@@ -932,11 +956,11 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
|
||||
let d = Asset::<T>::get(id).ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &d.owner, Error::<T>::NoPermission);
|
||||
let d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &d.owner, Error::<T, I>::NoPermission);
|
||||
|
||||
Metadata::<T>::try_mutate_exists(id, |metadata| {
|
||||
let deposit = metadata.take().ok_or(Error::<T>::Unknown)?.deposit;
|
||||
Metadata::<T, I>::try_mutate_exists(id, |metadata| {
|
||||
let deposit = metadata.take().ok_or(Error::<T, I>::Unknown)?.deposit;
|
||||
T::Currency::unreserve(&d.owner, deposit);
|
||||
Self::deposit_event(Event::MetadataCleared(id));
|
||||
Ok(())
|
||||
@@ -968,11 +992,11 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
T::ForceOrigin::ensure_origin(origin)?;
|
||||
|
||||
ensure!(name.len() <= T::StringLimit::get() as usize, Error::<T>::BadMetadata);
|
||||
ensure!(symbol.len() <= T::StringLimit::get() as usize, Error::<T>::BadMetadata);
|
||||
ensure!(name.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata);
|
||||
ensure!(symbol.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata);
|
||||
|
||||
ensure!(Asset::<T>::contains_key(id), Error::<T>::Unknown);
|
||||
Metadata::<T>::try_mutate_exists(id, |metadata| {
|
||||
ensure!(Asset::<T, I>::contains_key(id), Error::<T, I>::Unknown);
|
||||
Metadata::<T, I>::try_mutate_exists(id, |metadata| {
|
||||
let deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit);
|
||||
*metadata = Some(AssetMetadata {
|
||||
deposit,
|
||||
@@ -1005,9 +1029,9 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
T::ForceOrigin::ensure_origin(origin)?;
|
||||
|
||||
let d = Asset::<T>::get(id).ok_or(Error::<T>::Unknown)?;
|
||||
Metadata::<T>::try_mutate_exists(id, |metadata| {
|
||||
let deposit = metadata.take().ok_or(Error::<T>::Unknown)?.deposit;
|
||||
let d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
|
||||
Metadata::<T, I>::try_mutate_exists(id, |metadata| {
|
||||
let deposit = metadata.take().ok_or(Error::<T, I>::Unknown)?.deposit;
|
||||
T::Currency::unreserve(&d.owner, deposit);
|
||||
Self::deposit_event(Event::MetadataCleared(id));
|
||||
Ok(())
|
||||
@@ -1050,8 +1074,8 @@ pub mod pallet {
|
||||
) -> DispatchResult {
|
||||
T::ForceOrigin::ensure_origin(origin)?;
|
||||
|
||||
Asset::<T>::try_mutate(id, |maybe_asset| {
|
||||
let mut asset = maybe_asset.take().ok_or(Error::<T>::Unknown)?;
|
||||
Asset::<T, I>::try_mutate(id, |maybe_asset| {
|
||||
let mut asset = maybe_asset.take().ok_or(Error::<T, I>::Unknown)?;
|
||||
asset.owner = T::Lookup::lookup(owner)?;
|
||||
asset.issuer = T::Lookup::lookup(issuer)?;
|
||||
asset.admin = T::Lookup::lookup(admin)?;
|
||||
@@ -1097,7 +1121,7 @@ pub mod pallet {
|
||||
let delegate = T::Lookup::lookup(delegate)?;
|
||||
|
||||
let key = ApprovalKey { owner, delegate };
|
||||
Approvals::<T>::try_mutate(id, &key, |maybe_approved| -> DispatchResult {
|
||||
Approvals::<T, I>::try_mutate(id, &key, |maybe_approved| -> DispatchResult {
|
||||
let mut approved = maybe_approved.take().unwrap_or_default();
|
||||
let deposit_required = T::ApprovalDeposit::get();
|
||||
if approved.deposit < deposit_required {
|
||||
@@ -1135,7 +1159,7 @@ pub mod pallet {
|
||||
let owner = ensure_signed(origin)?;
|
||||
let delegate = T::Lookup::lookup(delegate)?;
|
||||
let key = ApprovalKey { owner, delegate };
|
||||
let approval = Approvals::<T>::take(id, &key).ok_or(Error::<T>::Unknown)?;
|
||||
let approval = Approvals::<T, I>::take(id, &key).ok_or(Error::<T, I>::Unknown)?;
|
||||
T::Currency::unreserve(&key.owner, approval.deposit);
|
||||
|
||||
Self::deposit_event(Event::ApprovalCancelled(id, key.owner, key.delegate));
|
||||
@@ -1166,8 +1190,8 @@ pub mod pallet {
|
||||
.map(|_| ())
|
||||
.or_else(|origin| -> DispatchResult {
|
||||
let origin = ensure_signed(origin)?;
|
||||
let d = Asset::<T>::get(id).ok_or(Error::<T>::Unknown)?;
|
||||
ensure!(&origin == &d.admin, Error::<T>::NoPermission);
|
||||
let d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
|
||||
ensure!(&origin == &d.admin, Error::<T, I>::NoPermission);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -1175,7 +1199,7 @@ pub mod pallet {
|
||||
let delegate = T::Lookup::lookup(delegate)?;
|
||||
|
||||
let key = ApprovalKey { owner, delegate };
|
||||
let approval = Approvals::<T>::take(id, &key).ok_or(Error::<T>::Unknown)?;
|
||||
let approval = Approvals::<T, I>::take(id, &key).ok_or(Error::<T, I>::Unknown)?;
|
||||
T::Currency::unreserve(&key.owner, approval.deposit);
|
||||
|
||||
Self::deposit_event(Event::ApprovalCancelled(id, key.owner, key.delegate));
|
||||
@@ -1213,9 +1237,12 @@ pub mod pallet {
|
||||
let destination = T::Lookup::lookup(destination)?;
|
||||
|
||||
let key = ApprovalKey { owner, delegate };
|
||||
Approvals::<T>::try_mutate_exists(id, &key, |maybe_approved| -> DispatchResult {
|
||||
let mut approved = maybe_approved.take().ok_or(Error::<T>::Unapproved)?;
|
||||
let remaining = approved.amount.checked_sub(&amount).ok_or(Error::<T>::Unapproved)?;
|
||||
Approvals::<T, I>::try_mutate_exists(id, &key, |maybe_approved| -> DispatchResult {
|
||||
let mut approved = maybe_approved.take().ok_or(Error::<T, I>::Unapproved)?;
|
||||
let remaining = approved
|
||||
.amount
|
||||
.checked_sub(&amount)
|
||||
.ok_or(Error::<T, I>::Unapproved)?;
|
||||
|
||||
let f = TransferFlags {
|
||||
keep_alive: false,
|
||||
|
||||
Reference in New Issue
Block a user