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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use super::big_uint_api_mock::*;
use crate::TxContext;
use elrond_wasm::{
api::BigUintApi,
types::{Address, EsdtTokenData, H256},
};
impl elrond_wasm::api::BlockchainApi for TxContext {
type BalanceType = RustBigUint;
fn get_sc_address(&self) -> Address {
self.tx_input_box.to.clone()
}
fn get_owner_address(&self) -> Address {
self.blockchain_info_box
.contract_owner
.clone()
.unwrap_or_else(|| panic!("contract owner address not set"))
}
fn get_shard_of_address(&self, _address: &Address) -> u32 {
panic!("get_shard_of_address not implemented")
}
fn is_smart_contract(&self, _address: &Address) -> bool {
panic!("is_smart_contract not implemented")
}
fn get_caller(&self) -> Address {
self.tx_input_box.from.clone()
}
fn get_balance(&self, address: &Address) -> RustBigUint {
if address != &self.get_sc_address() {
panic!("get balance not yet implemented for accounts other than the contract itself");
}
self.blockchain_info_box.contract_balance.clone().into()
}
fn get_tx_hash(&self) -> H256 {
self.tx_input_box.tx_hash.clone()
}
fn get_gas_left(&self) -> u64 {
self.tx_input_box.gas_limit
}
fn get_block_timestamp(&self) -> u64 {
self.blockchain_info_box.current_block_info.block_timestamp
}
fn get_block_nonce(&self) -> u64 {
self.blockchain_info_box.current_block_info.block_nonce
}
fn get_block_round(&self) -> u64 {
self.blockchain_info_box.current_block_info.block_round
}
fn get_block_epoch(&self) -> u64 {
self.blockchain_info_box.current_block_info.block_epoch
}
fn get_block_random_seed(&self) -> Box<[u8; 48]> {
self.blockchain_info_box
.current_block_info
.block_random_seed
.clone()
}
fn get_prev_block_timestamp(&self) -> u64 {
self.blockchain_info_box.previous_block_info.block_timestamp
}
fn get_prev_block_nonce(&self) -> u64 {
self.blockchain_info_box.previous_block_info.block_nonce
}
fn get_prev_block_round(&self) -> u64 {
self.blockchain_info_box.previous_block_info.block_round
}
fn get_prev_block_epoch(&self) -> u64 {
self.blockchain_info_box.previous_block_info.block_epoch
}
fn get_prev_block_random_seed(&self) -> Box<[u8; 48]> {
self.blockchain_info_box
.previous_block_info
.block_random_seed
.clone()
}
fn get_current_esdt_nft_nonce(&self, _address: &Address, _token: &[u8]) -> u64 {
0u64
}
fn get_esdt_balance(&self, address: &Address, token: &[u8], _nonce: u64) -> RustBigUint {
if address != &self.get_sc_address() {
panic!(
"get_esdt_balance not yet implemented for accounts other than the contract itself"
);
}
match self.blockchain_info_box.contract_esdt.get(&token.to_vec()) {
Some(value) => value.clone().into(),
None => RustBigUint::zero(),
}
}
fn get_esdt_token_data(
&self,
_address: &Address,
_token: &[u8],
_nonce: u64,
) -> EsdtTokenData<RustBigUint> {
panic!("get_esdt_token_data not yet implemented")
}
}