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

Fix TransactAsset Implementation #3345

Merged
8 commits merged into from
Jul 26, 2021
8 changes: 8 additions & 0 deletions xcm/src/v0/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ use super::{MultiLocation, Xcm};
#[derive(Clone, Encode, Decode, Eq, PartialEq, Debug)]
pub enum Error {
Undefined,
/// An arithmetic overflow happened.
Overflow,
/// The operation is intentionally unsupported.
Unimplemented,
UnhandledXcmVersion,
/// The implementation does not handle a given XCM.
UnhandledXcmMessage,
/// The implementation does not handle an effect present in an XCM.
UnhandledEffect,
EscalationOfPrivilege,
UntrustedReserveLocation,
Expand All @@ -43,10 +46,15 @@ pub enum Error {
FailedToDecode,
BadOrigin,
ExceedsMaxMessageSize,
/// An asset transaction (like withdraw or deposit) failed.
/// See implementors of the `TransactAsset` trait for sources.
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
/// Causes can include type conversion failures between id or balance types.
FailedToTransactAsset(#[codec(skip)] &'static str),
/// Execution of the XCM would potentially result in a greater weight used than the pre-specified
/// weight limit. The amount that is potentially required is the parameter.
WeightLimitReached(Weight),
/// An asset wildcard was passed where it was not expected (e.g. as the asset to withdraw in a
/// `WithdrawAsset` XCM).
Wildcard,
/// The case where an XCM message has specified a optional weight limit and the weight required for
/// processing is too great.
Expand Down
2 changes: 1 addition & 1 deletion xcm/xcm-builder/src/currency_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl From<Error> for XcmError {
fn from(e: Error) -> Self {
use XcmError::FailedToTransactAsset;
match e {
Error::AssetNotFound => FailedToTransactAsset("AssetNotFound"),
Error::AssetNotFound => XcmError::AssetNotFound,
Error::AccountIdConversionFailed => FailedToTransactAsset("AccountIdConversionFailed"),
Error::AmountToBalanceConversionFailed => FailedToTransactAsset("AmountToBalanceConversionFailed"),
}
Expand Down
2 changes: 1 addition & 1 deletion xcm/xcm-executor/src/traits/matches_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl From<Error> for XcmError {
fn from(e: Error) -> Self {
use XcmError::FailedToTransactAsset;
match e {
Error::AssetNotFound => FailedToTransactAsset("AssetNotFound"),
Error::AssetNotFound => XcmError::AssetNotFound,
Error::AccountIdConversionFailed => FailedToTransactAsset("AccountIdConversionFailed"),
Error::AmountToBalanceConversionFailed => FailedToTransactAsset("AmountToBalanceConversionFailed"),
Error::AssetIdConversionFailed => FailedToTransactAsset("AssetIdConversionFailed"),
Expand Down
23 changes: 16 additions & 7 deletions xcm/xcm-executor/src/traits/transact_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,42 @@ impl TransactAsset for Tuple {

fn deposit_asset(what: &MultiAsset, who: &MultiLocation) -> XcmResult {
for_tuples!( #(
match Tuple::deposit_asset(what, who) { o @ Ok(_) => return o, _ => () }
match Tuple::deposit_asset(what, who) {
Err(XcmError::AssetNotFound) => (),
r => return r,
}
)* );
log::trace!(
target: "xcm::TransactAsset::deposit_asset",
"did not deposit asset: what: {:?}, who: {:?}",
what,
who,
);
Err(XcmError::Unimplemented)
Err(XcmError::AssetNotFound)
}

fn withdraw_asset(what: &MultiAsset, who: &MultiLocation) -> Result<Assets, XcmError> {
for_tuples!( #(
match Tuple::withdraw_asset(what, who) { o @ Ok(_) => return o, _ => () }
match Tuple::withdraw_asset(what, who) {
Err(XcmError::AssetNotFound) => (),
r => return r,
}
)* );
log::trace!(
target: "xcm::TransactAsset::withdraw_asset",
"did not withdraw asset: what: {:?}, who: {:?}",
what,
what,
who,
);
Err(XcmError::Unimplemented)
Err(XcmError::AssetNotFound)
}

fn transfer_asset(what: &MultiAsset, from: &MultiLocation, to: &MultiLocation) -> Result<Assets, XcmError> {
for_tuples!( #(
match Tuple::transfer_asset(what, from, to) { o @ Ok(_) => return o, _ => () }
match Tuple::transfer_asset(what, from, to) {
Err(XcmError::AssetNotFound) => (),
apopiak marked this conversation as resolved.
Show resolved Hide resolved
r => return r,
}
)* );
log::trace!(
target: "xcm::TransactAsset::transfer_asset",
Expand All @@ -165,6 +174,6 @@ impl TransactAsset for Tuple {
from,
to,
);
Err(XcmError::Unimplemented)
Err(XcmError::AssetNotFound)
}
}