numbat_wasm_debug/api/
blockchain_api_mock.rs1use crate::TxContext;
2use numbat_wasm::types::{Address, BigUint, DcdtTokenData, ManagedAddress, TokenIdentifier, H256};
3
4impl numbat_wasm::api::BlockchainApi for TxContext {
5 fn get_sc_address_legacy(&self) -> Address {
6 self.tx_input_box.to.clone()
7 }
8
9 fn get_owner_address_legacy(&self) -> Address {
10 self.blockchain_info_box
11 .contract_owner
12 .clone()
13 .unwrap_or_else(|| panic!("contract owner address not set"))
14 }
15
16 fn get_shard_of_address_legacy(&self, _address: &Address) -> u32 {
17 panic!("get_shard_of_address not implemented")
18 }
19
20 fn is_smart_contract_legacy(&self, _address: &Address) -> bool {
21 panic!("is_smart_contract not implemented")
22
23 }
33
34 fn get_caller_legacy(&self) -> Address {
35 self.tx_input_box.from.clone()
36 }
37
38 fn get_balance_legacy(&self, address: &Address) -> BigUint<Self> {
39 assert!(
40 address == &self.get_sc_address_legacy(),
41 "get balance not yet implemented for accounts other than the contract itself"
42 );
43 self.insert_new_big_uint(self.blockchain_info_box.contract_balance.clone())
44 }
45
46 fn get_state_root_hash_legacy(&self) -> H256 {
47 panic!("get_state_root_hash_legacy not yet implemented")
48 }
49
50 fn get_tx_hash_legacy(&self) -> H256 {
51 self.tx_input_box.tx_hash.clone()
52 }
53
54 fn get_gas_left(&self) -> u64 {
55 self.tx_input_box.gas_limit
56 }
57
58 fn get_block_timestamp(&self) -> u64 {
59 self.blockchain_info_box.current_block_info.block_timestamp
60 }
61
62 fn get_block_nonce(&self) -> u64 {
63 self.blockchain_info_box.current_block_info.block_nonce
64 }
65
66 fn get_block_round(&self) -> u64 {
67 self.blockchain_info_box.current_block_info.block_round
68 }
69
70 fn get_block_epoch(&self) -> u64 {
71 self.blockchain_info_box.current_block_info.block_epoch
72 }
73
74 fn get_block_random_seed_legacy(&self) -> Box<[u8; 48]> {
75 self.blockchain_info_box
76 .current_block_info
77 .block_random_seed
78 .clone()
79 }
80
81 fn get_prev_block_timestamp(&self) -> u64 {
82 self.blockchain_info_box.previous_block_info.block_timestamp
83 }
84
85 fn get_prev_block_nonce(&self) -> u64 {
86 self.blockchain_info_box.previous_block_info.block_nonce
87 }
88
89 fn get_prev_block_round(&self) -> u64 {
90 self.blockchain_info_box.previous_block_info.block_round
91 }
92
93 fn get_prev_block_epoch(&self) -> u64 {
94 self.blockchain_info_box.previous_block_info.block_epoch
95 }
96
97 fn get_prev_block_random_seed_legacy(&self) -> Box<[u8; 48]> {
98 self.blockchain_info_box
99 .previous_block_info
100 .block_random_seed
101 .clone()
102 }
103
104 fn get_current_dcdt_nft_nonce(
105 &self,
106 _address: &Address,
107 _token: &TokenIdentifier<Self>,
108 ) -> u64 {
109 0u64
111 }
112
113 fn get_dcdt_balance(
115 &self,
116 address: &ManagedAddress<Self>,
117 token: &TokenIdentifier<Self>,
118 _nonce: u64,
119 ) -> BigUint<Self> {
120 assert!(
121 address == &self.get_sc_address(),
122 "get_dcdt_balance not yet implemented for accounts other than the contract itself"
123 );
124
125 match self
126 .blockchain_info_box
127 .contract_dcdt
128 .get(&token.to_dcdt_identifier().into_vec())
129 {
130 Some(value) => self.insert_new_big_uint(value.clone()),
131 None => BigUint::zero(self.clone()),
132 }
133 }
134
135 fn get_dcdt_token_data(
136 &self,
137 _address: &ManagedAddress<Self>,
138 _token: &TokenIdentifier<Self>,
139 _nonce: u64,
140 ) -> DcdtTokenData<Self> {
141 panic!("get_dcdt_token_data not yet implemented")
142 }
143}