mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
HoldReason: Improve usage (#13869)
* HoldReason: Improve usage `HoldReason` was switched recently to use the `composite_enum` attribute that will merge the enums from all pallets in the runtime to `RuntimeHoldReason`. `pallet-nis` was still requiring that the variant was passed as constant to call `hold`. The proper implementation is to use the `HoldReason` from inside the pallet directly when calling `hold`. This is done by adding a `RuntimeHoldReason` as type to the `Config` trait and requiring that `Currency` is using the same reason. Besides that the pr changes the name `HoldIdentifier` in `pallet_balances::Config` to `RuntimeHoldReason`. * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Review comment * Fixes --------- Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -245,7 +245,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ use pallet_nis::WithMaximumOf;
|
||||
use pallet_session::historical as pallet_session_historical;
|
||||
pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
|
||||
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
use sp_consensus_grandpa::AuthorityId as GrandpaId;
|
||||
@@ -439,17 +438,6 @@ parameter_types! {
|
||||
pub const MaxReserves: u32 = 50;
|
||||
}
|
||||
|
||||
/// A reason for placing a hold on funds.
|
||||
#[derive(
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, Debug, TypeInfo,
|
||||
)]
|
||||
pub enum HoldReason {
|
||||
/// The NIS Pallet has reserved it for a non-fungible receipt.
|
||||
Nis,
|
||||
/// Used by the NFT Fractionalization Pallet.
|
||||
NftFractionalization,
|
||||
}
|
||||
|
||||
impl pallet_balances::Config for Runtime {
|
||||
type MaxLocks = MaxLocks;
|
||||
type MaxReserves = MaxReserves;
|
||||
@@ -462,7 +450,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = HoldReason;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type MaxHolds = ConstU32<2>;
|
||||
}
|
||||
|
||||
@@ -1520,7 +1508,6 @@ parameter_types! {
|
||||
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
|
||||
pub Target: Perquintill = Perquintill::zero();
|
||||
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
|
||||
pub const NisHoldReason: HoldReason = HoldReason::Nis;
|
||||
}
|
||||
|
||||
impl pallet_nis::Config for Runtime {
|
||||
@@ -1544,7 +1531,7 @@ impl pallet_nis::Config for Runtime {
|
||||
type IntakePeriod = IntakePeriod;
|
||||
type MaxIntakeWeight = MaxIntakeWeight;
|
||||
type ThawThrottle = ThawThrottle;
|
||||
type HoldReason = NisHoldReason;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -1618,7 +1605,6 @@ parameter_types! {
|
||||
pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction");
|
||||
pub NewAssetSymbol: BoundedVec<u8, StringLimit> = (*b"FRAC").to_vec().try_into().unwrap();
|
||||
pub NewAssetName: BoundedVec<u8, StringLimit> = (*b"Frac").to_vec().try_into().unwrap();
|
||||
pub const NftFractionalizationHoldReason: HoldReason = HoldReason::NftFractionalization;
|
||||
}
|
||||
|
||||
impl pallet_nft_fractionalization::Config for Runtime {
|
||||
@@ -1636,7 +1622,7 @@ impl pallet_nft_fractionalization::Config for Runtime {
|
||||
type Nfts = Nfts;
|
||||
type PalletId = NftFractionalizationPalletId;
|
||||
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
|
||||
type HoldReason = NftFractionalizationHoldReason;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = ();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ use sc_executor_common::{
|
||||
};
|
||||
use sc_executor_wasmtime::InstantiationStrategy;
|
||||
use sc_runtime_test::wasm_binary_unwrap as test_runtime;
|
||||
use sp_wasm_interface::HostFunctions as _;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
Arc,
|
||||
|
||||
@@ -89,7 +89,7 @@ impl pallet_balances::Config for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ impl pallet_balances::Config for Test {
|
||||
type MaxLocks = ();
|
||||
type MaxReserves = ();
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type FreezeIdentifier = ();
|
||||
type MaxHolds = ();
|
||||
type MaxFreezes = ();
|
||||
|
||||
@@ -87,7 +87,7 @@ impl pallet_balances::Config for Test {
|
||||
type MaxLocks = ();
|
||||
type MaxReserves = ();
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxHolds = ();
|
||||
type MaxFreezes = ();
|
||||
|
||||
@@ -64,7 +64,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I> {
|
||||
impl<T: Config<I>, I: 'static> fungible::MutateHold<T::AccountId> for Pallet<T, I> {}
|
||||
|
||||
impl<T: Config<I>, I: 'static> fungible::InspectHold<T::AccountId> for Pallet<T, I> {
|
||||
type Reason = T::HoldIdentifier;
|
||||
type Reason = T::RuntimeHoldReason;
|
||||
|
||||
fn total_balance_on_hold(who: &T::AccountId) -> T::Balance {
|
||||
Self::account(who).reserved
|
||||
|
||||
@@ -257,8 +257,8 @@ pub mod pallet {
|
||||
/// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/`
|
||||
type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
|
||||
|
||||
/// The ID type for holds.
|
||||
type HoldIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
|
||||
/// The overarching hold reason.
|
||||
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy;
|
||||
|
||||
/// The ID type for freezes.
|
||||
type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
|
||||
@@ -437,7 +437,7 @@ pub mod pallet {
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
T::AccountId,
|
||||
BoundedVec<IdAmount<T::HoldIdentifier, T::Balance>, T::MaxHolds>,
|
||||
BoundedVec<IdAmount<T::RuntimeHoldReason, T::Balance>, T::MaxHolds>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ impl Config for Test {
|
||||
type MaxReserves = ConstU32<2>;
|
||||
type ReserveIdentifier = TestId;
|
||||
type WeightInfo = ();
|
||||
type HoldIdentifier = TestId;
|
||||
type RuntimeHoldReason = TestId;
|
||||
type FreezeIdentifier = TestId;
|
||||
type MaxFreezes = ConstU32<2>;
|
||||
type MaxHolds = ConstU32<2>;
|
||||
|
||||
@@ -161,7 +161,7 @@ impl pallet_balances::Config for Test {
|
||||
type ExistentialDeposit = ConstU128<1>;
|
||||
type AccountStore = System;
|
||||
type WeightInfo = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
|
||||
@@ -102,7 +102,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -105,7 +105,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -322,7 +322,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -256,7 +256,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type AccountStore = System;
|
||||
type MaxHolds = ConstU32<1>;
|
||||
type MaxFreezes = traits::ConstU32<1>;
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type FreezeIdentifier = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -1352,7 +1352,7 @@ mod tests {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -886,7 +886,7 @@ mod tests {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ConstU32<1>;
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ConstU32<1>;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ pub mod pallet {
|
||||
sp_runtime::traits::{AccountIdConversion, StaticLookup},
|
||||
traits::{
|
||||
fungible::{
|
||||
hold::{Inspect as HoldInspectFungible, Mutate as HoldMutateFungible},
|
||||
Inspect as InspectFungible, Mutate as MutateFungible,
|
||||
hold::Mutate as HoldMutateFungible, Inspect as InspectFungible,
|
||||
Mutate as MutateFungible,
|
||||
},
|
||||
fungibles::{
|
||||
metadata::{MetadataDeposit, Mutate as MutateMetadata},
|
||||
@@ -96,11 +96,10 @@ pub mod pallet {
|
||||
/// The currency mechanism, used for paying for deposits.
|
||||
type Currency: InspectFungible<Self::AccountId>
|
||||
+ MutateFungible<Self::AccountId>
|
||||
+ HoldInspectFungible<Self::AccountId>
|
||||
+ HoldMutateFungible<Self::AccountId>;
|
||||
+ HoldMutateFungible<Self::AccountId, Reason = Self::RuntimeHoldReason>;
|
||||
|
||||
#[pallet::constant]
|
||||
type HoldReason: Get<<Self::Currency as HoldInspectFungible<Self::AccountId>>::Reason>;
|
||||
/// Overarching hold reason.
|
||||
type RuntimeHoldReason: From<HoldReason>;
|
||||
|
||||
/// The deposit paid by the user locking an NFT. The deposit is returned to the original NFT
|
||||
/// owner when the asset is unified and the NFT is unlocked.
|
||||
@@ -201,6 +200,14 @@ pub mod pallet {
|
||||
NftNotFractionalized,
|
||||
}
|
||||
|
||||
/// A reason for the pallet placing a hold on funds.
|
||||
#[pallet::composite_enum]
|
||||
pub enum HoldReason {
|
||||
/// Reserved for a fractionalized NFT.
|
||||
#[codec(index = 0)]
|
||||
Fractionalized,
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Lock the NFT and mint a new fungible asset.
|
||||
@@ -239,7 +246,7 @@ pub mod pallet {
|
||||
|
||||
let pallet_account = Self::get_pallet_account();
|
||||
let deposit = T::Deposit::get();
|
||||
T::Currency::hold(&T::HoldReason::get(), &nft_owner, deposit)?;
|
||||
T::Currency::hold(&HoldReason::Fractionalized.into(), &nft_owner, deposit)?;
|
||||
Self::do_lock_nft(nft_collection_id, nft_id)?;
|
||||
Self::do_create_asset(asset_id.clone(), pallet_account.clone())?;
|
||||
Self::do_mint_asset(asset_id.clone(), &beneficiary, fractions)?;
|
||||
@@ -303,7 +310,12 @@ pub mod pallet {
|
||||
let asset_creator = details.asset_creator;
|
||||
Self::do_burn_asset(asset_id.clone(), &who, details.fractions)?;
|
||||
Self::do_unlock_nft(nft_collection_id, nft_id, &beneficiary)?;
|
||||
T::Currency::release(&T::HoldReason::get(), &asset_creator, deposit, BestEffort)?;
|
||||
T::Currency::release(
|
||||
&HoldReason::Fractionalized.into(),
|
||||
&asset_creator,
|
||||
deposit,
|
||||
BestEffort,
|
||||
)?;
|
||||
|
||||
Self::deposit_event(Event::NftUnified {
|
||||
nft_collection: nft_collection_id,
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
use super::*;
|
||||
use crate as pallet_nft_fractionalization;
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
construct_runtime, parameter_types,
|
||||
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64},
|
||||
@@ -28,7 +27,6 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::EnsureSigned;
|
||||
use pallet_nfts::PalletFeatures;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
@@ -83,13 +81,6 @@ impl frame_system::Config for Test {
|
||||
type MaxConsumers = ConstU32<16>;
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, Debug, TypeInfo,
|
||||
)]
|
||||
pub enum HoldIdentifier {
|
||||
NftFractionalization,
|
||||
}
|
||||
|
||||
impl pallet_balances::Config for Test {
|
||||
type Balance = u64;
|
||||
type DustRemoval = ();
|
||||
@@ -100,7 +91,7 @@ impl pallet_balances::Config for Test {
|
||||
type MaxLocks = ();
|
||||
type MaxReserves = ConstU32<50>;
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type HoldIdentifier = HoldIdentifier;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type MaxHolds = ConstU32<1>;
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
@@ -169,7 +160,6 @@ parameter_types! {
|
||||
pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction");
|
||||
pub NewAssetSymbol: BoundedVec<u8, StringLimit> = (*b"FRAC").to_vec().try_into().unwrap();
|
||||
pub NewAssetName: BoundedVec<u8, StringLimit> = (*b"Frac").to_vec().try_into().unwrap();
|
||||
pub const HoldReason: HoldIdentifier = HoldIdentifier::NftFractionalization;
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
@@ -189,7 +179,7 @@ impl Config for Test {
|
||||
type StringLimit = StringLimit;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = ();
|
||||
type HoldReason = HoldReason;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
}
|
||||
|
||||
// Build genesis storage according to the mock runtime.
|
||||
|
||||
@@ -90,7 +90,7 @@ impl pallet_balances::Config for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ mod tests {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -162,11 +162,7 @@ pub mod pallet {
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{
|
||||
fungible::{
|
||||
self,
|
||||
hold::{Inspect as FunHoldInspect, Mutate as FunHoldMutate},
|
||||
Balanced as FunBalanced,
|
||||
},
|
||||
fungible::{self, hold::Mutate as FunHoldMutate, Balanced as FunBalanced},
|
||||
nonfungible::{Inspect as NftInspect, Transfer as NftTransfer},
|
||||
tokens::{
|
||||
Fortitude::Polite,
|
||||
@@ -216,13 +212,10 @@ pub mod pallet {
|
||||
type Currency: FunInspect<Self::AccountId, Balance = Self::CurrencyBalance>
|
||||
+ FunMutate<Self::AccountId>
|
||||
+ FunBalanced<Self::AccountId>
|
||||
+ FunHoldInspect<Self::AccountId>
|
||||
+ FunHoldMutate<Self::AccountId>;
|
||||
+ FunHoldMutate<Self::AccountId, Reason = Self::RuntimeHoldReason>;
|
||||
|
||||
/// The identifier of the hold reason.
|
||||
|
||||
#[pallet::constant]
|
||||
type HoldReason: Get<<Self::Currency as FunHoldInspect<Self::AccountId>>::Reason>;
|
||||
/// Overarching hold reason.
|
||||
type RuntimeHoldReason: From<HoldReason>;
|
||||
|
||||
/// Just the `Currency::Balance` type; we have this item to allow us to constrain it to
|
||||
/// `From<u64>`.
|
||||
@@ -569,14 +562,14 @@ pub mod pallet {
|
||||
|q| -> Result<(u32, BalanceOf<T>), DispatchError> {
|
||||
let queue_full = q.len() == T::MaxQueueLen::get() as usize;
|
||||
ensure!(!queue_full || q[0].amount < amount, Error::<T>::BidTooLow);
|
||||
T::Currency::hold(&T::HoldReason::get(), &who, amount)?;
|
||||
T::Currency::hold(&HoldReason::NftReceipt.into(), &who, amount)?;
|
||||
|
||||
// queue is <Ordered: Lowest ... Highest><Fifo: Last ... First>
|
||||
let mut bid = Bid { amount, who: who.clone() };
|
||||
let net = if queue_full {
|
||||
sp_std::mem::swap(&mut q[0], &mut bid);
|
||||
let _ = T::Currency::release(
|
||||
&T::HoldReason::get(),
|
||||
&HoldReason::NftReceipt.into(),
|
||||
&bid.who,
|
||||
bid.amount,
|
||||
BestEffort,
|
||||
@@ -637,7 +630,7 @@ pub mod pallet {
|
||||
queue.remove(pos);
|
||||
let new_len = queue.len() as u32;
|
||||
|
||||
T::Currency::release(&T::HoldReason::get(), &bid.who, bid.amount, BestEffort)?;
|
||||
T::Currency::release(&HoldReason::NftReceipt.into(), &bid.who, bid.amount, BestEffort)?;
|
||||
|
||||
Queues::<T>::insert(duration, queue);
|
||||
QueueTotals::<T>::mutate(|qs| {
|
||||
@@ -729,7 +722,7 @@ pub mod pallet {
|
||||
let dropped = receipt.proportion.is_zero();
|
||||
|
||||
if amount > on_hold {
|
||||
T::Currency::release(&T::HoldReason::get(), &who, on_hold, Exact)?;
|
||||
T::Currency::release(&HoldReason::NftReceipt.into(), &who, on_hold, Exact)?;
|
||||
let deficit = amount - on_hold;
|
||||
// Try to transfer deficit from pot to receipt owner.
|
||||
summary.receipts_on_hold.saturating_reduce(on_hold);
|
||||
@@ -744,7 +737,7 @@ pub mod pallet {
|
||||
// Transfer excess of `on_hold` to the pot if we have now fully compensated for
|
||||
// the receipt.
|
||||
T::Currency::transfer_on_hold(
|
||||
&T::HoldReason::get(),
|
||||
&HoldReason::NftReceipt.into(),
|
||||
&who,
|
||||
&our_account,
|
||||
on_hold,
|
||||
@@ -760,7 +753,7 @@ pub mod pallet {
|
||||
)?;
|
||||
summary.receipts_on_hold.saturating_reduce(on_hold);
|
||||
}
|
||||
T::Currency::release(&T::HoldReason::get(), &who, amount, Exact)?;
|
||||
T::Currency::release(&HoldReason::NftReceipt.into(), &who, amount, Exact)?;
|
||||
}
|
||||
|
||||
if dropped {
|
||||
@@ -852,7 +845,7 @@ pub mod pallet {
|
||||
ensure!(owner == who, Error::<T>::NotOwner);
|
||||
|
||||
// Unreserve and transfer the funds to the pot.
|
||||
let reason = T::HoldReason::get();
|
||||
let reason = HoldReason::NftReceipt.into();
|
||||
let us = Self::account_id();
|
||||
T::Currency::transfer_on_hold(&reason, &who, &us, on_hold, Exact, Free, Polite)
|
||||
.map_err(|_| Error::<T>::Unfunded)?;
|
||||
@@ -903,7 +896,7 @@ pub mod pallet {
|
||||
)?;
|
||||
|
||||
// Transfer the funds from the pot to the owner and reserve
|
||||
let reason = T::HoldReason::get();
|
||||
let reason = HoldReason::NftReceipt.into();
|
||||
let us = Self::account_id();
|
||||
T::Currency::transfer_and_hold(&reason, &us, &who, amount, Exact, Expendable, Polite)?;
|
||||
|
||||
@@ -959,7 +952,7 @@ pub mod pallet {
|
||||
let mut item = Receipts::<T>::get(index).ok_or(TokenError::UnknownAsset)?;
|
||||
let (owner, on_hold) = item.owner.take().ok_or(Error::<T>::AlreadyCommunal)?;
|
||||
|
||||
let reason = T::HoldReason::get();
|
||||
let reason = HoldReason::NftReceipt.into();
|
||||
T::Currency::transfer_on_hold(&reason, &owner, dest, on_hold, Exact, OnHold, Polite)?;
|
||||
|
||||
item.owner = Some((dest.clone(), on_hold));
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
use crate::{self as pallet_nis, Perquintill, WithMaximumOf};
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
ord_parameter_types, parameter_types,
|
||||
traits::{
|
||||
@@ -30,7 +29,6 @@ use frame_support::{
|
||||
PalletId,
|
||||
};
|
||||
use pallet_balances::{Instance1, Instance2};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::{ConstU128, H256};
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
@@ -95,17 +93,10 @@ impl pallet_balances::Config<Instance1> for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = HoldIdentifier;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type MaxHolds = ConstU32<1>;
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, Debug, TypeInfo,
|
||||
)]
|
||||
pub enum HoldIdentifier {
|
||||
Nis,
|
||||
}
|
||||
|
||||
impl pallet_balances::Config<Instance2> for Test {
|
||||
type Balance = u128;
|
||||
type DustRemoval = ();
|
||||
@@ -122,7 +113,7 @@ impl pallet_balances::Config<Instance2> for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
@@ -133,7 +124,6 @@ parameter_types! {
|
||||
pub const MinReceipt: Perquintill = Perquintill::from_percent(1);
|
||||
pub const ThawThrottle: (Perquintill, u64) = (Perquintill::from_percent(25), 5);
|
||||
pub static MaxIntakeWeight: Weight = Weight::from_parts(2_000_000_000_000, 0);
|
||||
pub const HoldReason: HoldIdentifier = HoldIdentifier::Nis;
|
||||
}
|
||||
|
||||
ord_parameter_types! {
|
||||
@@ -161,7 +151,7 @@ impl pallet_nis::Config for Test {
|
||||
type MaxIntakeWeight = MaxIntakeWeight;
|
||||
type MinReceipt = MinReceipt;
|
||||
type ThawThrottle = ThawThrottle;
|
||||
type HoldReason = HoldReason;
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
}
|
||||
|
||||
// This function basically just builds a genesis storage key/value store according to
|
||||
|
||||
@@ -77,7 +77,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ impl pallet_balances::Config for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
impl pallet_utility::Config for Test {
|
||||
|
||||
@@ -88,7 +88,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -123,7 +123,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -1130,7 +1130,7 @@ mod mock {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ impl pallet_balances::Config for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -122,7 +122,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ impl pallet_balances::Config for Test {
|
||||
type ReserveIdentifier = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ impl pallet_balances::Config for Test {
|
||||
type ReserveIdentifier = [u8; 8];
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
parameter_types! {
|
||||
|
||||
@@ -88,7 +88,7 @@ impl pallet_balances::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = ();
|
||||
type MaxHolds = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -394,7 +394,7 @@ impl pallet_balances::Config for Runtime {
|
||||
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
|
||||
type FreezeIdentifier = ();
|
||||
type MaxFreezes = ();
|
||||
type HoldIdentifier = ();
|
||||
type RuntimeHoldReason = RuntimeHoldReason;
|
||||
type MaxHolds = ConstU32<1>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user