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
use super::{
BigIntApi, BigUintApi, CallValueApi, CryptoApi, ErrorApi, SendApi, StorageReadApi,
StorageWriteApi,
};
use crate::storage;
use crate::types::{Address, EsdtTokenData, H256};
use alloc::boxed::Box;
pub trait ContractHookApi<BigInt, BigUint>: Sized + CryptoApi
where
BigInt: BigIntApi<BigUint> + 'static,
BigUint: BigUintApi + 'static,
{
type Storage: StorageReadApi + StorageWriteApi + ErrorApi + Clone + 'static;
type CallValue: CallValueApi<BigUint> + ErrorApi + Clone + 'static;
type SendApi: SendApi<BigUint> + Clone + 'static;
fn get_storage_raw(&self) -> Self::Storage;
fn call_value(&self) -> Self::CallValue;
fn send(&self) -> Self::SendApi;
fn get_sc_address(&self) -> Address;
fn get_owner_address(&self) -> Address;
fn get_shard_of_address(&self, address: &Address) -> u32;
fn is_smart_contract(&self, address: &Address) -> bool;
fn get_caller(&self) -> Address;
fn get_balance(&self, address: &Address) -> BigUint;
fn get_sc_balance(&self) -> BigUint {
self.get_balance(&self.get_sc_address())
}
#[inline]
fn storage_load_cumulated_validator_reward(&self) -> BigUint {
storage::storage_get(
self.get_storage_raw(),
storage::protected_keys::ELROND_REWARD_KEY,
)
}
fn get_tx_hash(&self) -> H256;
fn get_gas_left(&self) -> u64;
fn get_block_timestamp(&self) -> u64;
fn get_block_nonce(&self) -> u64;
fn get_block_round(&self) -> u64;
fn get_block_epoch(&self) -> u64;
fn get_block_random_seed(&self) -> Box<[u8; 48]>;
fn get_prev_block_timestamp(&self) -> u64;
fn get_prev_block_nonce(&self) -> u64;
fn get_prev_block_round(&self) -> u64;
fn get_prev_block_epoch(&self) -> u64;
fn get_prev_block_random_seed(&self) -> Box<[u8; 48]>;
fn get_current_esdt_nft_nonce(&self, address: &Address, token: &[u8]) -> u64;
fn get_esdt_balance(&self, address: &Address, token: &[u8], nonce: u64) -> BigUint;
fn get_esdt_token_data(
&self,
address: &Address,
token: &[u8],
nonce: u64,
) -> EsdtTokenData<BigUint>;
}