multiversx_chain_vm/world_mock/
esdt_instance.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use num_bigint::BigUint;
use num_traits::Zero;

use super::EsdtInstanceMetadata;

/// Holds the data for a MultiversX standard digital token transaction
#[derive(Clone, Default, Debug)]
pub struct EsdtInstance {
    pub nonce: u64,
    pub balance: BigUint,
    pub metadata: EsdtInstanceMetadata,
}

impl EsdtInstance {
    pub fn default(nonce: u64) -> Self {
        EsdtInstance {
            nonce,
            balance: BigUint::zero(),
            metadata: EsdtInstanceMetadata::default(),
        }
    }

    pub fn fungible(balance: BigUint) -> Self {
        EsdtInstance {
            nonce: 0,
            balance,
            metadata: EsdtInstanceMetadata::default(),
        }
    }

    pub fn is_empty_esdt(&self) -> bool {
        self.balance.is_zero()
    }
}