neo_solidity/cli/bytecode/bytecode_builtins/builtin_call/
contract_calls.rs

1fn emit_contract_call(
2    bytecode: &mut Vec<u8>,
3    use_callt: bool,
4    token_patches: &mut Vec<MethodTokenPatch>,
5) {
6    // Stack: [contract_hash, method, params(bytes)]
7    emit_native_contract_call(
8        bytecode,
9        ir::NativeContract::StdLib,
10        "deserialize",
11        1,
12        use_callt,
13        token_patches,
14    );
15    push_integer_bigint(bytecode, &BigInt::from(CALLFLAGS_ALL));
16    bytecode.push(0x50); // SWAP -> [contract, method, flags, args]
17    bytecode.push(0x54); // REVERSE4 -> [args, flags, method, contract]
18    emit_syscall(bytecode, "System.Contract.Call");
19    // Solidity expects `bytes` for low-level calls; serialize the return stack item.
20    emit_native_contract_call(
21        bytecode,
22        ir::NativeContract::StdLib,
23        "serialize",
24        1,
25        use_callt,
26        token_patches,
27    );
28}
29
30fn emit_contract_call_with_flags(
31    bytecode: &mut Vec<u8>,
32    use_callt: bool,
33    token_patches: &mut Vec<MethodTokenPatch>,
34) {
35    // Stack: [contract_hash, method, params(bytes), flags]
36    bytecode.push(0x50); // SWAP -> [contract, method, flags, params]
37    emit_native_contract_call(
38        bytecode,
39        ir::NativeContract::StdLib,
40        "deserialize",
41        1,
42        use_callt,
43        token_patches,
44    );
45    bytecode.push(0x54); // REVERSE4 -> [args, flags, method, contract]
46    emit_syscall(bytecode, "System.Contract.Call");
47    emit_native_contract_call(
48        bytecode,
49        ir::NativeContract::StdLib,
50        "serialize",
51        1,
52        use_callt,
53        token_patches,
54    );
55}