xand_api_client/
models.rs

1//! The types in here represent chain-agnostic versions of the data one might fetch or send with
2//! the xand-api client. They are not the actual wire types, but are more usable representations.
3//!
4//! These may seem to fill the same purpose as `xand_models`, but there is an important
5//! distinction. Some things, like petri, need to view a chain-agnostic model of the world, but
6//! cannot depend on the xand-api-client. Hence, the only things that should be put in here are
7//! things that consumers of the client need, but not anything the `xand-api` server itself needs.
8
9use serde::{Deserialize, Serialize};
10use xand_api_proto::proto_models::{TransactionId, TransactionStatus};
11
12#[derive(Debug, Default, Clone)]
13pub struct Paginated<T> {
14    pub data: T,
15    pub total: u32,
16}
17
18impl<T> From<Vec<T>> for Paginated<Vec<T>> {
19    fn from(v: Vec<T>) -> Self {
20        #[allow(clippy::cast_possible_truncation)]
21        let total = v.len() as u32;
22
23        Self { total, data: v }
24    }
25}
26
27#[derive(Clone, Debug, Eq, PartialEq)]
28pub struct Paging {
29    /// Number of entries per page.
30    pub page_size: u32,
31    /// Page number starting from zero.
32    pub page_number: u32,
33}
34
35impl Paging {
36    /// Returns paging details suitable to get all items on a single page.
37    #[must_use]
38    pub fn all() -> Paging {
39        Paging {
40            page_size: u32::max_value(),
41            page_number: 0,
42        }
43    }
44}
45
46impl Default for Paging {
47    fn default() -> Paging {
48        Paging {
49            page_size: xand_api_proto::proto_models::DEFAULT_PAGE_SIZE,
50            page_number: 0,
51        }
52    }
53}
54
55#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
56pub struct TransactionUpdate {
57    pub id: TransactionId,
58    pub status: TransactionStatus,
59}