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

homa-lite: update cross-chain transfer #1341

Merged
merged 3 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 4 additions & 7 deletions modules/homa-lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use orml_traits::{MultiCurrency, XcmTransfer};
use primitives::{Balance, CurrencyId};
use sp_runtime::{traits::Zero, ArithmeticError, FixedPointNumber, Permill};
use sp_std::{ops::Mul, prelude::*};
use xcm::opaque::v0::{MultiLocation, Outcome};
use xcm::opaque::v0::MultiLocation;

pub use module::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -193,17 +193,14 @@ pub mod module {
.expect("Max rewards cannot be above 100%; qed");

// All checks pass. Proceed with Xcm transfer.
let xcm_result = T::XcmTransfer::transfer(
T::XcmTransfer::transfer(
who.clone(),
staking_currency,
amount,
T::SovereignSubAccountLocation::get(),
Self::xcm_dest_weight(),
)?;
ensure!(
matches!(xcm_result, Outcome::Complete(_)),
Error::<T>::XcmTransferFailed
);
)
.map_err(|_| Error::<T>::XcmTransferFailed)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to map the error (and drop original error), or we can throw the original error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we can throw the original error now, as transfer now returns a dispatch error. Will update.


// Mint the liquid currency into the user's account.
T::Currency::deposit(T::LiquidCurrencyId::get(), &who, liquid_to_mint)?;
Expand Down
14 changes: 7 additions & 7 deletions modules/homa-lite/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ use super::*;
use frame_support::{ord_parameter_types, parameter_types};
use frame_system::EnsureSignedBy;
use module_support::mocks::MockAddressMapping;
use orml_traits::{parameter_type_with_key, XcmExecutionResult, XcmTransfer};
use orml_traits::{parameter_type_with_key, XcmTransfer};
use primitives::{Amount, TokenSymbol};
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
use xcm::opaque::v0::{Junction, MultiAsset, MultiLocation, NetworkId, Outcome};
use xcm::opaque::v0::{Junction, MultiAsset, MultiLocation, NetworkId};

pub type AccountId = AccountId32;
pub type BlockNumber = u64;
Expand Down Expand Up @@ -75,10 +75,10 @@ impl XcmTransfer<AccountId, Balance, CurrencyId> for MockXcm {
_amount: Balance,
_dest: MultiLocation,
_dest_weight: Weight,
) -> XcmExecutionResult {
) -> DispatchResult {
match who {
INVALID_CALLER => Ok(Outcome::Error(xcm::opaque::v0::Error::Undefined)),
_ => Ok(Outcome::Complete(0)),
INVALID_CALLER => Err(DispatchError::Other("Invalid caller")),
_ => Ok(()),
}
}

Expand All @@ -88,8 +88,8 @@ impl XcmTransfer<AccountId, Balance, CurrencyId> for MockXcm {
_asset: MultiAsset,
_dest: MultiLocation,
_dest_weight: Weight,
) -> XcmExecutionResult {
Ok(Outcome::Complete(0))
) -> DispatchResult {
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion orml