use sp_std::result;
use xcm::latest::prelude::*;
pub trait MatchesFungible<Balance> {
fn matches_fungible(a: &MultiAsset) -> Option<Balance>;
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl<Balance> MatchesFungible<Balance> for Tuple {
fn matches_fungible(a: &MultiAsset) -> Option<Balance> {
for_tuples!( #(
match Tuple::matches_fungible(a) { o @ Some(_) => return o, _ => () }
)* );
log::trace!(target: "xcm::matches_fungible", "did not match fungible asset: {:?}", &a);
None
}
}
pub trait MatchesNonFungible<Instance> {
fn matches_nonfungible(a: &MultiAsset) -> Option<Instance>;
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl<Instance> MatchesNonFungible<Instance> for Tuple {
fn matches_nonfungible(a: &MultiAsset) -> Option<Instance> {
for_tuples!( #(
match Tuple::matches_nonfungible(a) { o @ Some(_) => return o, _ => () }
)* );
log::trace!(target: "xcm::matches_non_fungible", "did not match non-fungible asset: {:?}", &a);
None
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum Error {
AssetNotHandled,
AccountIdConversionFailed,
AmountToBalanceConversionFailed,
AssetIdConversionFailed,
InstanceConversionFailed,
}
impl From<Error> for XcmError {
fn from(e: Error) -> Self {
use XcmError::FailedToTransactAsset;
match e {
Error::AssetNotHandled => XcmError::AssetNotFound,
Error::AccountIdConversionFailed => FailedToTransactAsset("AccountIdConversionFailed"),
Error::AmountToBalanceConversionFailed =>
FailedToTransactAsset("AmountToBalanceConversionFailed"),
Error::AssetIdConversionFailed => FailedToTransactAsset("AssetIdConversionFailed"),
Error::InstanceConversionFailed => FailedToTransactAsset("InstanceConversionFailed"),
}
}
}
pub trait MatchesFungibles<AssetId, Balance> {
fn matches_fungibles(a: &MultiAsset) -> result::Result<(AssetId, Balance), Error>;
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl<AssetId, Balance> MatchesFungibles<AssetId, Balance> for Tuple {
fn matches_fungibles(a: &MultiAsset) -> result::Result<(AssetId, Balance), Error> {
for_tuples!( #(
match Tuple::matches_fungibles(a) { o @ Ok(_) => return o, _ => () }
)* );
log::trace!(target: "xcm::matches_fungibles", "did not match fungibles asset: {:?}", &a);
Err(Error::AssetNotHandled)
}
}
pub trait MatchesNonFungibles<AssetId, Instance> {
fn matches_nonfungibles(a: &MultiAsset) -> result::Result<(AssetId, Instance), Error>;
}
#[impl_trait_for_tuples::impl_for_tuples(30)]
impl<AssetId, Instance> MatchesNonFungibles<AssetId, Instance> for Tuple {
fn matches_nonfungibles(a: &MultiAsset) -> result::Result<(AssetId, Instance), Error> {
for_tuples!( #(
match Tuple::matches_nonfungibles(a) { o @ Ok(_) => return o, _ => () }
)* );
log::trace!(target: "xcm::matches_non_fungibles", "did not match fungibles asset: {:?}", &a);
Err(Error::AssetNotHandled)
}
}