use crate::{address::Address, token::Denomination};
#[non_exhaustive]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum QueryRequest {
#[cbor(rename = "block_info")]
BlockInfo,
#[cbor(rename = "accounts")]
Accounts(AccountsQuery),
}
#[non_exhaustive]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum QueryResponse {
#[cbor(rename = "error")]
Error {
module: String,
code: u32,
message: String,
},
#[cbor(rename = "block_info")]
BlockInfo {
round: u64,
epoch: u64,
timestamp: u64,
},
#[cbor(rename = "accounts")]
Accounts(AccountsResponse),
}
#[non_exhaustive]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum AccountsQuery {
#[cbor(rename = "balance")]
Balance {
address: Address,
denomination: Denomination,
},
}
impl From<AccountsQuery> for QueryRequest {
fn from(q: AccountsQuery) -> Self {
Self::Accounts(q)
}
}
#[non_exhaustive]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum AccountsResponse {
Balance { balance: u128 },
}
impl From<AccountsResponse> for QueryResponse {
fn from(q: AccountsResponse) -> Self {
Self::Accounts(q)
}
}