oasis_contract_sdk_types/
env.rs

1//! Environment query-related types.
2use crate::{address::Address, token::Denomination};
3
4/// A query request.
5#[non_exhaustive]
6#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
7pub enum QueryRequest {
8    /// Information about the current runtime block.
9    #[cbor(rename = "block_info")]
10    BlockInfo,
11
12    /// Accounts queries.
13    #[cbor(rename = "accounts")]
14    Accounts(AccountsQuery),
15}
16
17/// A query response.
18#[non_exhaustive]
19#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
20pub enum QueryResponse {
21    /// Indication of a failing request.
22    #[cbor(rename = "error")]
23    Error {
24        module: String,
25        code: u32,
26        message: String,
27    },
28
29    /// Information about the current runtime block.
30    #[cbor(rename = "block_info")]
31    BlockInfo {
32        round: u64,
33        epoch: u64,
34        timestamp: u64,
35    },
36
37    /// Accounts queries.
38    #[cbor(rename = "accounts")]
39    Accounts(AccountsResponse),
40}
41
42/// Accounts API queries.
43#[non_exhaustive]
44#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
45pub enum AccountsQuery {
46    /// Query an account's balance.
47    #[cbor(rename = "balance")]
48    Balance {
49        address: Address,
50        denomination: Denomination,
51    },
52}
53
54impl From<AccountsQuery> for QueryRequest {
55    fn from(q: AccountsQuery) -> Self {
56        Self::Accounts(q)
57    }
58}
59
60/// Accounts API responses.
61#[non_exhaustive]
62#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
63pub enum AccountsResponse {
64    /// An account's balance of the given denomination.
65    Balance { balance: u128 },
66}
67
68impl From<AccountsResponse> for QueryResponse {
69    fn from(q: AccountsResponse) -> Self {
70        Self::Accounts(q)
71    }
72}