Closed zemyblue closed 2 years ago
support to output multiple events from the result of one tx.
It has already been solved in the original cosmwasm. We will merge it before long. https://github.com/CosmWasm/cosmwasm/blob/a0cf296c43aa092b81457d96a9c6bc2ab223f6d3/packages/std/src/results/response.rs#L77-L83
I will make a derive macro to make it easy to make an event from a struct.
like: IntoEvent
#[derive(IntoEvent)]
struct Transfer {
from: Addr,
receiver: Addr,
amount: Coin,
}
let transfer_event = Transfer { from: addr_a, receiver: addr_b, amount: coin };
let expected_event = Event::new("Transfer").add_attribute("from", addr_a).add_attribute("receiver", addr_b).add_attribute("amount", coin);
assert_eq!(transfer_event.into(), expected_event)
Make a PR based on cosmwasm 0.16.2. It can be merged after this repository's version has updted. https://github.com/loloicci/line-cosmwasm/pull/1
Currently, the method to add an event in rustlang's smart contract is to add key and value as
add_attribute
to theresponse
of function. This is not suitable for outputting multiple events from one tx, and it is like adding a new event every time rather than adding an event with a defined characteristic, so it can be classified as different events even thought it is the same vent type during development.For example, in the event of Solidity
Transfer(sender, receiver, amount)
event, the event name is clearlyTransfer
, and it is defined as a format with three attributes, and becauseTransfer
event is always used in this format, it is easy to distinguish from the result. However, there is no way to control this with the current event usage method.So, it would be good if the way to define events and use them would be improved.
Improvement points