unc_sys/
lib.rs

1#![no_std]
2
3extern "C" {
4    // #############
5    // # Registers #
6    // #############
7    pub fn read_register(register_id: u64, ptr: u64);
8    pub fn register_len(register_id: u64) -> u64;
9    pub fn write_register(register_id: u64, data_len: u64, data_ptr: u64);
10    // ###############
11    // # Context API #
12    // ###############
13    pub fn current_account_id(register_id: u64);
14    pub fn signer_account_id(register_id: u64);
15    pub fn signer_account_pk(register_id: u64);
16    pub fn predecessor_account_id(register_id: u64);
17    pub fn input(register_id: u64);
18    pub fn block_index() -> u64;
19    pub fn block_timestamp() -> u64;
20    pub fn epoch_height() -> u64;
21    pub fn storage_usage() -> u64;
22    // #################
23    // # Economics API #
24    // #################
25    pub fn account_balance(balance_ptr: u64);
26    pub fn account_locked_balance(balance_ptr: u64);
27    pub fn attached_deposit(balance_ptr: u64);
28    pub fn prepaid_gas() -> u64;
29    pub fn used_gas() -> u64;
30    // ############
31    // # Math API #
32    // ############
33    pub fn random_seed(register_id: u64);
34    pub fn sha256(value_len: u64, value_ptr: u64, register_id: u64);
35    pub fn keccak256(value_len: u64, value_ptr: u64, register_id: u64);
36    pub fn keccak512(value_len: u64, value_ptr: u64, register_id: u64);
37    pub fn ripemd160(value_len: u64, value_ptr: u64, register_id: u64);
38    pub fn ecrecover(
39        hash_len: u64,
40        hash_ptr: u64,
41        sig_len: u64,
42        sig_ptr: u64,
43        v: u64,
44        malleability_flag: u64,
45        register_id: u64,
46    ) -> u64;
47    pub fn ed25519_verify(
48        sig_len: u64,
49        sig_ptr: u64,
50        msg_len: u64,
51        msg_ptr: u64,
52        pub_key_len: u64,
53        pub_key_ptr: u64,
54    ) -> u64;
55    // #####################
56    // # Miscellaneous API #
57    // #####################
58    pub fn value_return(value_len: u64, value_ptr: u64);
59    pub fn panic() -> !;
60    pub fn panic_utf8(len: u64, ptr: u64) -> !;
61    pub fn log_utf8(len: u64, ptr: u64);
62    pub fn log_utf16(len: u64, ptr: u64);
63    pub fn abort(msg_ptr: u32, filename_ptr: u32, line: u32, col: u32) -> !;
64    // ################
65    // # Promises API #
66    // ################
67    pub fn promise_create(
68        account_id_len: u64,
69        account_id_ptr: u64,
70        function_name_len: u64,
71        function_name_ptr: u64,
72        arguments_len: u64,
73        arguments_ptr: u64,
74        amount_ptr: u64,
75        gas: u64,
76    ) -> u64;
77    pub fn promise_then(
78        promise_index: u64,
79        account_id_len: u64,
80        account_id_ptr: u64,
81        function_name_len: u64,
82        function_name_ptr: u64,
83        arguments_len: u64,
84        arguments_ptr: u64,
85        amount_ptr: u64,
86        gas: u64,
87    ) -> u64;
88    pub fn promise_and(promise_idx_ptr: u64, promise_idx_count: u64) -> u64;
89    pub fn promise_batch_create(account_id_len: u64, account_id_ptr: u64) -> u64;
90    pub fn promise_batch_then(promise_index: u64, account_id_len: u64, account_id_ptr: u64) -> u64;
91    // #######################
92    // # Promise API actions #
93    // #######################
94    pub fn promise_batch_action_create_account(promise_index: u64);
95    pub fn promise_batch_action_deploy_contract(promise_index: u64, code_len: u64, code_ptr: u64);
96    pub fn promise_batch_action_function_call(
97        promise_index: u64,
98        function_name_len: u64,
99        function_name_ptr: u64,
100        arguments_len: u64,
101        arguments_ptr: u64,
102        amount_ptr: u64,
103        gas: u64,
104    );
105    pub fn promise_batch_action_function_call_weight(
106        promise_index: u64,
107        function_name_len: u64,
108        function_name_ptr: u64,
109        arguments_len: u64,
110        arguments_ptr: u64,
111        amount_ptr: u64,
112        gas: u64,
113        weight: u64,
114    );
115    pub fn promise_batch_action_transfer(promise_index: u64, amount_ptr: u64);
116    pub fn promise_batch_action_stake(
117        promise_index: u64,
118        amount_ptr: u64,
119        public_key_len: u64,
120        public_key_ptr: u64,
121    );
122    pub fn promise_batch_action_add_key_with_full_access(
123        promise_index: u64,
124        public_key_len: u64,
125        public_key_ptr: u64,
126        nonce: u64,
127    );
128    pub fn promise_batch_action_add_key_with_function_call(
129        promise_index: u64,
130        public_key_len: u64,
131        public_key_ptr: u64,
132        nonce: u64,
133        allowance_ptr: u64,
134        receiver_id_len: u64,
135        receiver_id_ptr: u64,
136        function_names_len: u64,
137        function_names_ptr: u64,
138    );
139    pub fn promise_batch_action_delete_key(
140        promise_index: u64,
141        public_key_len: u64,
142        public_key_ptr: u64,
143    );
144    pub fn promise_batch_action_delete_account(
145        promise_index: u64,
146        beneficiary_id_len: u64,
147        beneficiary_id_ptr: u64,
148    );
149    pub fn promise_yield_create(
150        function_name_len: u64,
151        function_name_ptr: u64,
152        arguments_len: u64,
153        arguments_ptr: u64,
154        gas: u64,
155        gas_weight: u64,
156        register_id: u64,
157    ) -> u64;
158    pub fn promise_yield_resume(
159        data_id_len: u64,
160        data_id_ptr: u64,
161        payload_len: u64,
162        payload_ptr: u64,
163    ) -> u32;
164    // #######################
165    // # Promise API results #
166    // #######################
167    pub fn promise_results_count() -> u64;
168    pub fn promise_result(result_idx: u64, register_id: u64) -> u64;
169    pub fn promise_return(promise_id: u64);
170    // ###############
171    // # Storage API #
172    // ###############
173    pub fn storage_write(
174        key_len: u64,
175        key_ptr: u64,
176        value_len: u64,
177        value_ptr: u64,
178        register_id: u64,
179    ) -> u64;
180    pub fn storage_read(key_len: u64, key_ptr: u64, register_id: u64) -> u64;
181    pub fn storage_remove(key_len: u64, key_ptr: u64, register_id: u64) -> u64;
182    pub fn storage_has_key(key_len: u64, key_ptr: u64) -> u64;
183    pub fn storage_iter_prefix(prefix_len: u64, prefix_ptr: u64) -> u64;
184    pub fn storage_iter_range(start_len: u64, start_ptr: u64, end_len: u64, end_ptr: u64) -> u64;
185    pub fn storage_iter_next(iterator_id: u64, key_register_id: u64, value_register_id: u64)
186        -> u64;
187    // ###############
188    // # Validator API #
189    // ###############
190    pub fn validator_stake(account_id_len: u64, account_id_ptr: u64, stake_ptr: u64);
191    pub fn validator_total_stake(stake_ptr: u64);
192    // #############
193    // # Alt BN128 #
194    // #############
195    pub fn alt_bn128_g1_multiexp(value_len: u64, value_ptr: u64, register_id: u64);
196    pub fn alt_bn128_g1_sum(value_len: u64, value_ptr: u64, register_id: u64);
197    pub fn alt_bn128_pairing_check(value_len: u64, value_ptr: u64) -> u64;
198}
199
200/// Alias for [`block_index`] function. Returns the height of the current block.
201///
202/// # Safety
203///
204/// This function relies on the external implementation of [`block_index`].
205#[inline]
206pub unsafe fn block_height() -> u64 {
207    block_index()
208}