bright_lightning/lnd/models/
lnd_payment.rs1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Clone)]
6pub struct LndPaymentRequest {
7 payment_request: String, timeout_seconds: i32, fee_limit_sat: String, allow_self_payment: bool, }
12impl LndPaymentRequest {
13 #[must_use]
14 pub const fn new(
15 payment_request: String,
16 timeout_seconds: i32,
17 fee_limit_sat: String,
18 allow_self_payment: bool,
19 ) -> Self {
20 Self {
21 payment_request,
22 timeout_seconds,
23 fee_limit_sat,
24 allow_self_payment,
25 }
26 }
27}
28impl std::fmt::Display for LndPaymentRequest {
29 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 write!(f, "{}", serde_json::to_string(self).unwrap_or_default())
31 }
32}
33impl From<LndPaymentRequest> for String {
34 fn from(val: LndPaymentRequest) -> Self {
35 serde_json::to_string(&val).unwrap_or_default()
36 }
37}
38impl TryFrom<String> for LndPaymentRequest {
39 type Error = anyhow::Error;
40 fn try_from(value: String) -> Result<Self, Self::Error> {
41 Ok(serde_json::from_str(&value)?)
42 }
43}
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
45pub enum InvoicePaymentState {
46 #[serde(rename = "IN_FLIGHT")]
47 InFlight,
48 #[serde(rename = "SUCCEEDED")]
49 Succeeded,
50 #[serde(rename = "FAILED")]
51 Failed,
52 #[serde(rename = "INITIATED")]
53 Initiaited,
54}
55impl Display for InvoicePaymentState {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 write!(f, "{}", serde_json::to_string_pretty(self).unwrap())
58 }
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
62pub struct LndPaymentResponse {
63 payment_preimage: String,
64 status: InvoicePaymentState,
65}
66impl LndPaymentResponse {
67 #[must_use]
68 pub fn preimage(&self) -> String {
69 self.payment_preimage.clone()
70 }
71 #[must_use]
72 pub fn status(&self) -> InvoicePaymentState {
73 self.status.clone()
74 }
75}
76impl TryFrom<String> for LndPaymentResponse {
77 type Error = anyhow::Error;
78 fn try_from(value: String) -> Result<Self, Self::Error> {
79 Ok(serde_json::from_str(&value)?)
80 }
81}
82impl TryInto<String> for LndPaymentResponse {
83 type Error = anyhow::Error;
84 fn try_into(self) -> Result<String, Self::Error> {
85 Ok(serde_json::to_string(&self)?)
86 }
87}
88impl Display for LndPaymentResponse {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 write!(f, "{}", serde_json::to_string_pretty(self).unwrap())
91 }
92}