Skip to content
Snippets Groups Projects
Unverified Commit 5b392758 authored by Xavier Lau's avatar Xavier Lau
Browse files

Resolve comments

parent a16ce7d6
No related merge requests found
Pipeline #512396 waiting for manual action with stages
in 45 seconds
......@@ -26,7 +26,7 @@ use crate::*;
const SEED: u32 = 0;
type BalanceOf<T> =
<<T as Config>::Currency as FunInspect<<T as frame_system::Config>::AccountId>>::Balance;
<<T as Config>::Currency as FungibleInspect<<T as frame_system::Config>::AccountId>>::Balance;
fn fill_queues<T: Config>() -> Result<(), DispatchError> {
// filling queues involves filling the first queue entirely and placing a single item in all
......
......@@ -90,25 +90,11 @@ pub use pallet::*;
pub use weights::WeightInfo;
use alloc::{vec, vec::Vec};
use frame::{
prelude::*,
traits::{
fungible::{
self, Balanced as FunBalanced, Inspect as FunInspect, Mutate as FunMutate,
MutateHold as FunMutateHold,
},
nonfungible::{Inspect as NftInspect, Transfer as NftTransfer},
tokens::{
Balance, DepositConsequence,
Fortitude::{self, *},
Precision::*,
Preservation::{self, *},
Provenance,
Restriction::*,
WithdrawConsequence,
},
},
};
use frame::prelude::*;
use Fortitude::*;
use Precision::*;
use Preservation::*;
use Restriction::*;
pub struct WithMaximumOf<A: TypedGet>(core::marker::PhantomData<A>);
impl<A: TypedGet> Convert<Perquintill, A::Type> for WithMaximumOf<A>
......@@ -132,7 +118,7 @@ where
}
pub struct NoCounterpart<T>(core::marker::PhantomData<T>);
impl<T> FunInspect<T> for NoCounterpart<T> {
impl<T> FungibleInspect<T> for NoCounterpart<T> {
type Balance = u32;
fn total_issuance() -> u32 {
0
......@@ -163,7 +149,7 @@ impl<T> fungible::Unbalanced<T> for NoCounterpart<T> {
}
fn set_total_issuance(_: Self::Balance) {}
}
impl<T: Eq> FunMutate<T> for NoCounterpart<T> {}
impl<T: Eq> FungibleMutate<T> for NoCounterpart<T> {}
impl<T> Convert<Perquintill, u32> for NoCounterpart<T> {
fn convert(_: Perquintill) -> u32 {
0
......@@ -186,8 +172,9 @@ impl BenchmarkSetup for () {
pub mod pallet {
use super::*;
type BalanceOf<T> =
<<T as Config>::Currency as FunInspect<<T as frame_system::Config>::AccountId>>::Balance;
type BalanceOf<T> = <<T as Config>::Currency as FungibleInspect<
<T as frame_system::Config>::AccountId,
>>::Balance;
type DebtOf<T> =
fungible::Debt<<T as frame_system::Config>::AccountId, <T as Config>::Currency>;
type ReceiptRecordOf<T> =
......@@ -210,10 +197,10 @@ pub mod pallet {
type PalletId: Get<PalletId>;
/// Currency type that this works on.
type Currency: FunInspect<Self::AccountId, Balance = Self::CurrencyBalance>
+ FunMutate<Self::AccountId>
+ FunBalanced<Self::AccountId>
+ FunMutateHold<Self::AccountId, Reason = Self::RuntimeHoldReason>;
type Currency: FungibleInspect<Self::AccountId, Balance = Self::CurrencyBalance>
+ FungibleMutate<Self::AccountId>
+ FungibleBalanced<Self::AccountId>
+ FungibleMutateHold<Self::AccountId, Reason = Self::RuntimeHoldReason>;
/// Overarching hold reason.
type RuntimeHoldReason: From<HoldReason>;
......@@ -230,7 +217,7 @@ pub mod pallet {
type IgnoredIssuance: Get<BalanceOf<Self>>;
/// The accounting system for the fungible counterpart tokens.
type Counterpart: FunMutate<Self::AccountId>;
type Counterpart: FungibleMutate<Self::AccountId>;
/// The system to convert an overall proportion of issuance into a number of fungible
/// counterpart tokens.
......@@ -238,7 +225,7 @@ pub mod pallet {
/// In general it's best to use `WithMaximumOf`.
type CounterpartAmount: ConvertBack<
Perquintill,
<Self::Counterpart as FunInspect<Self::AccountId>>::Balance,
<Self::Counterpart as FungibleInspect<Self::AccountId>>::Balance,
>;
/// Unbalanced handler to account for funds created (in case of a higher total issuance over
......@@ -930,7 +917,7 @@ pub mod pallet {
pub required: Balance,
}
impl<T: Config> NftInspect<T::AccountId> for Pallet<T> {
impl<T: Config> NonFungibleInspect<T::AccountId> for Pallet<T> {
type ItemId = ReceiptIndex;
fn owner(item: &ReceiptIndex) -> Option<T::AccountId> {
......@@ -949,7 +936,7 @@ pub mod pallet {
}
}
impl<T: Config> NftTransfer<T::AccountId> for Pallet<T> {
impl<T: Config> NonFungibleTransfer<T::AccountId> for Pallet<T> {
fn transfer(index: &ReceiptIndex, dest: &T::AccountId) -> DispatchResult {
let mut item = Receipts::<T>::get(index).ok_or(TokenError::UnknownAsset)?;
let (owner, on_hold) = item.owner.take().ok_or(Error::<T>::AlreadyCommunal)?;
......
......@@ -17,10 +17,7 @@
//! Tests for NIS pallet.
use frame::{
runtime::prelude::TokenError::FundsUnavailable, testing_prelude::*,
traits::fungible::InspectHold,
};
use frame::{runtime::prelude::*, testing_prelude::*};
use crate::{
mock::{Balance, *},
......@@ -72,7 +69,7 @@ fn place_bid_works() {
new_test_ext().execute_with(|| {
System::run_to_block::<AllPalletsWithSystem>(1);
assert_noop!(Nis::place_bid(signed(1), 1, 2), Error::<Test>::AmountTooSmall);
assert_noop!(Nis::place_bid(signed(1), 101, 2), FundsUnavailable);
assert_noop!(Nis::place_bid(signed(1), 101, 2), TokenError::FundsUnavailable);
assert_noop!(Nis::place_bid(signed(1), 10, 4), Error::<Test>::DurationTooBig);
assert_ok!(Nis::place_bid(signed(1), 10, 2));
assert_eq!(Balances::reserved_balance(1), 10);
......
......@@ -206,9 +206,11 @@ pub mod prelude {
pub use frame_support::{
defensive, defensive_assert,
traits::{
Contains, EitherOf, EstimateNextSessionRotation, IsSubType, MapSuccess, NoOpPoll,
OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
Contains, Defensive, DefensiveSaturating, EitherOf, EstimateNextSessionRotation,
IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade, OneSessionHandler, RankedMembers,
RankedMembersSwapHandler,
},
PalletId,
};
/// Pallet prelude of `frame-system`.
......@@ -229,11 +231,15 @@ pub mod prelude {
/// All arithmetic types and traits used for safe math.
pub use super::arithmetic::*;
/// All token related types and traits.
pub use super::token::*;
/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
AccountIdConversion, BlockNumberProvider, Bounded, Convert, ConvertBack, DispatchInfoOf,
Dispatchable, ReduceBy, ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup,
TrailingZeroInput,
};
/// Other error/result types for runtime
#[doc(no_inline)]
......@@ -533,6 +539,20 @@ pub mod arithmetic {
pub use sp_arithmetic::{traits::*, *};
}
/// All token related types and traits.
pub mod token {
pub use frame_support::traits::{
fungible::{
Balanced as FungibleBalanced, Inspect as FungibleInspect,
InspectHold as FungibleInspectHold, Mutate as FungibleMutate,
MutateHold as FungibleMutateHold,
},
nonfungible::{Inspect as NonFungibleInspect, Transfer as NonFungibleTransfer},
tokens::*,
OnUnbalanced,
};
}
/// All derive macros used in frame.
///
/// This is already part of the [`prelude`].
......
......@@ -910,7 +910,7 @@ pub mod pallet_prelude {
Task, TypedGet,
},
Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity,
PalletId, PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat,
PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat,
};
pub use codec::{Decode, Encode, MaxEncodedLen};
pub use core::marker::PhantomData;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment