Skip to content

Commit

Permalink
Store fees for saved payments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmitr committed May 6, 2024
1 parent 42549ea commit df5ce1d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ dictionary PaymentDetails {
PaymentDirection direction;
PaymentStatus status;
u64 last_update;
u64? fee_msat;
};

// [NonExhaustive]
Expand Down
2 changes: 2 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ where
direction: PaymentDirection::Inbound,
status: PaymentStatus::Succeeded,
last_update: 0,
fee_msat: None,
};

match self.payment_store.insert(payment) {
Expand Down Expand Up @@ -643,6 +644,7 @@ where
let update = PaymentDetailsUpdate {
preimage: Some(Some(payment_preimage)),
status: Some(PaymentStatus::Succeeded),
fee_msat: Some(fee_paid_msat),
..PaymentDetailsUpdate::new(payment_id)
};

Expand Down
6 changes: 6 additions & 0 deletions src/payment/bolt11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl Bolt11Payment {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Pending,
last_update: 0,
fee_msat: None,
};
self.payment_store.insert(payment)?;

Expand All @@ -139,6 +140,7 @@ impl Bolt11Payment {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Failed,
last_update: 0,
fee_msat: None,
};

self.payment_store.insert(payment)?;
Expand Down Expand Up @@ -233,6 +235,7 @@ impl Bolt11Payment {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Pending,
last_update: 0,
fee_msat: None,
};
self.payment_store.insert(payment)?;

Expand All @@ -258,6 +261,7 @@ impl Bolt11Payment {
direction: PaymentDirection::Outbound,
status: PaymentStatus::Failed,
last_update: 0,
fee_msat: None,
};
self.payment_store.insert(payment)?;

Expand Down Expand Up @@ -325,6 +329,7 @@ impl Bolt11Payment {
direction: PaymentDirection::Inbound,
status: PaymentStatus::Pending,
last_update: 0,
fee_msat: None,
};

self.payment_store.insert(payment)?;
Expand Down Expand Up @@ -457,6 +462,7 @@ impl Bolt11Payment {
direction: PaymentDirection::Inbound,
status: PaymentStatus::Pending,
last_update: 0,
fee_msat: None,
};

self.payment_store.insert(payment)?;
Expand Down
12 changes: 9 additions & 3 deletions src/payment/payment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct PaymentDetails {
pub status: PaymentStatus,
/// Last update timestamp, as seconds since Unix epoch.
pub last_update: u64,
/// Fee paid.
pub fee_msat: Option<u64>,
}

impl Writeable for PaymentDetails {
Expand All @@ -53,7 +55,8 @@ impl Writeable for PaymentDetails {
(6, self.amount_msat, required),
(8, self.direction, required),
(10, self.status, required),
(131074, self.last_update, required)
(131074, self.last_update, required),
(131076, self.fee_msat, required),
});
Ok(())
}
Expand All @@ -71,6 +74,7 @@ impl Readable for PaymentDetails {
(8, direction, required),
(10, status, required),
(131074, last_update, option),
(131076, fee_msat, option),
});

let id: PaymentId = id.0.ok_or(DecodeError::InvalidValue)?;
Expand Down Expand Up @@ -108,7 +112,7 @@ impl Readable for PaymentDetails {
}
};

Ok(PaymentDetails { id, kind, amount_msat, direction, status, last_update })
Ok(PaymentDetails { id, kind, amount_msat, direction, status, last_update, fee_msat })
}
}

Expand Down Expand Up @@ -241,11 +245,12 @@ pub(crate) struct PaymentDetailsUpdate {
pub amount_msat: Option<Option<u64>>,
pub direction: Option<PaymentDirection>,
pub status: Option<PaymentStatus>,
pub fee_msat: Option<Option<u64>>,
}

impl PaymentDetailsUpdate {
pub fn new(id: PaymentId) -> Self {
Self { id, preimage: None, secret: None, amount_msat: None, direction: None, status: None }
Self { id, preimage: None, secret: None, amount_msat: None, direction: None, status: None, fee_msat: None }
}
}

Expand Down Expand Up @@ -444,6 +449,7 @@ mod tests {
direction: PaymentDirection::Inbound,
status: PaymentStatus::Pending,
last_update: 0,
fee_msat: None,
};

assert_eq!(Ok(false), payment_store.insert(payment.clone()));
Expand Down
2 changes: 2 additions & 0 deletions src/payment/spontaneous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl SpontaneousPayment {
direction: PaymentDirection::Outbound,
amount_msat: Some(amount_msat),
last_update: 0,
fee_msat: None,
};
self.payment_store.insert(payment)?;

Expand All @@ -119,6 +120,7 @@ impl SpontaneousPayment {
direction: PaymentDirection::Outbound,
amount_msat: Some(amount_msat),
last_update: 0,
fee_msat: None,
};

self.payment_store.insert(payment)?;
Expand Down

0 comments on commit df5ce1d

Please sign in to comment.