use super::super::bigint::BigInt;
use super::super::encoding::Base64;
use super::super::{BalanceChange, CheckpointSequenceNumber, IotaTransactionBlockEffects, TransactionDigest};
use super::ExecuteTransactionRequestType;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
#[serde_as]
#[derive(Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase", rename = "TransactionBlockResponse")]
pub struct IotaTransactionBlockResponse {
pub digest: TransactionDigest,
#[serde_as(as = "Base64")]
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub raw_transaction: Vec<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub effects: Option<IotaTransactionBlockEffects>,
#[serde(skip_serializing_if = "Option::is_none")]
pub balance_changes: Option<Vec<BalanceChange>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<BigInt<u64>>")]
pub timestamp_ms: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub confirmed_local_execution: Option<bool>,
#[serde_as(as = "Option<BigInt<u64>>")]
#[serde(skip_serializing_if = "Option::is_none")]
pub checkpoint: Option<CheckpointSequenceNumber>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub errors: Vec<String>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub raw_effects: Vec<u8>,
}
#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Default)]
#[serde(rename_all = "camelCase", rename = "TransactionBlockResponseOptions", default)]
pub struct IotaTransactionBlockResponseOptions {
pub show_input: bool,
pub show_raw_input: bool,
pub show_effects: bool,
pub show_events: bool,
pub show_object_changes: bool,
pub show_balance_changes: bool,
pub show_raw_effects: bool,
}
impl IotaTransactionBlockResponseOptions {
pub fn new() -> Self {
Self::default()
}
pub fn full_content() -> Self {
Self {
show_effects: true,
show_input: true,
show_raw_input: true,
show_events: true,
show_object_changes: true,
show_balance_changes: true,
show_raw_effects: false,
}
}
pub fn with_input(mut self) -> Self {
self.show_input = true;
self
}
pub fn with_raw_input(mut self) -> Self {
self.show_raw_input = true;
self
}
pub fn with_effects(mut self) -> Self {
self.show_effects = true;
self
}
pub fn with_events(mut self) -> Self {
self.show_events = true;
self
}
pub fn with_balance_changes(mut self) -> Self {
self.show_balance_changes = true;
self
}
pub fn with_object_changes(mut self) -> Self {
self.show_object_changes = true;
self
}
pub fn with_raw_effects(mut self) -> Self {
self.show_raw_effects = true;
self
}
pub fn default_execution_request_type(&self) -> ExecuteTransactionRequestType {
if self.require_effects() {
ExecuteTransactionRequestType::WaitForLocalExecution
} else {
ExecuteTransactionRequestType::WaitForEffectsCert
}
}
pub fn require_input(&self) -> bool {
self.show_input || self.show_raw_input || self.show_object_changes
}
pub fn require_effects(&self) -> bool {
self.show_effects
|| self.show_events
|| self.show_balance_changes
|| self.show_object_changes
|| self.show_raw_effects
}
pub fn only_digest(&self) -> bool {
self == &Self::default()
}
}
#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DryRunTransactionBlockResponse {
pub effects: IotaTransactionBlockEffects,
}