-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathlib.rs
More file actions
373 lines (317 loc) · 10.8 KB
/
Copy pathlib.rs
File metadata and controls
373 lines (317 loc) · 10.8 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
mod core;
mod debug;
mod evm;
mod ocean;
mod prelude;
mod util;
use ain_evm::blocktemplate::BlockTemplate;
use crate::{core::*, debug::*, evm::*, ocean::*, util::*};
pub struct BlockTemplateWrapper(Option<BlockTemplate>);
impl BlockTemplateWrapper {
const ERROR: &'static str = "Inner block template is None";
fn get_inner(&self) -> Result<&BlockTemplate, &'static str> {
self.0.as_ref().ok_or(Self::ERROR)
}
fn get_inner_mut(&mut self) -> Result<&mut BlockTemplate, &'static str> {
self.0.as_mut().ok_or(Self::ERROR)
}
}
#[cxx::bridge]
pub mod ffi {
// ========= FFI ==========
pub struct CrossBoundaryResult {
pub ok: bool,
pub reason: String,
}
// ========= Util ==========
extern "Rust" {
fn rs_try_from_utf8(result: &mut CrossBoundaryResult, string: &'static [u8]) -> String;
}
// ========= Core ==========
extern "Rust" {
fn ain_rs_preinit(result: &mut CrossBoundaryResult);
fn ain_rs_init_logging(result: &mut CrossBoundaryResult);
fn ain_rs_init_core_services(result: &mut CrossBoundaryResult);
fn ain_rs_wipe_evm_folder(result: &mut CrossBoundaryResult);
fn ain_rs_stop_core_services(result: &mut CrossBoundaryResult);
// Networking
fn ain_rs_init_network_json_rpc_service(result: &mut CrossBoundaryResult, addr: &str);
fn ain_rs_init_network_grpc_service(result: &mut CrossBoundaryResult, addr: &str);
fn ain_rs_init_network_rest_ocean(result: &mut CrossBoundaryResult, addr: &str);
fn ain_rs_init_network_subscriptions_service(result: &mut CrossBoundaryResult, addr: &str);
fn ain_rs_stop_network_services(result: &mut CrossBoundaryResult);
}
#[derive(Default)]
pub struct BlockV2Info {
pub height: u32,
pub difficulty: u32,
pub version: i32,
pub median_time: i64,
pub minter_block_count: u64,
pub size: usize,
pub size_stripped: usize,
pub weight: i64,
pub stake_modifier: String,
pub minter: String,
pub masternode: String,
}
// ========== Block ==========
#[derive(Default)]
pub struct EVMBlockHeader {
pub parent_hash: String,
pub beneficiary: String,
pub state_root: String,
pub receipts_root: String,
pub number: u64,
pub gas_limit: u64,
pub gas_used: u64,
pub timestamp: u64,
pub extra_data: Vec<u8>,
pub mix_hash: String,
pub nonce: u64,
pub base_fee: u64,
}
// ========== Transaction ==========
#[derive(Default)]
pub struct EVMTransaction {
// EIP-2718 transaction type: legacy - 0x0, EIP2930 - 0x1, EIP1559 - 0x2
pub tx_type: u8,
pub hash: String,
pub sender: String,
pub nonce: u64,
pub gas_price: u64,
pub gas_limit: u64,
pub max_fee_per_gas: u64,
pub max_priority_fee_per_gas: u64,
pub create_tx: bool,
pub to: String,
pub value: u64,
pub data: Vec<u8>,
}
#[derive(Default)]
pub struct TxMinerInfo {
pub address: String,
pub nonce: u64,
pub tip_fee: u64,
pub min_rbf_tip_fee: u64,
}
// ========== Governance Variable ==========
#[derive(Default)]
pub struct GovVarKeyDataStructure {
pub category: u8,
pub category_id: u32,
pub key: u32,
pub key_id: u32,
}
// ========== EVM ==========
pub struct CreateTransactionContext<'a> {
pub chain_id: u64,
pub nonce: u64,
pub gas_price: u64,
pub gas_limit: u64,
pub to: &'a str,
pub value: u64,
pub input: Vec<u8>,
pub priv_key: [u8; 32],
}
pub struct CreateTransferDomainContext {
pub from: String,
pub to: String,
pub native_address: String,
pub direction: bool,
pub value: u64,
pub token_id: u32,
pub chain_id: u64,
pub priv_key: [u8; 32],
pub use_nonce: bool,
pub nonce: u64,
}
pub struct TransferDomainInfo {
pub from: String,
pub to: String,
pub native_address: String,
pub direction: bool,
pub value: u64,
pub token_id: u32,
}
pub struct DST20TokenInfo {
pub id: u64,
pub name: String,
pub symbol: String,
}
#[derive(Default)]
pub struct CreateTxResult {
pub tx: Vec<u8>,
pub nonce: u64,
}
#[derive(Default)]
pub struct FinalizeBlockCompletion {
pub block_hash: String,
pub total_burnt_fees: u64,
pub total_priority_fees: u64,
pub block_number: u64,
}
#[derive(Default)]
pub struct ValidateTxCompletion {
pub tx_hash: String,
}
extern "Rust" {
type BlockTemplateWrapper;
// In-fallible functions
//
// If they are fallible, it's a TODO to changed and move later
// so errors are propogated up properly.
fn evm_try_get_balance(result: &mut CrossBoundaryResult, address: &str) -> u64;
fn evm_try_unsafe_create_template(
result: &mut CrossBoundaryResult,
dvm_block: u64,
miner_address: &str,
difficulty: u32,
timestamp: u64,
mnview_ptr: usize,
) -> &'static mut BlockTemplateWrapper;
fn evm_try_unsafe_remove_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
);
fn evm_try_disconnect_latest_block(result: &mut CrossBoundaryResult);
// Failible functions
// Has to take CrossBoundaryResult as first param
// Has to start with try_ / evm_try
fn evm_try_unsafe_update_state_in_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
);
fn evm_try_unsafe_get_next_valid_nonce_in_template(
result: &mut CrossBoundaryResult,
block_template: &BlockTemplateWrapper,
address: &str,
) -> u64;
fn evm_try_unsafe_remove_txs_above_hash_in_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
target_hash: String,
) -> Vec<String>;
fn evm_try_unsafe_add_balance_in_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
raw_tx: &str,
native_hash: &str,
);
fn evm_try_unsafe_sub_balance_in_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
raw_tx: &str,
native_hash: &str,
) -> bool;
fn evm_try_unsafe_validate_raw_tx_in_template(
result: &mut CrossBoundaryResult,
block_template: &BlockTemplateWrapper,
raw_tx: &str,
);
fn evm_try_unsafe_validate_transferdomain_tx_in_template(
result: &mut CrossBoundaryResult,
block_template: &BlockTemplateWrapper,
raw_tx: &str,
context: TransferDomainInfo,
);
fn evm_try_unsafe_push_tx_in_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
raw_tx: &str,
native_hash: &str,
) -> ValidateTxCompletion;
fn evm_try_unsafe_construct_block_in_template(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
is_miner: bool,
) -> FinalizeBlockCompletion;
fn evm_try_unsafe_commit_block(
result: &mut CrossBoundaryResult,
block_template: &BlockTemplateWrapper,
);
fn evm_try_unsafe_handle_attribute_apply(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
attribute_type: GovVarKeyDataStructure,
value: Vec<u8>,
) -> bool;
fn evm_try_create_and_sign_tx(
result: &mut CrossBoundaryResult,
ctx: CreateTransactionContext,
) -> CreateTxResult;
fn evm_try_create_and_sign_transfer_domain_tx(
result: &mut CrossBoundaryResult,
ctx: CreateTransferDomainContext,
) -> CreateTxResult;
fn evm_try_store_account_nonce(
result: &mut CrossBoundaryResult,
from_address: &str,
nonce: u64,
);
fn evm_try_get_block_hash_by_number(
result: &mut CrossBoundaryResult,
height: u64,
) -> String;
fn evm_try_get_block_number_by_hash(result: &mut CrossBoundaryResult, hash: &str) -> u64;
fn evm_try_get_block_header_by_hash(
result: &mut CrossBoundaryResult,
hash: &str,
) -> EVMBlockHeader;
fn evm_try_get_tx_by_hash(
result: &mut CrossBoundaryResult,
tx_hash: &str,
) -> EVMTransaction;
fn evm_try_get_tx_hash(result: &mut CrossBoundaryResult, raw_tx: &str) -> String;
fn evm_try_unsafe_make_signed_tx(result: &mut CrossBoundaryResult, raw_tx: &str) -> usize;
fn evm_try_unsafe_cache_signed_tx(
result: &mut CrossBoundaryResult,
raw_tx: &str,
instance: usize,
);
fn evm_try_unsafe_create_dst20(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
native_hash: &str,
token: DST20TokenInfo,
);
fn evm_try_unsafe_bridge_dst20(
result: &mut CrossBoundaryResult,
block_template: &mut BlockTemplateWrapper,
raw_tx: &str,
native_hash: &str,
token_id: u64,
out: bool,
);
fn evm_try_unsafe_is_smart_contract_in_template(
result: &mut CrossBoundaryResult,
address: &str,
block_template: &BlockTemplateWrapper,
) -> bool;
fn evm_try_get_tx_miner_info_from_raw_tx(
result: &mut CrossBoundaryResult,
raw_tx: &str,
mnview_ptr: usize,
) -> TxMinerInfo;
fn evm_try_dispatch_pending_transactions_event(
result: &mut CrossBoundaryResult,
raw_tx: &str,
);
fn ocean_index_block(result: &mut CrossBoundaryResult, block: String, info: &BlockV2Info);
fn ocean_invalidate_block(
result: &mut CrossBoundaryResult,
block: String,
info: &BlockV2Info,
);
}
// ========= Debug ==========
extern "Rust" {
fn debug_dump_db(
result: &mut CrossBoundaryResult,
arg: String,
start: String,
limit: String,
) -> String;
fn debug_log_account_states(result: &mut CrossBoundaryResult) -> String;
}
}