Skip to content
New issue

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

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

Already on GitHub? # to your account

Removed getters in cross-in-out. #1402

Merged
merged 1 commit into from
Sep 3, 2024
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
22 changes: 8 additions & 14 deletions pallets/cross-in-out/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,20 @@ pub mod pallet {

/// To store currencies that support indirect cross-in and cross-out.
#[pallet::storage]
#[pallet::getter(fn get_cross_currency_registry)]
pub type CrossCurrencyRegistry<T> = StorageMap<_, Blake2_128Concat, CurrencyId, ()>;

/// Accounts in the whitelist can issue the corresponding Currency.
#[pallet::storage]
#[pallet::getter(fn get_issue_whitelist)]
pub type IssueWhiteList<T: Config> =
StorageMap<_, Blake2_128Concat, CurrencyId, BoundedVec<AccountIdOf<T>, T::MaxLengthLimit>>;

/// Accounts in the whitelist can register the mapping between a multilocation and an accountId.
#[pallet::storage]
#[pallet::getter(fn get_register_whitelist)]
pub type RegisterWhiteList<T> =
StorageMap<_, Blake2_128Concat, CurrencyId, Vec<AccountIdOf<T>>>;

/// Mapping a Bifrost account to a multilocation of a outer chain
#[pallet::storage]
#[pallet::getter(fn account_to_outer_multilocation)]
pub type AccountToOuterMultilocation<T> = StorageDoubleMap<
_,
Blake2_128Concat,
Expand All @@ -174,7 +170,6 @@ pub mod pallet {

/// Mapping a multilocation of a outer chain to a Bifrost account
#[pallet::storage]
#[pallet::getter(fn outer_multilocation_to_account)]
pub type OuterMultilocationToAccount<T> = StorageDoubleMap<
_,
Blake2_128Concat,
Expand All @@ -187,7 +182,6 @@ pub mod pallet {

/// minimum crossin and crossout amount【crossinMinimum, crossoutMinimum】
#[pallet::storage]
#[pallet::getter(fn get_crossing_minimum_amount)]
pub type CrossingMinimumAmount<T> =
StorageMap<_, Blake2_128Concat, CurrencyId, (BalanceOf<T>, BalanceOf<T>)>;

Expand Down Expand Up @@ -217,12 +211,12 @@ pub mod pallet {
Error::<T>::CurrencyNotSupportCrossInAndOut
);

let crossing_minimum_amount = Self::get_crossing_minimum_amount(currency_id)
let crossing_minimum_amount = CrossingMinimumAmount::<T>::get(currency_id)
.ok_or(Error::<T>::NoCrossingMinimumSet)?;
ensure!(amount >= crossing_minimum_amount.0, Error::<T>::AmountLowerThanMinimum);

let issue_whitelist =
Self::get_issue_whitelist(currency_id).ok_or(Error::<T>::NotAllowed)?;
IssueWhiteList::<T>::get(currency_id).ok_or(Error::<T>::NotAllowed)?;
ensure!(issue_whitelist.contains(&issuer), Error::<T>::NotAllowed);

let entrance_account_mutlilcaition = Box::new(MultiLocation {
Expand All @@ -237,7 +231,7 @@ pub mod pallet {
let dest = if entrance_account_mutlilcaition == location {
T::EntrancePalletId::get().into_account_truncating()
} else {
Self::outer_multilocation_to_account(currency_id, location.clone())
OuterMultilocationToAccount::<T>::get(currency_id, location.clone())
.ok_or(Error::<T>::NoAccountIdMapping)?
};

Expand Down Expand Up @@ -268,7 +262,7 @@ pub mod pallet {
Error::<T>::CurrencyNotSupportCrossInAndOut
);

let crossing_minimum_amount = Self::get_crossing_minimum_amount(currency_id)
let crossing_minimum_amount = CrossingMinimumAmount::<T>::get(currency_id)
.ok_or(Error::<T>::NoCrossingMinimumSet)?;
ensure!(amount >= crossing_minimum_amount.1, Error::<T>::AmountLowerThanMinimum);

Expand Down Expand Up @@ -296,7 +290,7 @@ pub mod pallet {
let registerer = ensure_signed(origin)?;

let register_whitelist =
Self::get_register_whitelist(currency_id).ok_or(Error::<T>::NotAllowed)?;
RegisterWhiteList::<T>::get(currency_id).ok_or(Error::<T>::NotAllowed)?;
ensure!(register_whitelist.contains(&registerer), Error::<T>::NotAllowed);

ensure!(
Expand Down Expand Up @@ -346,7 +340,7 @@ pub mod pallet {
);

let original_location =
Self::account_to_outer_multilocation(currency_id, account.clone())
AccountToOuterMultilocation::<T>::get(currency_id, account.clone())
.ok_or(Error::<T>::NotExist)?;
ensure!(original_location != *foreign_location.clone(), Error::<T>::AlreadyExist);

Expand Down Expand Up @@ -413,7 +407,7 @@ pub mod pallet {
) -> DispatchResult {
T::ControlOrigin::ensure_origin(origin)?;

let rs = Self::get_issue_whitelist(currency_id);
let rs = IssueWhiteList::<T>::get(currency_id);
let mut issue_whitelist;
if let Some(bounded_vec) = rs {
issue_whitelist = bounded_vec.to_vec();
Expand Down Expand Up @@ -471,7 +465,7 @@ pub mod pallet {
T::ControlOrigin::ensure_origin(origin)?;

let empty_vec: Vec<AccountIdOf<T>> = Vec::new();
if Self::get_register_whitelist(currency_id) == None {
if RegisterWhiteList::<T>::get(currency_id) == None {
RegisterWhiteList::<T>::insert(currency_id, empty_vec);
}

Expand Down
12 changes: 6 additions & 6 deletions pallets/cross-in-out/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ fn cross_in_and_cross_out_should_work() {
#[test]
fn add_to_and_remove_from_issue_whitelist_should_work() {
ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| {
assert_eq!(CrossInOut::get_issue_whitelist(KSM), None);
assert_eq!(IssueWhiteList::<Runtime>::get(KSM), None);

assert_ok!(CrossInOut::add_to_issue_whitelist(RuntimeOrigin::signed(ALICE), KSM, ALICE));
let bounded_vector = BoundedVec::try_from(vec![ALICE]).unwrap();
assert_eq!(CrossInOut::get_issue_whitelist(KSM), Some(bounded_vector));
assert_eq!(IssueWhiteList::<Runtime>::get(KSM), Some(bounded_vector));

assert_noop!(
CrossInOut::remove_from_issue_whitelist(RuntimeOrigin::signed(ALICE), KSM, BOB),
Expand All @@ -136,17 +136,17 @@ fn add_to_and_remove_from_issue_whitelist_should_work() {
ALICE
));
let empty_vec = BoundedVec::default();
assert_eq!(CrossInOut::get_issue_whitelist(KSM), Some(empty_vec));
assert_eq!(IssueWhiteList::<Runtime>::get(KSM), Some(empty_vec));
});
}

#[test]
fn add_to_and_remove_from_register_whitelist_should_work() {
ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| {
assert_eq!(CrossInOut::get_register_whitelist(KSM), None);
assert_eq!(RegisterWhiteList::<Runtime>::get(KSM), None);

assert_ok!(CrossInOut::add_to_register_whitelist(RuntimeOrigin::signed(ALICE), KSM, ALICE));
assert_eq!(CrossInOut::get_register_whitelist(KSM), Some(vec![ALICE]));
assert_eq!(RegisterWhiteList::<Runtime>::get(KSM), Some(vec![ALICE]));

assert_noop!(
CrossInOut::remove_from_register_whitelist(RuntimeOrigin::signed(ALICE), KSM, BOB),
Expand All @@ -158,7 +158,7 @@ fn add_to_and_remove_from_register_whitelist_should_work() {
KSM,
ALICE
));
assert_eq!(CrossInOut::get_register_whitelist(KSM), Some(vec![]));
assert_eq!(RegisterWhiteList::<Runtime>::get(KSM), Some(vec![]));
});
}

Expand Down