use cometbft::{abci, block, consensus, serializers, validator, AppHash};
use serde::{Deserialize, Serialize};
use crate::dialect::{self, Dialect};
use crate::prelude::*;
use crate::request::RequestMessage;
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Request {
pub height: Option<block::Height>,
}
impl Request {
pub fn new(height: block::Height) -> Self {
Self {
height: Some(height),
}
}
}
impl RequestMessage for Request {
fn method(&self) -> crate::Method {
crate::Method::BlockResults
}
}
impl crate::Request<dialect::v0_34::Dialect> for Request {
type Response = self::v0_34::DialectResponse;
}
impl crate::Request<dialect::v1::Dialect> for Request {
type Response = Response;
}
impl<S: Dialect> crate::SimpleRequest<S> for Request
where
Self: crate::Request<S>,
Response: From<Self::Response>,
{
type Output = Response;
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Response {
pub height: block::Height,
pub txs_results: Option<Vec<abci::types::ExecTxResult>>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(deserialize_with = "serializers::nullable::deserialize")]
pub finalize_block_events: Vec<abci::Event>,
pub begin_block_events: Option<Vec<abci::Event>>,
pub end_block_events: Option<Vec<abci::Event>>,
#[serde(deserialize_with = "serializers::nullable::deserialize")]
pub validator_updates: Vec<validator::Update>,
pub consensus_param_updates: Option<consensus::Params>,
#[serde(default)]
#[serde(with = "serializers::apphash")]
pub app_hash: AppHash,
}
impl crate::Response for Response {}
pub mod v0_34 {
use super::Response;
use crate::dialect::v0_34::Event;
use crate::prelude::*;
use crate::{dialect, serializers};
use cometbft::{block, consensus, validator};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct DialectResponse {
pub height: block::Height,
pub txs_results: Option<Vec<dialect::DeliverTx<Event>>>,
pub begin_block_events: Option<Vec<Event>>,
pub end_block_events: Option<Vec<Event>>,
#[serde(deserialize_with = "serializers::nullable::deserialize")]
pub validator_updates: Vec<validator::Update>,
pub consensus_param_updates: Option<consensus::Params>,
}
impl crate::Response for DialectResponse {}
impl From<DialectResponse> for Response {
fn from(msg: DialectResponse) -> Self {
Response {
height: msg.height,
txs_results: msg
.txs_results
.map(|v| v.into_iter().map(Into::into).collect()),
finalize_block_events: vec![],
begin_block_events: msg
.begin_block_events
.map(|v| v.into_iter().map(Into::into).collect()),
end_block_events: msg
.end_block_events
.map(|v| v.into_iter().map(Into::into).collect()),
validator_updates: msg.validator_updates,
consensus_param_updates: msg.consensus_param_updates,
app_hash: Default::default(),
}
}
}
}