Add a custom event to the intkey_multiply example
The commit demonstrates how a custom event can be added to the
smart contract. In this example, send the raw values which are
multiplied to get a new value. All the values are sent as an
event to the listener.
@@ -610,9 +610,17 @@ impl TransactionHandler for IntkeyMultiplyTransactionHandler {
new_value
)));
};
- state.set(&payload.get_name_a(), new_value as u32)
+ state.set(&payload.get_name_a(), new_value as u32)?;
+
+ // Send an event with the result and the current values of b & c
+ // Compute the event data to be sent in Bvalue,Cvalue,Avalue format
+ let values = format!("{},{},{}", orig_value_b, orig_value_c, new_value);
+ context
+ .add_event(String::from("computation"), Vec::new(), values.as_bytes())
+ .map_err(ApplyError::from)
}
}
+
#[cfg(target_arch = "wasm32")]
fn run_smart_permisson(signer: &str, payload: &[u8], agent: Agent) -> Result<i32, ApplyError> {
let org_id = agent.org_id();
