Derive Macro stellar_axelar_std_derive::IntoEvent
source · #[derive(IntoEvent)]
{
// Attributes available to this derive:
#[event_name]
#[datum]
#[data]
}
Expand description
Implements the Event trait for a Stellar contract event.
Fields without a #[data]
attribute are used as topics, while fields with #[data]
are used as event data.
The event name can be specified with #[event_name(...)]
or will default to the struct name in snake_case (minus “Event” suffix).
§Example
ⓘ
use core::fmt::Debug;
use stellar_axelar_std::events::Event;
use stellar_axelar_std::IntoEvent;
use stellar_axelar_std::{Address, contract, contractimpl, Env, String};
#[derive(Debug, PartialEq, IntoEvent)]
#[event_name("transfer")]
pub struct TransferEvent {
pub from: Address,
pub to: Address,
#[data]
pub amount: String,
}
#[contract]
pub struct Token;
#[contractimpl]
impl Token {
pub fn transfer(env: &Env, to: Address, amount: String) {
// ... transfer logic ...
// Generates event with:
// - Topics: ["transfer", contract_address, to]
// - Data: [amount]
TransferEvent {
from: env.current_contract_address(),
to,
amount,
}.emit(env);
}
}
}