neo_solidity/cli/bytecode/bytecode_builtins/builtin_call/
native_wrappers.rs1fn emit_native_call(
2 bytecode: &mut Vec<u8>,
3 contract: ir::NativeContract,
4 method: &str,
5 arg_count: usize,
6 use_callt: bool,
7 token_patches: &mut Vec<MethodTokenPatch>,
8) {
9 emit_native_contract_call(
10 bytecode,
11 contract,
12 method,
13 arg_count,
14 use_callt,
15 token_patches,
16 );
17}
18
19fn emit_deploy_contract(
20 bytecode: &mut Vec<u8>,
21 arg_count: usize,
22 use_callt: bool,
23 token_patches: &mut Vec<MethodTokenPatch>,
24) {
25 emit_native_contract_call(
29 bytecode,
30 ir::NativeContract::ContractManagement,
31 "deploy",
32 arg_count,
33 use_callt,
34 token_patches,
35 );
36 bytecode.push(0x12); bytecode.push(0xCE); }
39
40fn emit_get_contract(
41 bytecode: &mut Vec<u8>,
42 use_callt: bool,
43 token_patches: &mut Vec<MethodTokenPatch>,
44) {
45 emit_native_contract_call(
51 bytecode,
52 ir::NativeContract::ContractManagement,
53 "getContract",
54 1,
55 use_callt,
56 token_patches,
57 );
58
59 bytecode.push(0x4A); bytecode.push(0x12); bytecode.push(0xCE); bytecode.push(0x4B); bytecode.push(0x13); bytecode.push(0xCE); bytecode.push(0x4B); bytecode.push(0x14); bytecode.push(0xCE); emit_native_contract_call(
74 bytecode,
75 ir::NativeContract::StdLib,
76 "serialize",
77 1,
78 use_callt,
79 token_patches,
80 ); bytecode.push(0x13); bytecode.push(0x4D); bytecode.push(0x11); bytecode.push(0xCE); bytecode.push(0x14); bytecode.push(0x52); bytecode.push(0x45); bytecode.push(0x14); bytecode.push(0xC0); bytecode.push(0x4A); bytecode.push(0xD1); }
100
101fn emit_get_contract_script(
102 bytecode: &mut Vec<u8>,
103 use_callt: bool,
104 token_patches: &mut Vec<MethodTokenPatch>,
105) {
106 emit_native_contract_call(
109 bytecode,
110 ir::NativeContract::ContractManagement,
111 "getContract",
112 1,
113 use_callt,
114 token_patches,
115 );
116 bytecode.push(0x13); bytecode.push(0xCE); }
119
120fn emit_get_neo_account_state(
121 bytecode: &mut Vec<u8>,
122 use_callt: bool,
123 token_patches: &mut Vec<MethodTokenPatch>,
124) {
125 emit_native_contract_call(
131 bytecode,
132 ir::NativeContract::Neo,
133 "getAccountState",
134 1,
135 use_callt,
136 token_patches,
137 );
138
139 bytecode.push(0x4A); bytecode.push(0xD8); let jmp_if_not_null_pos = bytecode.len();
143 bytecode.push(0x27); let jmp_if_not_null_operand = bytecode.len();
145 bytecode.extend_from_slice(&[0, 0, 0, 0]);
146
147 bytecode.push(0x45); bytecode.push(0x10); bytecode.push(0x10); push_data(bytecode, &[]); bytecode.push(0x10); bytecode.push(0x14); bytecode.push(0xC0); bytecode.push(0x4A); bytecode.push(0xD1); let jmp_end_pos = bytecode.len();
160 bytecode.push(0x23); let jmp_end_operand = bytecode.len();
162 bytecode.extend_from_slice(&[0, 0, 0, 0]);
163
164 let not_null_pos = bytecode.len();
166
167 bytecode.push(0x4A); bytecode.push(0x12); bytecode.push(0xCE); bytecode.push(0xD8); let jmp_vote_non_null_pos = bytecode.len();
173 bytecode.push(0x27); let jmp_vote_non_null_operand = bytecode.len();
175 bytecode.extend_from_slice(&[0, 0, 0, 0]);
176
177 bytecode.push(0x4A); bytecode.push(0x12); push_data(bytecode, &[]);
181 bytecode.push(0xD0); let vote_non_null_pos = bytecode.len();
184
185 let rel_vote_non_null = (vote_non_null_pos as i32)
186 .checked_sub(jmp_vote_non_null_pos as i32)
187 .unwrap_or(0);
188 bytecode[jmp_vote_non_null_operand..jmp_vote_non_null_operand + 4]
189 .copy_from_slice(&rel_vote_non_null.to_le_bytes());
190
191 let end_pos = bytecode.len();
192
193 let rel_not_null = (not_null_pos as i32)
194 .checked_sub(jmp_if_not_null_pos as i32)
195 .unwrap_or(0);
196 bytecode[jmp_if_not_null_operand..jmp_if_not_null_operand + 4]
197 .copy_from_slice(&rel_not_null.to_le_bytes());
198
199 let rel_end = (end_pos as i32)
200 .checked_sub(jmp_end_pos as i32)
201 .unwrap_or(0);
202 bytecode[jmp_end_operand..jmp_end_operand + 4].copy_from_slice(&rel_end.to_le_bytes());
203}