drt_chain_vm/vm_hooks/
vh_source.rs1use std::{fmt::Debug, sync::MutexGuard};
2
3use crate::{
4 tx_mock::{BackTransfers, TxFunctionName, TxInput, TxLog, TxManagedTypes, TxResult},
5 types::{VMAddress, VMCodeMetadata, H256},
6 world_mock::{AccountData, BlockInfo},
7};
8
9pub trait VMHooksHandlerSource: Debug {
11 fn m_types_lock(&self) -> MutexGuard<TxManagedTypes>;
12
13 fn halt_with_error(&self, status: u64, message: &str) -> !;
14
15 fn vm_error(&self, message: &str) -> ! {
16 self.halt_with_error(10, message)
17 }
18
19 fn input_ref(&self) -> &TxInput;
20
21 fn current_address(&self) -> &VMAddress {
22 &self.input_ref().to
23 }
24
25 fn tx_hash(&self) -> H256 {
26 self.input_ref().tx_hash.clone()
27 }
28
29 fn random_next_bytes(&self, length: usize) -> Vec<u8>;
31
32 fn result_lock(&self) -> MutexGuard<TxResult>;
33
34 fn push_tx_log(&self, tx_log: TxLog) {
35 self.result_lock().result_logs.push(tx_log);
36 }
37
38 fn storage_read(&self, key: &[u8]) -> Vec<u8> {
39 self.storage_read_any_address(self.current_address(), key)
40 }
41
42 fn storage_read_any_address(&self, address: &VMAddress, key: &[u8]) -> Vec<u8>;
43
44 fn storage_write(&self, key: &[u8], value: &[u8]);
45
46 fn get_previous_block_info(&self) -> &BlockInfo;
47
48 fn get_current_block_info(&self) -> &BlockInfo;
49
50 fn back_transfers_lock(&self) -> MutexGuard<BackTransfers>;
51
52 fn account_data(&self, address: &VMAddress) -> Option<AccountData>;
56
57 fn current_account_data(&self) -> AccountData {
61 self.account_data(&self.input_ref().to)
62 .expect("missing current account")
63 }
64
65 fn account_code(&self, address: &VMAddress) -> Vec<u8>;
66
67 fn perform_async_call(
68 &self,
69 to: VMAddress,
70 rewa_value: num_bigint::BigUint,
71 func_name: TxFunctionName,
72 args: Vec<Vec<u8>>,
73 ) -> !;
74
75 fn perform_execute_on_dest_context(
76 &self,
77 to: VMAddress,
78 rewa_value: num_bigint::BigUint,
79 func_name: TxFunctionName,
80 args: Vec<Vec<u8>>,
81 ) -> Vec<Vec<u8>>;
82
83 fn perform_deploy(
84 &self,
85 rewa_value: num_bigint::BigUint,
86 contract_code: Vec<u8>,
87 code_metadata: VMCodeMetadata,
88 args: Vec<Vec<u8>>,
89 ) -> (VMAddress, Vec<Vec<u8>>);
90
91 fn perform_transfer_execute(
92 &self,
93 to: VMAddress,
94 rewa_value: num_bigint::BigUint,
95 func_name: TxFunctionName,
96 arguments: Vec<Vec<u8>>,
97 );
98}