|
1 | | -// This file is Copyright its original authors, visible in version control history. |
2 | | -// |
3 | | -// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
4 | | -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
5 | | -// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in |
6 | | -// accordance with one or both of these licenses. |
7 | | - |
8 | | -use bitcoin::Txid; |
9 | | -use lightning::{impl_writeable_tlv_based, ln::channelmanager::PaymentId}; |
10 | | - |
11 | | -use crate::{ |
12 | | - data_store::{StorableObject, StorableObjectUpdate}, |
13 | | - payment::{store::PaymentDetailsUpdate, PaymentDetails}, |
14 | | -}; |
15 | | - |
16 | | -/// Represents a pending payment |
17 | | -#[derive(Clone, Debug, PartialEq, Eq)] |
18 | | -pub struct PendingPaymentDetails { |
19 | | - /// The full payment details |
20 | | - pub details: PaymentDetails, |
21 | | - /// Transaction IDs that have replaced or conflict with this payment. |
22 | | - pub conflicting_txids: Vec<Txid>, |
23 | | -} |
24 | | - |
25 | | -impl PendingPaymentDetails { |
26 | | - pub(crate) fn new(details: PaymentDetails, conflicting_txids: Vec<Txid>) -> Self { |
27 | | - Self { details, conflicting_txids } |
28 | | - } |
29 | | - |
30 | | - /// Convert to finalized payment for the main payment store |
31 | | - pub fn into_payment_details(self) -> PaymentDetails { |
32 | | - self.details |
33 | | - } |
34 | | -} |
35 | | - |
36 | | -impl_writeable_tlv_based!(PendingPaymentDetails, { |
37 | | - (0, details, required), |
38 | | - (2, conflicting_txids, optional_vec), |
39 | | -}); |
40 | | - |
41 | | -#[derive(Clone, Debug, PartialEq, Eq)] |
42 | | -pub(crate) struct PendingPaymentDetailsUpdate { |
43 | | - pub id: PaymentId, |
44 | | - pub payment_update: Option<PaymentDetailsUpdate>, |
45 | | - pub conflicting_txids: Option<Vec<Txid>>, |
46 | | -} |
47 | | - |
48 | | -impl StorableObject for PendingPaymentDetails { |
49 | | - type Id = PaymentId; |
50 | | - type Update = PendingPaymentDetailsUpdate; |
51 | | - |
52 | | - fn id(&self) -> Self::Id { |
53 | | - self.details.id |
54 | | - } |
55 | | - |
56 | | - fn update(&mut self, update: &Self::Update) -> bool { |
57 | | - let mut updated = false; |
58 | | - |
59 | | - // Update the underlying payment details if present |
60 | | - if let Some(payment_update) = &update.payment_update { |
61 | | - updated |= self.details.update(payment_update); |
62 | | - } |
63 | | - |
64 | | - if let Some(new_conflicting_txids) = &update.conflicting_txids { |
65 | | - if &self.conflicting_txids != new_conflicting_txids { |
66 | | - self.conflicting_txids = new_conflicting_txids.clone(); |
67 | | - updated = true; |
68 | | - } |
69 | | - } |
70 | | - |
71 | | - updated |
72 | | - } |
73 | | - |
74 | | - fn to_update(&self) -> Self::Update { |
75 | | - self.into() |
76 | | - } |
77 | | -} |
78 | | - |
79 | | -impl StorableObjectUpdate<PendingPaymentDetails> for PendingPaymentDetailsUpdate { |
80 | | - fn id(&self) -> <PendingPaymentDetails as StorableObject>::Id { |
81 | | - self.id |
82 | | - } |
83 | | -} |
84 | | - |
85 | | -impl From<&PendingPaymentDetails> for PendingPaymentDetailsUpdate { |
86 | | - fn from(value: &PendingPaymentDetails) -> Self { |
87 | | - Self { |
88 | | - id: value.id(), |
89 | | - payment_update: Some(value.details.to_update()), |
90 | | - conflicting_txids: Some(value.conflicting_txids.clone()), |
91 | | - } |
92 | | - } |
93 | | -} |
| 1 | +// This file is Copyright its original authors, visible in version control history. |
| 2 | +// |
| 3 | +// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
| 5 | +// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in |
| 6 | +// accordance with one or both of these licenses. |
| 7 | + |
| 8 | +use bitcoin::Txid; |
| 9 | +use lightning::impl_writeable_tlv_based; |
| 10 | +use lightning::ln::channelmanager::PaymentId; |
| 11 | + |
| 12 | +use crate::data_store::{StorableObject, StorableObjectUpdate}; |
| 13 | +use crate::payment::store::PaymentDetailsUpdate; |
| 14 | +use crate::payment::PaymentDetails; |
| 15 | + |
| 16 | +/// Represents a pending payment |
| 17 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 18 | +pub struct PendingPaymentDetails { |
| 19 | + /// The full payment details |
| 20 | + pub details: PaymentDetails, |
| 21 | + /// Transaction IDs that have replaced or conflict with this payment. |
| 22 | + pub conflicting_txids: Vec<Txid>, |
| 23 | +} |
| 24 | + |
| 25 | +impl PendingPaymentDetails { |
| 26 | + pub(crate) fn new(details: PaymentDetails, conflicting_txids: Vec<Txid>) -> Self { |
| 27 | + Self { details, conflicting_txids } |
| 28 | + } |
| 29 | + |
| 30 | + /// Convert to finalized payment for the main payment store |
| 31 | + pub fn into_payment_details(self) -> PaymentDetails { |
| 32 | + self.details |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +impl_writeable_tlv_based!(PendingPaymentDetails, { |
| 37 | + (0, details, required), |
| 38 | + (2, conflicting_txids, optional_vec), |
| 39 | +}); |
| 40 | + |
| 41 | +#[derive(Clone, Debug, PartialEq, Eq)] |
| 42 | +pub(crate) struct PendingPaymentDetailsUpdate { |
| 43 | + pub id: PaymentId, |
| 44 | + pub payment_update: Option<PaymentDetailsUpdate>, |
| 45 | + pub conflicting_txids: Option<Vec<Txid>>, |
| 46 | +} |
| 47 | + |
| 48 | +impl StorableObject for PendingPaymentDetails { |
| 49 | + type Id = PaymentId; |
| 50 | + type Update = PendingPaymentDetailsUpdate; |
| 51 | + |
| 52 | + fn id(&self) -> Self::Id { |
| 53 | + self.details.id |
| 54 | + } |
| 55 | + |
| 56 | + fn update(&mut self, update: &Self::Update) -> bool { |
| 57 | + let mut updated = false; |
| 58 | + |
| 59 | + // Update the underlying payment details if present |
| 60 | + if let Some(payment_update) = &update.payment_update { |
| 61 | + updated |= self.details.update(payment_update); |
| 62 | + } |
| 63 | + |
| 64 | + if let Some(new_conflicting_txids) = &update.conflicting_txids { |
| 65 | + if &self.conflicting_txids != new_conflicting_txids { |
| 66 | + self.conflicting_txids = new_conflicting_txids.clone(); |
| 67 | + updated = true; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + updated |
| 72 | + } |
| 73 | + |
| 74 | + fn to_update(&self) -> Self::Update { |
| 75 | + self.into() |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +impl StorableObjectUpdate<PendingPaymentDetails> for PendingPaymentDetailsUpdate { |
| 80 | + fn id(&self) -> <PendingPaymentDetails as StorableObject>::Id { |
| 81 | + self.id |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +impl From<&PendingPaymentDetails> for PendingPaymentDetailsUpdate { |
| 86 | + fn from(value: &PendingPaymentDetails) -> Self { |
| 87 | + Self { |
| 88 | + id: value.id(), |
| 89 | + payment_update: Some(value.details.to_update()), |
| 90 | + conflicting_txids: Some(value.conflicting_txids.clone()), |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments