Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
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
19 changes: 18 additions & 1 deletion xcm/src/v3/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl TryFrom<AssetInstance> for u128 {
}

/// Classification of whether an asset is fungible or not, along with a mandatory amount or instance.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum Fungibility {
/// A fungible asset; we record a number of units, as a `u128` in the inner item.
Expand All @@ -245,6 +245,23 @@ pub enum Fungibility {
NonFungible(AssetInstance),
}

#[derive(Decode)]
enum UncheckedFungibility {
Fungible(#[codec(compact)] u128),
NonFungible(AssetInstance),
}

impl Decode for Fungibility {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, parity_scale_codec::Error> {
match UncheckedFungibility::decode(input)? {
UncheckedFungibility::Fungible(a) if a != 0 => Ok(Self::Fungible(a)),
UncheckedFungibility::NonFungible(i) => Ok(Self::NonFungible(i)),
UncheckedFungibility::Fungible(_) =>
Err("Fungible asset of zero amount is not allowed".into()),
}
}
}

impl Fungibility {
pub fn is_kind(&self, w: WildFungibility) -> bool {
use Fungibility::*;
Expand Down