taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

wire.rs (6892B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2024, 2025, 2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 //! Type for the Taler Wire Gateway HTTP API <https://docs.taler.net/core/api-bank-wire.html#taler-wire-gateway-http-api>
     18 
     19 use compact_str::CompactString;
     20 use serde::{Deserialize, Serialize};
     21 use taler_macros::api_config;
     22 use url::Url;
     23 
     24 use super::{EddsaPublicKey, HashCode, ShortHashCode, WadId};
     25 use crate::{
     26     api::EddsaSignature,
     27     types::{
     28         amount::{Amount, Currency},
     29         payto::PaytoURI,
     30         timestamp::TalerTimestamp,
     31     },
     32 };
     33 
     34 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-WireConfig>
     35 #[api_config("taler-wire-gateway")]
     36 #[derive(Debug, Clone, Serialize, Deserialize)]
     37 pub struct WireConfig<'a> {
     38     pub currency: Currency,
     39     pub support_account_check: bool,
     40 }
     41 
     42 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferResponse>
     43 #[derive(Debug, Clone, Serialize, Deserialize)]
     44 pub struct TransferResponse {
     45     pub timestamp: TalerTimestamp,
     46     pub row_id: u64,
     47 }
     48 
     49 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferRequest>
     50 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
     51 pub struct TransferRequest {
     52     pub request_uid: HashCode,
     53     pub amount: Amount,
     54     pub exchange_base_url: Url,
     55     pub metadata: Option<CompactString>,
     56     pub wtid: ShortHashCode,
     57     pub credit_account: PaytoURI,
     58 }
     59 
     60 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferList>
     61 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
     62 pub struct TransferList {
     63     pub transfers: Vec<TransferListStatus>,
     64     pub debit_account: PaytoURI,
     65 }
     66 
     67 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransferListStatus>
     68 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
     69 pub struct TransferListStatus {
     70     pub row_id: u64,
     71     pub status: TransferState,
     72     pub amount: Amount,
     73     pub credit_account: PaytoURI,
     74     pub timestamp: TalerTimestamp,
     75 }
     76 
     77 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-TransfertSatus>
     78 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
     79 pub struct TransferStatus {
     80     pub status: TransferState,
     81     pub status_msg: Option<String>,
     82     pub amount: Amount,
     83     pub origin_exchange_url: String,
     84     pub metadata: Option<CompactString>,
     85     pub wtid: ShortHashCode,
     86     pub credit_account: PaytoURI,
     87     pub timestamp: TalerTimestamp,
     88 }
     89 
     90 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-OutgoingHistory>
     91 #[derive(Debug, Clone, Serialize, Deserialize)]
     92 pub struct OutgoingHistory {
     93     pub outgoing_transactions: Vec<OutgoingBankTransaction>,
     94     pub debit_account: PaytoURI,
     95 }
     96 
     97 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-OutgoingBankTransaction>
     98 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
     99 pub struct OutgoingBankTransaction {
    100     pub row_id: u64,
    101     pub date: TalerTimestamp,
    102     pub amount: Amount,
    103     pub debit_fee: Option<Amount>,
    104     pub credit_account: PaytoURI,
    105     pub wtid: ShortHashCode,
    106     pub exchange_base_url: Url,
    107     pub metadata: Option<CompactString>,
    108 }
    109 
    110 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingHistory>
    111 #[derive(Debug, Clone, Serialize, Deserialize)]
    112 pub struct IncomingHistory {
    113     pub credit_account: PaytoURI,
    114     pub incoming_transactions: Vec<IncomingBankTransaction>,
    115 }
    116 
    117 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-IncomingBankTransaction>
    118 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
    119 #[serde(tag = "type")]
    120 pub enum IncomingBankTransaction {
    121     #[serde(rename = "RESERVE")]
    122     Reserve {
    123         row_id: u64,
    124         date: TalerTimestamp,
    125         amount: Amount,
    126         credit_fee: Option<Amount>,
    127         debit_account: PaytoURI,
    128         reserve_pub: EddsaPublicKey,
    129         authorization_pub: Option<EddsaPublicKey>,
    130         authorization_sig: Option<EddsaSignature>,
    131     },
    132     #[serde(rename = "WAD")]
    133     Wad {
    134         row_id: u64,
    135         date: TalerTimestamp,
    136         amount: Amount,
    137         debit_account: PaytoURI,
    138         origin_exchange_url: Url,
    139         wad_id: WadId,
    140     },
    141     #[serde(rename = "KYCAUTH")]
    142     Kyc {
    143         row_id: u64,
    144         date: TalerTimestamp,
    145         amount: Amount,
    146         credit_fee: Option<Amount>,
    147         debit_account: PaytoURI,
    148         account_pub: EddsaPublicKey,
    149         authorization_pub: Option<EddsaPublicKey>,
    150         authorization_sig: Option<EddsaSignature>,
    151     },
    152 }
    153 
    154 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddIncomingRequest>
    155 #[derive(Debug, Clone, Serialize, Deserialize)]
    156 pub struct AddIncomingRequest {
    157     pub amount: Amount,
    158     pub reserve_pub: EddsaPublicKey,
    159     pub debit_account: PaytoURI,
    160 }
    161 
    162 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddIncomingResponse>
    163 #[derive(Debug, Clone, Serialize, Deserialize)]
    164 pub struct AddIncomingResponse {
    165     pub row_id: u64,
    166     pub timestamp: TalerTimestamp,
    167 }
    168 
    169 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddKycauthRequest>
    170 #[derive(Debug, Clone, Serialize, Deserialize)]
    171 pub struct AddKycauthRequest {
    172     pub amount: Amount,
    173     pub account_pub: EddsaPublicKey,
    174     pub debit_account: PaytoURI,
    175 }
    176 
    177 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AddMappedRequest>
    178 #[derive(Debug, Clone, Serialize, Deserialize)]
    179 pub struct AddMappedRequest {
    180     pub amount: Amount,
    181     pub authorization_pub: EddsaPublicKey,
    182     pub debit_account: PaytoURI,
    183 }
    184 
    185 /// <https://docs.taler.net/core/api-bank-wire.html#tsref-type-AccountInfo>
    186 #[derive(Debug, Clone, Serialize, Deserialize)]
    187 pub struct AccountInfo {}
    188 
    189 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, sqlx::Type)]
    190 #[allow(non_camel_case_types)]
    191 #[sqlx(type_name = "transfer_status")]
    192 pub enum TransferState {
    193     pending,
    194     transient_failure,
    195     permanent_failure,
    196     late_failure,
    197     success,
    198 }
    199 
    200 impl AsRef<str> for TransferState {
    201     fn as_ref(&self) -> &str {
    202         match self {
    203             TransferState::pending => "pending",
    204             TransferState::transient_failure => "transient_failure",
    205             TransferState::permanent_failure => "permanent_failure",
    206             TransferState::late_failure => "late_failure",
    207             TransferState::success => "success",
    208         }
    209     }
    210 }