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

1fn emit_abi_encode(
2    bytecode: &mut Vec<u8>,
3    arg_count: usize,
4    use_callt: bool,
5    token_patches: &mut Vec<MethodTokenPatch>,
6) {
7    let total_bigint = BigInt::from(arg_count);
8    push_integer_bigint(bytecode, &total_bigint);
9    bytecode.push(0xC0); // PACK
10    // PACK pops values from the stack and therefore reverses their order.
11    // For `abi.encode(a, b, c)` we must preserve the original argument order.
12    if arg_count > 1 {
13        bytecode.push(0x4A); // DUP (keep a reference to the array on the stack)
14        bytecode.push(0xD1); // REVERSEITEMS (consumes one reference, reverses in-place)
15    }
16    emit_native_contract_call(
17        bytecode,
18        ir::NativeContract::StdLib,
19        "serialize",
20        1,
21        use_callt,
22        token_patches,
23    );
24}
25
26fn emit_abi_decode(
27    bytecode: &mut Vec<u8>,
28    use_callt: bool,
29    token_patches: &mut Vec<MethodTokenPatch>,
30) {
31    emit_native_contract_call(
32        bytecode,
33        ir::NativeContract::StdLib,
34        "deserialize",
35        1,
36        use_callt,
37        token_patches,
38    );
39}
40
41fn emit_notify_serialized(
42    bytecode: &mut Vec<u8>,
43    use_callt: bool,
44    token_patches: &mut Vec<MethodTokenPatch>,
45) {
46    // Syscalls.notify expects a serialized payload: [eventName, stateArray]
47    emit_native_contract_call(
48        bytecode,
49        ir::NativeContract::StdLib,
50        "deserialize",
51        1,
52        use_callt,
53        token_patches,
54    );
55    // Extract eventName/state via PICKITEM and call Runtime.Notify.
56    bytecode.push(0x4A); // DUP (payload)
57    bytecode.push(0x10); // PUSH0
58    bytecode.push(0xCE); // PICKITEM -> eventName
59    bytecode.push(0x50); // SWAP -> [eventName, payload]
60    bytecode.push(0x4A); // DUP (payload)
61    bytecode.push(0x11); // PUSH1
62    bytecode.push(0xCE); // PICKITEM -> state
63    bytecode.push(0x46); // NIP (drop payload) -> [eventName, state]
64    bytecode.push(0x50); // SWAP -> [state, eventName]
65    emit_syscall(bytecode, "System.Runtime.Notify");
66    bytecode.push(0x11); // PUSH1
67}