use core::fmt::{self, Display};
use serde::{Deserialize, Serialize};
use crate::{chain, channel::Channels, node, prelude::*, serializers, Moniker, Version};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Info {
pub protocol_version: ProtocolVersionInfo,
pub id: node::Id,
pub listen_addr: ListenAddress,
pub network: chain::Id,
pub version: Version,
pub channels: Channels,
pub moniker: Moniker,
pub other: OtherInfo,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProtocolVersionInfo {
#[serde(with = "serializers::from_str")]
pub p2p: u64,
#[serde(with = "serializers::from_str")]
pub block: u64,
#[serde(with = "serializers::from_str")]
pub app: u64,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ListenAddress(String);
impl ListenAddress {
pub fn new(s: String) -> ListenAddress {
ListenAddress(s)
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl Display for ListenAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct OtherInfo {
pub tx_index: TxIndexStatus,
pub rpc_address: String,
}
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Default)]
pub enum TxIndexStatus {
#[serde(rename = "on")]
#[default]
On,
#[serde(rename = "off")]
Off,
}
impl From<TxIndexStatus> for bool {
fn from(status: TxIndexStatus) -> bool {
match status {
TxIndexStatus::On => true,
TxIndexStatus::Off => false,
}
}
}