use std::sync::Arc;
use bitcoin::address::NetworkUnchecked;
use lexe_api::types::{invoice::Invoice, payments::BasicPaymentV2};
use lexe_common::{
ln::{amount::Amount, hashes::Txid, priority::ConfirmationPriority},
time::TimestampMs,
};
use serde::{Deserialize, Serialize};
mod reexports {
pub use lexe_api::types::payments::{
ClientPaymentId, LnClaimId, PaymentCreatedIndex, PaymentDirection,
PaymentHash, PaymentId, PaymentKind, PaymentRail, PaymentSecret,
PaymentStatus, PaymentUpdatedIndex,
};
}
pub use reexports::*;
#[derive(Serialize, Deserialize)]
pub struct Payment {
pub index: PaymentCreatedIndex,
pub rail: PaymentRail,
pub kind: PaymentKind,
pub direction: PaymentDirection,
pub txid: Option<Txid>,
pub amount: Option<Amount>,
pub fees: Amount,
pub status: PaymentStatus,
pub status_msg: String,
pub address: Option<Arc<bitcoin::Address<NetworkUnchecked>>>,
pub invoice: Option<Arc<Invoice>>,
pub tx: Option<Arc<bitcoin::Transaction>>,
pub note: Option<String>,
pub payer_name: Option<String>,
pub payer_note: Option<String>,
pub priority: Option<ConfirmationPriority>,
pub expires_at: Option<TimestampMs>,
pub finalized_at: Option<TimestampMs>,
pub created_at: TimestampMs,
pub updated_at: TimestampMs,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub enum Order {
#[serde(rename = "asc")]
Asc,
#[serde(rename = "desc")]
Desc,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum PaymentFilter {
#[serde(rename = "all")]
All,
#[serde(rename = "pending")]
Pending,
#[serde(rename = "completed")]
Completed,
#[serde(rename = "failed")]
Failed,
#[serde(rename = "finalized")]
Finalized,
}
impl From<BasicPaymentV2> for Payment {
fn from(p: BasicPaymentV2) -> Self {
let BasicPaymentV2 {
id,
related_ids: _,
kind,
direction,
offer_id: _,
txid,
amount,
fee,
status,
status_str,
address,
invoice,
offer: _,
tx,
note,
payer_name,
payer_note,
priority,
quantity: _,
replacement_txid: _,
expires_at,
finalized_at,
created_at,
updated_at,
} = p;
let index = PaymentCreatedIndex { created_at, id };
Self {
index,
rail: kind.rail(),
kind,
direction,
txid,
amount,
fees: fee,
status,
status_msg: status_str,
address,
invoice,
tx,
note,
payer_name,
payer_note,
priority,
expires_at,
finalized_at,
created_at,
updated_at,
}
}
}