Skip to content

Commit f28b20d

Browse files
authored
Merge pull request #32 from G8XSU/forwarded-payments
Add Api impl for ListForwardedPayments.
2 parents 5840bad + 5f34539 commit f28b20d

27 files changed

+470
-147
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ jobs:
3434
- name: Pin packages to allow for MSRV
3535
if: matrix.msrv
3636
run: |
37-
cargo update -p hashlink --precise "0.8.2" --verbose # hashlink 0.8.3 requires hashbrown 0.14, requiring 1.64.0
3837
cargo update -p regex --precise "1.9.6" --verbose # regex 1.10.0 requires rustc 1.65.0
3938
cargo update -p home --precise "0.5.5" --verbose # home v0.5.9 requires rustc 1.70 or newer
4039
cargo update -p tokio --precise "1.38.1" --verbose # tokio v1.39.0 requires rustc 1.70 or newer

Cargo.lock

Lines changed: 15 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ldk-server-protos/src/api.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,44 @@ pub struct ListPaymentsResponse {
337337
#[prost(message, repeated, tag = "1")]
338338
pub payments: ::prost::alloc::vec::Vec<super::types::Payment>,
339339
}
340+
/// Retrieves list of all forwarded payments.
341+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/enum.Event.html#variant.PaymentForwarded>
342+
#[allow(clippy::derive_partial_eq_without_eq)]
343+
#[derive(Clone, PartialEq, ::prost::Message)]
344+
pub struct ListForwardedPaymentsRequest {
345+
/// `page_token` is a pagination token.
346+
///
347+
/// To query for the first page, `page_token` must not be specified.
348+
///
349+
/// For subsequent pages, use the value that was returned as `next_page_token` in the previous
350+
/// page's response.
351+
#[prost(message, optional, tag = "1")]
352+
pub page_token: ::core::option::Option<super::types::PageToken>,
353+
}
354+
/// The response `content` for the `ListForwardedPayments` API, when HttpStatusCode is OK (200).
355+
/// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
356+
#[allow(clippy::derive_partial_eq_without_eq)]
357+
#[derive(Clone, PartialEq, ::prost::Message)]
358+
pub struct ListForwardedPaymentsResponse {
359+
/// List of forwarded payments.
360+
#[prost(message, repeated, tag = "1")]
361+
pub forwarded_payments: ::prost::alloc::vec::Vec<super::types::ForwardedPayment>,
362+
/// `next_page_token` is a pagination token, used to retrieve the next page of results.
363+
/// Use this value to query for next-page of paginated operation, by specifying
364+
/// this value as the `page_token` in the next request.
365+
///
366+
/// If `next_page_token` is `None`, then the "last page" of results has been processed and
367+
/// there is no more data to be retrieved.
368+
///
369+
/// If `next_page_token` is not `None`, it does not necessarily mean that there is more data in the
370+
/// result set. The only way to know when you have reached the end of the result set is when
371+
/// `next_page_token` is `None`.
372+
///
373+
/// **Caution**: Clients must not assume a specific number of records to be present in a page for
374+
/// paginated response.
375+
#[prost(message, optional, tag = "2")]
376+
pub next_page_token: ::core::option::Option<super::types::PageToken>,
377+
}
340378
/// Retrieves an overview of all known balances.
341379
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.list_balances>
342380
#[allow(clippy::derive_partial_eq_without_eq)]

ldk-server-protos/src/proto/api.proto

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,40 @@ message ListPaymentsResponse {
319319
repeated types.Payment payments = 1;
320320
}
321321

322+
// Retrieves list of all forwarded payments.
323+
// See more: https://docs.rs/ldk-node/latest/ldk_node/enum.Event.html#variant.PaymentForwarded
324+
message ListForwardedPaymentsRequest {
325+
// `page_token` is a pagination token.
326+
//
327+
// To query for the first page, `page_token` must not be specified.
328+
//
329+
// For subsequent pages, use the value that was returned as `next_page_token` in the previous
330+
// page's response.
331+
optional types.PageToken page_token = 1;
332+
}
333+
334+
// The response `content` for the `ListForwardedPayments` API, when HttpStatusCode is OK (200).
335+
// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.
336+
message ListForwardedPaymentsResponse {
337+
// List of forwarded payments.
338+
repeated types.ForwardedPayment forwarded_payments = 1;
339+
340+
// `next_page_token` is a pagination token, used to retrieve the next page of results.
341+
// Use this value to query for next-page of paginated operation, by specifying
342+
// this value as the `page_token` in the next request.
343+
//
344+
// If `next_page_token` is `None`, then the "last page" of results has been processed and
345+
// there is no more data to be retrieved.
346+
//
347+
// If `next_page_token` is not `None`, it does not necessarily mean that there is more data in the
348+
// result set. The only way to know when you have reached the end of the result set is when
349+
// `next_page_token` is `None`.
350+
//
351+
// **Caution**: Clients must not assume a specific number of records to be present in a page for
352+
// paginated response.
353+
optional types.PageToken next_page_token = 2;
354+
}
355+
322356
// Retrieves an overview of all known balances.
323357
// See more: https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.list_balances
324358
message GetBalancesRequest {}

ldk-server-protos/src/proto/types.proto

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,51 @@ enum PaymentStatus {
161161
FAILED = 2;
162162
}
163163

164+
// A forwarded payment through our node.
165+
// See more: https://docs.rs/ldk-node/latest/ldk_node/enum.Event.html#variant.PaymentForwarded
166+
message ForwardedPayment{
167+
// The channel id of the incoming channel between the previous node and us.
168+
string prev_channel_id = 1;
169+
170+
// The channel id of the outgoing channel between the next node and us.
171+
string next_channel_id = 2;
172+
173+
// The `user_channel_id` of the incoming channel between the previous node and us.
174+
string prev_user_channel_id = 3;
175+
176+
// The `user_channel_id` of the outgoing channel between the next node and us.
177+
// This will be `None` if the payment was settled via an on-chain transaction.
178+
// See the caveat described for the `total_fee_earned_msat` field.
179+
optional string next_user_channel_id = 4;
180+
181+
// The total fee, in milli-satoshis, which was earned as a result of the payment.
182+
//
183+
// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC was pending, the amount the
184+
// next hop claimed will have been rounded down to the nearest whole satoshi. Thus, the fee calculated here may be
185+
// higher than expected as we still claimed the full value in millisatoshis from the source.
186+
// In this case, `claim_from_onchain_tx` will be set.
187+
//
188+
// If the channel which sent us the payment has been force-closed, we will claim the funds via an on-chain transaction.
189+
// In that case we do not yet know the on-chain transaction fees which we will spend and will instead set this to `None`.
190+
optional uint64 total_fee_earned_msat = 5;
191+
192+
// The share of the total fee, in milli-satoshis, which was withheld in addition to the forwarding fee.
193+
// This will only be set if we forwarded an intercepted HTLC with less than the expected amount. This means our
194+
// counterparty accepted to receive less than the invoice amount.
195+
//
196+
// The caveat described above the `total_fee_earned_msat` field applies here as well.
197+
optional uint64 skimmed_fee_msat = 6;
198+
199+
// If this is true, the forwarded HTLC was claimed by our counterparty via an on-chain transaction.
200+
bool claim_from_onchain_tx = 7;
201+
202+
// The final amount forwarded, in milli-satoshis, after the fee is deducted.
203+
//
204+
// The caveat described above the `total_fee_earned_msat` field applies here as well.
205+
optional uint64 outbound_amount_forwarded_msat = 8;
206+
207+
}
208+
164209
message Channel {
165210
// The channel ID (prior to funding transaction generation, this is a random 32-byte
166211
// identifier, afterwards this is the transaction ID of the funding transaction XOR the
@@ -579,3 +624,9 @@ message AwaitingThresholdConfirmations {
579624
// The amount, in satoshis, of the output being swept.
580625
uint64 amount_satoshis = 5;
581626
}
627+
628+
// Token used to determine start of next page in paginated APIs.
629+
message PageToken {
630+
string token = 1;
631+
int64 index = 2;
632+
}

ldk-server-protos/src/types.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,52 @@ pub struct LspFeeLimits {
165165
#[prost(uint64, optional, tag = "2")]
166166
pub max_proportional_opening_fee_ppm_msat: ::core::option::Option<u64>,
167167
}
168+
/// A forwarded payment through our node.
169+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/enum.Event.html#variant.PaymentForwarded>
170+
#[allow(clippy::derive_partial_eq_without_eq)]
171+
#[derive(Clone, PartialEq, ::prost::Message)]
172+
pub struct ForwardedPayment {
173+
/// The channel id of the incoming channel between the previous node and us.
174+
#[prost(string, tag = "1")]
175+
pub prev_channel_id: ::prost::alloc::string::String,
176+
/// The channel id of the outgoing channel between the next node and us.
177+
#[prost(string, tag = "2")]
178+
pub next_channel_id: ::prost::alloc::string::String,
179+
/// The `user_channel_id` of the incoming channel between the previous node and us.
180+
#[prost(string, tag = "3")]
181+
pub prev_user_channel_id: ::prost::alloc::string::String,
182+
/// The `user_channel_id` of the outgoing channel between the next node and us.
183+
/// This will be `None` if the payment was settled via an on-chain transaction.
184+
/// See the caveat described for the `total_fee_earned_msat` field.
185+
#[prost(string, optional, tag = "4")]
186+
pub next_user_channel_id: ::core::option::Option<::prost::alloc::string::String>,
187+
/// The total fee, in milli-satoshis, which was earned as a result of the payment.
188+
///
189+
/// Note that if we force-closed the channel over which we forwarded an HTLC while the HTLC was pending, the amount the
190+
/// next hop claimed will have been rounded down to the nearest whole satoshi. Thus, the fee calculated here may be
191+
/// higher than expected as we still claimed the full value in millisatoshis from the source.
192+
/// In this case, `claim_from_onchain_tx` will be set.
193+
///
194+
/// If the channel which sent us the payment has been force-closed, we will claim the funds via an on-chain transaction.
195+
/// In that case we do not yet know the on-chain transaction fees which we will spend and will instead set this to `None`.
196+
#[prost(uint64, optional, tag = "5")]
197+
pub total_fee_earned_msat: ::core::option::Option<u64>,
198+
/// The share of the total fee, in milli-satoshis, which was withheld in addition to the forwarding fee.
199+
/// This will only be set if we forwarded an intercepted HTLC with less than the expected amount. This means our
200+
/// counterparty accepted to receive less than the invoice amount.
201+
///
202+
/// The caveat described above the `total_fee_earned_msat` field applies here as well.
203+
#[prost(uint64, optional, tag = "6")]
204+
pub skimmed_fee_msat: ::core::option::Option<u64>,
205+
/// If this is true, the forwarded HTLC was claimed by our counterparty via an on-chain transaction.
206+
#[prost(bool, tag = "7")]
207+
pub claim_from_onchain_tx: bool,
208+
/// The final amount forwarded, in milli-satoshis, after the fee is deducted.
209+
///
210+
/// The caveat described above the `total_fee_earned_msat` field applies here as well.
211+
#[prost(uint64, optional, tag = "8")]
212+
pub outbound_amount_forwarded_msat: ::core::option::Option<u64>,
213+
}
168214
#[allow(clippy::derive_partial_eq_without_eq)]
169215
#[derive(Clone, PartialEq, ::prost::Message)]
170216
pub struct Channel {
@@ -647,6 +693,15 @@ pub struct AwaitingThresholdConfirmations {
647693
#[prost(uint64, tag = "5")]
648694
pub amount_satoshis: u64,
649695
}
696+
/// Token used to determine start of next page in paginated APIs.
697+
#[allow(clippy::derive_partial_eq_without_eq)]
698+
#[derive(Clone, PartialEq, ::prost::Message)]
699+
pub struct PageToken {
700+
#[prost(string, tag = "1")]
701+
pub token: ::prost::alloc::string::String,
702+
#[prost(int64, tag = "2")]
703+
pub index: i64,
704+
}
650705
/// Represents the direction of a payment.
651706
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
652707
#[repr(i32)]

ldk-server/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
ldk-node = { version = "0.4.0", default-features = false }
7+
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", rev = "2095d878be10923845bcdd1dd039ab0e670e723d" }
88
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
99
serde_json = { version = "1.0.118", default-features = false }
1010
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
@@ -15,7 +15,5 @@ prost = { version = "0.11.6", default-features = false, features = ["std"] }
1515
ldk-server-protos = { path = "../ldk-server-protos" }
1616
bytes = "1.4.0"
1717
hex = { package = "hex-conservative", version = "0.2.1", default-features = false }
18-
rusqlite = { version = "0.28.0", features = ["bundled"] }
19-
20-
[dev-dependencies]
18+
rusqlite = { version = "0.31.0", features = ["bundled"] }
2119
rand = "0.8.5"

ldk-server/src/api/bolt11_receive.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
use ldk_node::Node;
1+
use crate::service::Context;
22
use ldk_server_protos::api::{Bolt11ReceiveRequest, Bolt11ReceiveResponse};
3-
use std::sync::Arc;
43

54
pub(crate) const BOLT11_RECEIVE_PATH: &str = "Bolt11Receive";
65

76
pub(crate) fn handle_bolt11_receive_request(
8-
node: Arc<Node>, request: Bolt11ReceiveRequest,
7+
context: Context, request: Bolt11ReceiveRequest,
98
) -> Result<Bolt11ReceiveResponse, ldk_node::NodeError> {
109
let invoice = match request.amount_msat {
11-
Some(amount_msat) => {
12-
node.bolt11_payment().receive(amount_msat, &request.description, request.expiry_secs)?
13-
},
14-
None => node
10+
Some(amount_msat) => context.node.bolt11_payment().receive(
11+
amount_msat,
12+
&request.description,
13+
request.expiry_secs,
14+
)?,
15+
None => context
16+
.node
1517
.bolt11_payment()
1618
.receive_variable_amount(&request.description, request.expiry_secs)?,
1719
};

0 commit comments

Comments
 (0)