numbat_wasm_debug/api/
call_value_api_mock.rs

1use crate::{TxContext, TxPanic};
2use numbat_wasm::{
3    api::CallValueApi,
4    err_msg,
5    types::{BigUint, DcdtTokenType, ManagedBuffer, TokenIdentifier},
6};
7
8impl CallValueApi for TxContext {
9    fn check_not_payable(&self) {
10        if self.rewa_value() > 0 {
11            std::panic::panic_any(TxPanic {
12                status: 10,
13                message: err_msg::NON_PAYABLE_FUNC_REWA.to_vec(),
14            });
15        }
16        if self.dcdt_value() > 0 {
17            std::panic::panic_any(TxPanic {
18                status: 10,
19                message: err_msg::NON_PAYABLE_FUNC_DCDT.to_vec(),
20            });
21        }
22    }
23
24    #[inline]
25    fn rewa_value(&self) -> BigUint<Self> {
26        self.insert_new_big_uint(self.tx_input_box.call_value.clone())
27    }
28
29    #[inline]
30    fn dcdt_value(&self) -> BigUint<Self> {
31        self.insert_new_big_uint(self.tx_input_box.dcdt_value.clone())
32    }
33
34    #[inline]
35    fn token(&self) -> TokenIdentifier<Self> {
36        ManagedBuffer::new_from_bytes(
37            self.clone(),
38            self.tx_input_box.dcdt_token_identifier.as_slice(),
39        )
40        .into()
41    }
42
43    #[inline]
44    fn dcdt_token_nonce(&self) -> u64 {
45        // TODO: Add DCDT nonce in mock
46        0u64
47    }
48
49    #[inline]
50    fn dcdt_token_type(&self) -> DcdtTokenType {
51        // TODO: Add DCDT token type in mock
52        DcdtTokenType::Fungible
53    }
54
55    // TODO: Mock multi-transfers
56
57    #[inline]
58    fn dcdt_num_transfers(&self) -> usize {
59        0
60    }
61
62    #[inline]
63    fn dcdt_value_by_index(&self, _index: usize) -> BigUint<Self> {
64        self.insert_new_big_uint_zero()
65    }
66
67    #[inline]
68    fn token_by_index(&self, _index: usize) -> TokenIdentifier<Self> {
69        TokenIdentifier::rewa(self.clone())
70    }
71
72    #[inline]
73    fn dcdt_token_nonce_by_index(&self, _index: usize) -> u64 {
74        0
75    }
76
77    #[inline]
78    fn dcdt_token_type_by_index(&self, _index: usize) -> DcdtTokenType {
79        DcdtTokenType::Fungible
80    }
81}