Skip to content

Commit

Permalink
contracts: add function that emits event with input
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leegwater Simões committed Jul 1, 2024
1 parent 2d32532 commit cb080a1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/eventer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#![no_std]

extern crate alloc;
use alloc::vec::Vec;

use piecrust_uplink as uplink;

/// Struct that describes the state of the eventer contract
Expand All @@ -23,10 +26,23 @@ impl Eventer {
uplink::emit("number", i);
}
}

pub fn emit_input(&mut self, input: Vec<u8>) -> (u64, u64) {
let spent_before = uplink::spent();
uplink::emit("input", input);
let spent_after = uplink::spent();
(spent_before, spent_after)
}
}

/// Expose `Eventer::emit_num()` to the host
#[no_mangle]
unsafe fn emit_events(arg_len: u32) -> u32 {
uplink::wrap_call(arg_len, |num| STATE.emit_num(num))
}

/// Expose `Eventer::emit_input()` to the host
#[no_mangle]
unsafe fn emit_input(arg_len: u32) -> u32 {
uplink::wrap_call(arg_len, |input| STATE.emit_input(input))
}

0 comments on commit cb080a1

Please sign in to comment.