Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed May 24, 2023
1 parent 15f2b9b commit 9d0200b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
3 changes: 1 addition & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,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 {
Expand All @@ -1624,7 +1623,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 = ();
}
Expand Down
1 change: 0 additions & 1 deletion client/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion frame/asset-rate/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
}
Expand Down
2 changes: 1 addition & 1 deletion frame/examples/dev-mode/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type HoldIdentifier = ();
type RuntimeHoldReason = RuntimeHoldReason;
type MaxHolds = ();
}

Expand Down
28 changes: 20 additions & 8 deletions frame/nft-fractionalization/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 2 additions & 12 deletions frame/nft-fractionalization/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
use super::*;
use crate as pallet_nft_fractionalization;

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
construct_runtime, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64},
BoundedVec, PalletId,
};
use frame_system::EnsureSigned;
use pallet_nfts::PalletFeatures;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{
testing::Header,
Expand Down Expand Up @@ -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 = ();
Expand All @@ -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 = ();
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion frame/statement/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ();
}

Expand Down
2 changes: 1 addition & 1 deletion test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand Down

0 comments on commit 9d0200b

Please sign in to comment.