mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 08:18:04 +00:00
Disallow decoding of phantom asset (#6597)
* Disallow decoding of phantom asset * Remove pub
This commit is contained in:
@@ -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.
|
||||
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user