neo_solidity/cli/bytecode/bytecode_builtins/
events.rs

1fn emit_event(bytecode: &mut Vec<u8>, module: &ir::Module, index: usize, arg_count: usize) {
2    if module.events.get(index).is_some() {
3        emit_event_payload(bytecode, arg_count);
4    }
5}
6
7fn emit_event_by_name(bytecode: &mut Vec<u8>, _name: &str, arg_count: usize) {
8    emit_event_payload(bytecode, arg_count);
9}
10
11fn emit_event_payload(bytecode: &mut Vec<u8>, arg_count: usize) {
12    // Neo N3 Runtime.Notify signature is: Notify(eventName, stateArray)
13    // The lowering pushes eventName first, then the event arguments.
14    let total_bigint = BigInt::from(arg_count);
15    push_integer_bigint(bytecode, &total_bigint);
16    bytecode.push(0xC0); // PACK arguments into an array, leaving eventName below it
17    // PACK reverses argument order (it pops from the stack), but Neo ABI expects event
18    // arguments to match the declared order in the manifest. Reverse the packed array
19    // in-place to restore the original ordering.
20    if arg_count > 1 {
21        bytecode.push(0x4A); // DUP (keep a reference to the array on the stack)
22        bytecode.push(0xD1); // REVERSEITEMS (consumes one reference, reverses in-place)
23    }
24    bytecode.push(0x50); // SWAP -> [stateArray, eventName]
25    emit_syscall(bytecode, "System.Runtime.Notify");
26}