Skip to main content

talea_core/api/
requests.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::types::{Direction, ExternalRef, Seq};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
8pub struct WireAmount {
9    pub minor: i64,
10    pub asset: String,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
15pub struct AssetDraft {
16    pub id: String,
17    /// One of: `fiat`, `crypto`. Crypto requires `network`; `native_id`
18    /// distinguishes tokens from the chain's base coin.
19    pub class: String,
20    pub network: Option<String>, // required for crypto, e.g. "bitcoin", "ethereum".
21    pub native_id: Option<String>, // contract / asset id; null for a chain base coin.
22    pub precision: u8,
23    pub name: String,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
28pub struct AccountDraft {
29    pub book: String,
30    pub path: String,
31    pub asset: String,
32    /// One of: `asset`, `liability`, `income`, `expense`, `equity`, `clearing`.
33    pub kind: String,
34    pub normal_side: Option<Direction>, // null = clearing
35    pub min_balance: Option<i64>,       // null = unconstrained
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
40pub struct PostingDraft {
41    pub account: String,
42    pub amount: WireAmount,
43    pub direction: Direction,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
48pub struct TransactionDraft {
49    pub book: String,
50    pub idempotency_key: String,
51    pub postings: Vec<PostingDraft>,
52    #[serde(default)]
53    pub external_refs: Vec<ExternalRef>,
54    #[serde(default)]
55    pub metadata: serde_json::Value,
56    /// Business/event time; the server defaults it to now when absent.
57    #[serde(default)]
58    pub occurred_at: Option<DateTime<Utc>>,
59}
60
61#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
62pub struct Page {
63    pub after_seq: Option<Seq>,
64    pub limit: u32,
65}