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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::{TxContext, TxPanic};
use elrond_wasm::{
    api::CallValueApi,
    err_msg,
    types::{BigUint, EsdtTokenType, ManagedBuffer, TokenIdentifier},
};

impl CallValueApi for TxContext {
    fn check_not_payable(&self) {
        if self.egld_value() > 0 {
            std::panic::panic_any(TxPanic {
                status: 10,
                message: err_msg::NON_PAYABLE_FUNC_EGLD.to_vec(),
            });
        }
        if self.esdt_value() > 0 {
            std::panic::panic_any(TxPanic {
                status: 10,
                message: err_msg::NON_PAYABLE_FUNC_ESDT.to_vec(),
            });
        }
    }

    #[inline]
    fn egld_value(&self) -> BigUint<Self> {
        self.insert_new_big_uint(self.tx_input_box.call_value.clone())
    }

    #[inline]
    fn esdt_value(&self) -> BigUint<Self> {
        self.insert_new_big_uint(self.tx_input_box.esdt_value.clone())
    }

    #[inline]
    fn token(&self) -> TokenIdentifier<Self> {
        ManagedBuffer::new_from_bytes(
            self.clone(),
            self.tx_input_box.esdt_token_identifier.as_slice(),
        )
        .into()
    }

    #[inline]
    fn esdt_token_nonce(&self) -> u64 {
        // TODO: Add ESDT nonce in mock
        0u64
    }

    #[inline]
    fn esdt_token_type(&self) -> EsdtTokenType {
        // TODO: Add ESDT token type in mock
        EsdtTokenType::Fungible
    }

    // TODO: Mock multi-transfers

    #[inline]
    fn esdt_num_transfers(&self) -> usize {
        0
    }

    #[inline]
    fn esdt_value_by_index(&self, _index: usize) -> BigUint<Self> {
        self.insert_new_big_uint_zero()
    }

    #[inline]
    fn token_by_index(&self, _index: usize) -> TokenIdentifier<Self> {
        TokenIdentifier::egld(self.clone())
    }

    #[inline]
    fn esdt_token_nonce_by_index(&self, _index: usize) -> u64 {
        0
    }

    #[inline]
    fn esdt_token_type_by_index(&self, _index: usize) -> EsdtTokenType {
        EsdtTokenType::Fungible
    }
}