use alloc::collections::BTreeMap as HashMap;
use serde::{Deserialize, Serialize};
use tendermint::{abci, Block};
use crate::{prelude::*, query::EventType, response::Wrapper, serializers, Response};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Event {
pub query: String,
pub data: EventData,
pub events: Option<HashMap<String, Vec<String>>>,
}
impl Response for Event {}
pub type WrappedEvent = Wrapper<Event>;
impl Event {
pub fn event_type(&self) -> Option<EventType> {
match self.data {
EventData::NewBlock { .. } => Some(EventType::NewBlock),
EventData::Tx { .. } => Some(EventType::Tx),
_ => None,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(tag = "type", content = "value")]
#[allow(clippy::large_enum_variant)]
pub enum EventData {
#[serde(alias = "tendermint/event/NewBlock")]
NewBlock {
block: Option<Block>,
result_begin_block: Option<abci::response::BeginBlock>,
result_end_block: Option<abci::response::EndBlock>,
},
#[serde(alias = "tendermint/event/Tx")]
Tx {
#[serde(rename = "TxResult")]
tx_result: TxInfo,
},
GenericJsonEvent(serde_json::Value),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct TxInfo {
#[serde(with = "serializers::from_str")]
pub height: i64,
pub index: Option<i64>,
#[serde(with = "serializers::bytes::base64string")]
pub tx: Vec<u8>,
pub result: TxResult,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct TxResult {
pub log: Option<String>,
pub gas_wanted: Option<String>,
pub gas_used: Option<String>,
pub events: Vec<abci::Event>,
}