use crate::prelude::*;
use cosmwasm_std::{Addr, Event};
use cw_utils::Expiration;
#[derive(Debug)]
pub struct MintEvent {
pub token_id: String,
pub owner: Addr,
}
impl From<MintEvent> for Event {
fn from(src: MintEvent) -> Self {
Event::new("mint").add_attributes(vec![
("token_id", src.token_id.to_string()),
("owner", src.owner.to_string()),
])
}
}
impl TryFrom<Event> for MintEvent {
type Error = anyhow::Error;
fn try_from(evt: Event) -> anyhow::Result<Self> {
Ok(MintEvent {
token_id: evt.string_attr("token_id")?,
owner: evt.unchecked_addr_attr("owner")?,
})
}
}
#[derive(Debug)]
pub struct BurnEvent {
pub token_id: String,
}
impl From<BurnEvent> for Event {
fn from(src: BurnEvent) -> Self {
Event::new("burn").add_attributes(vec![("token_id", src.token_id)])
}
}
impl TryFrom<Event> for BurnEvent {
type Error = anyhow::Error;
fn try_from(evt: Event) -> anyhow::Result<Self> {
Ok(BurnEvent {
token_id: evt.string_attr("token_id")?,
})
}
}
#[derive(Debug)]
pub struct ApprovalEvent {
pub token_id: String,
pub spender: Addr,
pub expires: Expiration,
}
impl From<ApprovalEvent> for Event {
fn from(src: ApprovalEvent) -> Self {
Event::new("approval").add_attributes(vec![
("token_id", src.token_id.to_string()),
("spender", src.spender.to_string()),
("expires", src.expires.to_string()),
])
}
}
#[derive(Debug)]
pub struct RevokeEvent {
pub token_id: String,
pub spender: Addr,
}
impl From<RevokeEvent> for Event {
fn from(src: RevokeEvent) -> Self {
Event::new("revoke").add_attributes(vec![
("token_id", src.token_id.to_string()),
("spender", src.spender.to_string()),
])
}
}
#[derive(Debug)]
pub struct ApproveAllEvent {
pub operator: Addr,
pub expires: Expiration,
}
impl From<ApproveAllEvent> for Event {
fn from(src: ApproveAllEvent) -> Self {
Event::new("approve-all").add_attributes(vec![
("operator", src.operator.to_string()),
("expires", src.expires.to_string()),
])
}
}
#[derive(Debug)]
pub struct RevokeAllEvent {
pub operator: Addr,
}
impl From<RevokeAllEvent> for Event {
fn from(src: RevokeAllEvent) -> Self {
Event::new("revoke-all").add_attributes(vec![("operator", src.operator.to_string())])
}
}
#[derive(Debug)]
pub struct TransferEvent {
pub recipient: Addr,
pub token_id: String,
}
impl From<TransferEvent> for Event {
fn from(src: TransferEvent) -> Self {
Event::new("transfer").add_attributes(vec![
("recipient", src.recipient.to_string()),
("token_id", src.token_id),
])
}
}