Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate xpallets-assets to attribute macro #560

Merged
merged 8 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
405 changes: 222 additions & 183 deletions xpallets/assets/src/lib.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion xpallets/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
};

use frame_support::{parameter_types, sp_io};
use frame_support::{parameter_types, sp_io, traits::GenesisBuild};

use chainx_primitives::AssetId;
pub use xp_protocol::X_BTC;
Expand Down
14 changes: 7 additions & 7 deletions xpallets/assets/src/multicurrency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use frame_support::{
ensure,
log::error,
traits::{BalanceStatus, LockIdentifier},
transactional, IterableStorageDoubleMap,
transactional,
};

use orml_traits::{
Expand All @@ -22,9 +22,9 @@ use chainx_primitives::AssetId;
use xpallet_support::traits::TreasuryAccount;

use crate::types::{AssetType, BalanceLock};
use crate::{AssetBalance, BalanceOf, Config, Error, Module};
use crate::{AssetBalance, BalanceOf, Config, Error, Pallet};

impl<T: Config> MultiCurrency<T::AccountId> for Module<T> {
impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
type CurrencyId = AssetId;
type Balance = BalanceOf<T>;

Expand Down Expand Up @@ -173,7 +173,7 @@ impl<T: Config> MultiCurrency<T::AccountId> for Module<T> {
}
}

impl<T: Config> MultiCurrencyExtended<T::AccountId> for Module<T> {
impl<T: Config> MultiCurrencyExtended<T::AccountId> for Pallet<T> {
type Amount = T::Amount;

fn update_balance(
Expand All @@ -195,7 +195,7 @@ impl<T: Config> MultiCurrencyExtended<T::AccountId> for Module<T> {
}
}

impl<T: Config> MultiReservableCurrency<T::AccountId> for Module<T> {
impl<T: Config> MultiReservableCurrency<T::AccountId> for Pallet<T> {
fn can_reserve(
currency_id: Self::CurrencyId,
who: &T::AccountId,
Expand Down Expand Up @@ -326,7 +326,7 @@ impl<T: Config> MultiReservableCurrency<T::AccountId> for Module<T> {
}
}

impl<T: Config> MultiLockableCurrency<T::AccountId> for Module<T> {
impl<T: Config> MultiLockableCurrency<T::AccountId> for Pallet<T> {
type Moment = T::BlockNumber;

fn set_lock(
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<T: Config> MultiLockableCurrency<T::AccountId> for Module<T> {
}
}

impl<T: Config> MergeAccount<T::AccountId> for Module<T> {
impl<T: Config> MergeAccount<T::AccountId> for Pallet<T> {
#[transactional]
fn merge_account(source: &T::AccountId, dest: &T::AccountId) -> DispatchResult {
AssetBalance::<T>::iter_prefix(source).try_for_each(
Expand Down
10 changes: 5 additions & 5 deletions xpallets/assets/src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use chainx_primitives::AssetId;

use crate::traits::OnAssetChanged;
use crate::types::{AssetErr, AssetType};
use crate::{BalanceOf, Config, Event, Module};
use crate::{BalanceOf, Config, Event, Pallet};

impl<AccountId, Balance> OnAssetChanged<AccountId, Balance> for () {}

Expand All @@ -32,7 +32,7 @@ impl<T: Config> AssetChangedTrigger<T> {
to_type: AssetType,
value: BalanceOf<T>,
) -> Result<(), AssetErr> {
Module::<T>::deposit_event(Event::<T>::Moved(
Pallet::<T>::deposit_event(Event::<T>::Moved(
*id,
from.clone(),
from_type,
Expand All @@ -49,7 +49,7 @@ impl<T: Config> AssetChangedTrigger<T> {
}

pub fn on_issue_post(id: &AssetId, who: &T::AccountId, value: BalanceOf<T>) -> DispatchResult {
Module::<T>::deposit_event(Event::<T>::Issued(*id, who.clone(), value));
Pallet::<T>::deposit_event(Event::<T>::Issued(*id, who.clone(), value));
T::OnAssetChanged::on_issue_post(id, who, value)?;
Ok(())
}
Expand All @@ -63,7 +63,7 @@ impl<T: Config> AssetChangedTrigger<T> {
who: &T::AccountId,
value: BalanceOf<T>,
) -> DispatchResult {
Module::<T>::deposit_event(Event::<T>::Destroyed(*id, who.clone(), value));
Pallet::<T>::deposit_event(Event::<T>::Destroyed(*id, who.clone(), value));
T::OnAssetChanged::on_destroy_post(id, who, value)?;
Ok(())
}
Expand All @@ -74,7 +74,7 @@ impl<T: Config> AssetChangedTrigger<T> {
type_: AssetType,
value: BalanceOf<T>,
) -> DispatchResult {
Module::<T>::deposit_event(Event::<T>::BalanceSet(*id, who.clone(), type_, value));
Pallet::<T>::deposit_event(Event::<T>::BalanceSet(*id, who.clone(), type_, value));
T::OnAssetChanged::on_set_balance(id, who, type_, value)?;
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions xpallets/assets/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sp_std::marker::PhantomData;
pub trait WeightInfo {
fn transfer() -> Weight;
fn force_transfer() -> Weight;
fn set_balance(n: u32) -> Weight;
fn set_balance() -> Weight;
fn set_asset_limit() -> Weight;
}

Expand All @@ -49,7 +49,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(8 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
fn set_balance(_n: u32) -> Weight {
fn set_balance() -> Weight {
(218_742_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
Expand All @@ -73,7 +73,7 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(8 as Weight))
.saturating_add(RocksDbWeight::get().writes(6 as Weight))
}
fn set_balance(_n: u32) -> Weight {
fn set_balance() -> Weight {
(218_742_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
Expand Down
6 changes: 5 additions & 1 deletion xpallets/dex/spot/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ use std::{
collections::{BTreeMap, HashSet},
};

use frame_support::{parameter_types, traits::Get, weights::Weight};
use frame_support::{
parameter_types,
traits::{GenesisBuild, Get},
weights::Weight,
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
Expand Down
6 changes: 4 additions & 2 deletions xpallets/gateway/common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use std::{cell::RefCell, convert::TryFrom, time::Duration};

use codec::{Decode, Encode};
use frame_support::traits::UnixTime;
use frame_support::{parameter_types, sp_io};
use frame_support::{
parameter_types, sp_io,
traits::{GenesisBuild, UnixTime},
};
use frame_system::EnsureSignedBy;
use sp_core::{crypto::UncheckedInto, H256};
use sp_io::hashing::blake2_256;
Expand Down
5 changes: 3 additions & 2 deletions xpallets/gateway/records/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Copyright 2019-2020 ChainX Project Authors. Licensed under GPL-3.0.

use frame_support::{parameter_types, sp_io};
use frame_support::{parameter_types, sp_io, traits::GenesisBuild};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};

use chainx_primitives::AssetId;
pub use xp_protocol::{X_BTC, X_ETH};
use xpallet_assets::AssetRestrictions;
use xpallet_assets_registrar::AssetInfo;

pub use xp_protocol::{X_BTC, X_ETH};

use crate::{self as xpallet_gateway_records, *};

/// The AccountId alias in this test module.
Expand Down