Skip to main content

blokli_client/api/v1/graphql/
mod.rs

1//! Schema-facing GraphQL fragments and scalar wrappers.
2//!
3//! The public client traits return selected structs and enums from these modules through
4//! [`crate::api::types`]. Operation builders and GraphQL variables are implementation details used by
5//! [`crate::BlokliClient`].
6
7use crate::errors::ErrorKind;
8
9pub mod accounts;
10pub mod balances;
11pub mod channels;
12#[cfg(feature = "curvy")]
13pub mod curvy;
14pub mod graph;
15pub mod info;
16pub mod safe;
17pub mod services;
18pub mod tickets;
19pub mod txs;
20
21#[cynic::schema("blokli")]
22pub(crate) mod schema {}
23
24// https://generator.cynic-rs.dev/
25
26/// Token kind accepted by balance queries.
27///
28/// Maps the Blokli GraphQL `Token` enum onto Rust variants. Note that the
29/// GraphQL `HOPR` symbol refers to the wrapped HOPR token (wxHOPR).
30#[derive(cynic::Enum, Clone, Copy, Debug, PartialEq, Eq)]
31#[allow(clippy::upper_case_acronyms)]
32pub enum Token {
33    /// Wrapped HOPR token (wxHOPR); the GraphQL `HOPR` symbol.
34    #[cynic(rename = "HOPR")]
35    WxHOPR,
36    /// Native HOPR token (xHOPR).
37    #[cynic(rename = "XHOPR")]
38    XHOPR,
39    /// Native chain token (xDai).
40    #[cynic(rename = "NATIVE")]
41    Native,
42}
43
44/// Channel lifecycle state reported by Blokli.
45#[derive(cynic::Enum, Clone, Copy, Debug, PartialEq, Eq)]
46pub enum ChannelStatus {
47    /// Channel is open and can carry traffic.
48    #[cynic(rename = "OPEN")]
49    Open,
50    /// Channel close has been initiated but the closure grace period has not elapsed.
51    #[cynic(rename = "PENDINGTOCLOSE")]
52    PendingToClose,
53    /// Channel is closed.
54    #[cynic(rename = "CLOSED")]
55    Closed,
56}
57
58/// Readiness state for a Blokli instance.
59#[derive(cynic::Enum, Clone, Copy, Debug, PartialEq, Eq)]
60pub enum ReadinessState {
61    /// Blokli reports that it is ready to serve requests.
62    #[cynic(rename = "READY")]
63    Ready,
64    /// Blokli reports that it is not ready.
65    #[cynic(rename = "NOT_READY")]
66    NotReady,
67}
68
69/// Date-time value as returned by the GraphQL API.
70#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq)]
71pub struct DateTime(pub String);
72
73/// Decimal token amount encoded as a string by the GraphQL API.
74#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq)]
75pub struct TokenValueString(pub String);
76
77/// Unsigned 64-bit integer encoded as a string by the GraphQL API.
78#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq)]
79#[cynic(graphql_type = "UInt64")]
80pub struct Uint64(pub String);
81
82/// Unsigned 256-bit integer encoded as a decimal string by the GraphQL API.
83#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq)]
84#[cynic(graphql_type = "UInt256")]
85pub struct Uint256(pub String);
86
87/// 32-byte hex value as returned by the GraphQL API.
88#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq)]
89pub struct Hex32(pub String);
90
91#[derive(cynic::InlineFragments, Debug)]
92pub enum CountResult {
93    Count(Count),
94    MissingFilterError(MissingFilterError),
95    QueryFailedError(QueryFailedError),
96    #[cynic(fallback)]
97    Unknown,
98}
99
100impl From<CountResult> for Result<u32, crate::errors::BlokliClientError> {
101    fn from(value: CountResult) -> Self {
102        match value {
103            CountResult::Count(count) => Ok(count.count as u32),
104            CountResult::MissingFilterError(e) => Err(e.into()),
105            CountResult::QueryFailedError(e) => Err(e.into()),
106            CountResult::Unknown => Err(ErrorKind::NoData.into()),
107        }
108    }
109}
110
111/// Shared count payload used by several GraphQL count queries.
112#[derive(cynic::QueryFragment, Debug)]
113pub struct Count {
114    /// GraphQL concrete type name.
115    pub __typename: String,
116    /// Number of matching records.
117    pub count: i32,
118}
119
120/// Generic Blokli query failure returned by GraphQL union fields.
121#[derive(cynic::QueryFragment, Debug)]
122pub struct QueryFailedError {
123    /// GraphQL concrete type name.
124    pub __typename: String,
125    /// Human-readable error message from Blokli.
126    pub message: String,
127    /// Stable Blokli error code.
128    pub code: String,
129}
130
131impl From<QueryFailedError> for crate::errors::BlokliClientError {
132    fn from(value: QueryFailedError) -> Self {
133        ErrorKind::BlokliError {
134            kind: "query failed",
135            code: value.code,
136            message: value.message,
137        }
138        .into()
139    }
140}
141
142/// Error returned when a query requires at least one filter.
143#[derive(cynic::QueryFragment, Debug)]
144pub struct MissingFilterError {
145    /// GraphQL concrete type name.
146    pub __typename: String,
147    /// Stable Blokli error code.
148    pub code: String,
149    /// Human-readable error message from Blokli.
150    pub message: String,
151}
152
153impl From<MissingFilterError> for crate::errors::BlokliClientError {
154    fn from(value: MissingFilterError) -> Self {
155        ErrorKind::BlokliError {
156            kind: "missing filter",
157            code: value.code,
158            message: value.message,
159        }
160        .into()
161    }
162}
163
164/// Error returned when Blokli rejects an address argument.
165#[derive(cynic::QueryFragment, Debug)]
166pub struct InvalidAddressError {
167    /// GraphQL concrete type name.
168    pub __typename: String,
169    /// Stable Blokli error code.
170    pub code: String,
171    /// Human-readable error message from Blokli.
172    pub message: String,
173}
174
175impl From<InvalidAddressError> for crate::errors::BlokliClientError {
176    fn from(value: InvalidAddressError) -> Self {
177        ErrorKind::BlokliError {
178            kind: "invalid address",
179            code: value.code,
180            message: value.message,
181        }
182        .into()
183    }
184}