Skip to content

Commit 7242146

Browse files
authored
Merge pull request #15 from G8XSU/payment-apis
Implement GetPaymentDetails and ListPayments Api.
2 parents b6eb138 + 4a37f1f commit 7242146

File tree

7 files changed

+566
-1
lines changed

7 files changed

+566
-1
lines changed

protos/src/lib.rs

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,202 @@ pub struct ListChannelsResponse {
322322
#[prost(message, repeated, tag = "1")]
323323
pub channels: ::prost::alloc::vec::Vec<Channel>,
324324
}
325+
/// Returns payment details for a given payment_id.
326+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.payment>
327+
#[allow(clippy::derive_partial_eq_without_eq)]
328+
#[derive(Clone, PartialEq, ::prost::Message)]
329+
pub struct GetPaymentDetailsRequest {
330+
/// An identifier used to uniquely identify a payment in hex-encoded form.
331+
#[prost(string, tag = "1")]
332+
pub payment_id: ::prost::alloc::string::String,
333+
}
334+
#[allow(clippy::derive_partial_eq_without_eq)]
335+
#[derive(Clone, PartialEq, ::prost::Message)]
336+
pub struct GetPaymentDetailsResponse {
337+
/// Represents a payment.
338+
/// Will be `None` if payment doesn't exist.
339+
#[prost(message, optional, tag = "1")]
340+
pub payment: ::core::option::Option<Payment>,
341+
}
342+
/// Retrieves list of all payments.
343+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.list_payments>
344+
#[allow(clippy::derive_partial_eq_without_eq)]
345+
#[derive(Clone, PartialEq, ::prost::Message)]
346+
pub struct ListPaymentsRequest {}
347+
#[allow(clippy::derive_partial_eq_without_eq)]
348+
#[derive(Clone, PartialEq, ::prost::Message)]
349+
pub struct ListPaymentsResponse {
350+
/// List of payments.
351+
#[prost(message, repeated, tag = "1")]
352+
pub payments: ::prost::alloc::vec::Vec<Payment>,
353+
}
354+
/// Represents a payment.
355+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.PaymentDetails.html>
356+
#[allow(clippy::derive_partial_eq_without_eq)]
357+
#[derive(Clone, PartialEq, ::prost::Message)]
358+
pub struct Payment {
359+
/// An identifier used to uniquely identify a payment in hex-encoded form.
360+
#[prost(string, tag = "1")]
361+
pub id: ::prost::alloc::string::String,
362+
/// The kind of the payment.
363+
#[prost(message, optional, tag = "2")]
364+
pub kind: ::core::option::Option<PaymentKind>,
365+
/// The amount transferred.
366+
#[prost(uint64, optional, tag = "3")]
367+
pub amount_msat: ::core::option::Option<u64>,
368+
/// The direction of the payment.
369+
#[prost(enumeration = "PaymentDirection", tag = "4")]
370+
pub direction: i32,
371+
/// The status of the payment.
372+
#[prost(enumeration = "PaymentStatus", tag = "5")]
373+
pub status: i32,
374+
/// The timestamp, in seconds since start of the UNIX epoch, when this entry was last updated.
375+
#[prost(uint64, tag = "6")]
376+
pub latest_update_timestamp: u64,
377+
}
378+
#[allow(clippy::derive_partial_eq_without_eq)]
379+
#[derive(Clone, PartialEq, ::prost::Message)]
380+
pub struct PaymentKind {
381+
#[prost(oneof = "payment_kind::Kind", tags = "1, 2, 3, 4, 5, 6")]
382+
pub kind: ::core::option::Option<payment_kind::Kind>,
383+
}
384+
/// Nested message and enum types in `PaymentKind`.
385+
pub mod payment_kind {
386+
#[allow(clippy::derive_partial_eq_without_eq)]
387+
#[derive(Clone, PartialEq, ::prost::Oneof)]
388+
pub enum Kind {
389+
#[prost(message, tag = "1")]
390+
Onchain(super::Onchain),
391+
#[prost(message, tag = "2")]
392+
Bolt11(super::Bolt11),
393+
#[prost(message, tag = "3")]
394+
Bolt11Jit(super::Bolt11Jit),
395+
#[prost(message, tag = "4")]
396+
Bolt12Offer(super::Bolt12Offer),
397+
#[prost(message, tag = "5")]
398+
Bolt12Refund(super::Bolt12Refund),
399+
#[prost(message, tag = "6")]
400+
Spontaneous(super::Spontaneous),
401+
}
402+
}
403+
/// Represents an on-chain payment.
404+
#[allow(clippy::derive_partial_eq_without_eq)]
405+
#[derive(Clone, PartialEq, ::prost::Message)]
406+
pub struct Onchain {}
407+
/// Represents a BOLT 11 payment.
408+
#[allow(clippy::derive_partial_eq_without_eq)]
409+
#[derive(Clone, PartialEq, ::prost::Message)]
410+
pub struct Bolt11 {
411+
/// The payment hash, i.e., the hash of the preimage.
412+
#[prost(string, tag = "1")]
413+
pub hash: ::prost::alloc::string::String,
414+
/// The pre-image used by the payment.
415+
#[prost(string, optional, tag = "2")]
416+
pub preimage: ::core::option::Option<::prost::alloc::string::String>,
417+
/// The secret used by the payment.
418+
#[prost(bytes = "bytes", optional, tag = "3")]
419+
pub secret: ::core::option::Option<::prost::bytes::Bytes>,
420+
}
421+
/// Represents a BOLT 11 payment intended to open an LSPS 2 just-in-time channel.
422+
#[allow(clippy::derive_partial_eq_without_eq)]
423+
#[derive(Clone, PartialEq, ::prost::Message)]
424+
pub struct Bolt11Jit {
425+
/// The payment hash, i.e., the hash of the preimage.
426+
#[prost(string, tag = "1")]
427+
pub hash: ::prost::alloc::string::String,
428+
/// The pre-image used by the payment.
429+
#[prost(string, optional, tag = "2")]
430+
pub preimage: ::core::option::Option<::prost::alloc::string::String>,
431+
/// The secret used by the payment.
432+
#[prost(bytes = "bytes", optional, tag = "3")]
433+
pub secret: ::core::option::Option<::prost::bytes::Bytes>,
434+
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
435+
///
436+
/// Allowing them to deduct this fee from the first inbound payment will pay for the LSP’s channel opening fees.
437+
///
438+
/// See \[`LdkChannelConfig::accept_underpaying_htlcs`\](<https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.accept_underpaying_htlcs>)
439+
/// for more information.
440+
#[prost(message, optional, tag = "4")]
441+
pub lsp_fee_limits: ::core::option::Option<LspFeeLimits>,
442+
}
443+
/// Represents a BOLT 12 ‘offer’ payment, i.e., a payment for an Offer.
444+
#[allow(clippy::derive_partial_eq_without_eq)]
445+
#[derive(Clone, PartialEq, ::prost::Message)]
446+
pub struct Bolt12Offer {
447+
/// The payment hash, i.e., the hash of the preimage.
448+
#[prost(string, optional, tag = "1")]
449+
pub hash: ::core::option::Option<::prost::alloc::string::String>,
450+
/// The pre-image used by the payment.
451+
#[prost(string, optional, tag = "2")]
452+
pub preimage: ::core::option::Option<::prost::alloc::string::String>,
453+
/// The secret used by the payment.
454+
#[prost(bytes = "bytes", optional, tag = "3")]
455+
pub secret: ::core::option::Option<::prost::bytes::Bytes>,
456+
/// The hex-encoded ID of the offer this payment is for.
457+
#[prost(string, tag = "4")]
458+
pub offer_id: ::prost::alloc::string::String,
459+
/// The payer's note for the payment.
460+
/// Truncated to \[PAYER_NOTE_LIMIT\](<https://docs.rs/lightning/latest/lightning/offers/invoice_request/constant.PAYER_NOTE_LIMIT.html>).
461+
///
462+
/// **Caution**: The `payer_note` field may come from an untrusted source. To prevent potential misuse,
463+
/// all non-printable characters will be sanitized and replaced with safe characters.
464+
#[prost(string, optional, tag = "5")]
465+
pub payer_note: ::core::option::Option<::prost::alloc::string::String>,
466+
/// The quantity of an item requested in the offer.
467+
#[prost(uint64, optional, tag = "6")]
468+
pub quantity: ::core::option::Option<u64>,
469+
}
470+
/// Represents a BOLT 12 ‘refund’ payment, i.e., a payment for a Refund.
471+
#[allow(clippy::derive_partial_eq_without_eq)]
472+
#[derive(Clone, PartialEq, ::prost::Message)]
473+
pub struct Bolt12Refund {
474+
/// The payment hash, i.e., the hash of the preimage.
475+
#[prost(string, optional, tag = "1")]
476+
pub hash: ::core::option::Option<::prost::alloc::string::String>,
477+
/// The pre-image used by the payment.
478+
#[prost(string, optional, tag = "2")]
479+
pub preimage: ::core::option::Option<::prost::alloc::string::String>,
480+
/// The secret used by the payment.
481+
#[prost(bytes = "bytes", optional, tag = "3")]
482+
pub secret: ::core::option::Option<::prost::bytes::Bytes>,
483+
/// The payer's note for the payment.
484+
/// Truncated to \[PAYER_NOTE_LIMIT\](<https://docs.rs/lightning/latest/lightning/offers/invoice_request/constant.PAYER_NOTE_LIMIT.html>).
485+
///
486+
/// **Caution**: The `payer_note` field may come from an untrusted source. To prevent potential misuse,
487+
/// all non-printable characters will be sanitized and replaced with safe characters.
488+
#[prost(string, optional, tag = "5")]
489+
pub payer_note: ::core::option::Option<::prost::alloc::string::String>,
490+
/// The quantity of an item requested in the offer.
491+
#[prost(uint64, optional, tag = "6")]
492+
pub quantity: ::core::option::Option<u64>,
493+
}
494+
/// Represents a spontaneous (“keysend”) payment.
495+
#[allow(clippy::derive_partial_eq_without_eq)]
496+
#[derive(Clone, PartialEq, ::prost::Message)]
497+
pub struct Spontaneous {
498+
/// The payment hash, i.e., the hash of the preimage.
499+
#[prost(string, tag = "1")]
500+
pub hash: ::prost::alloc::string::String,
501+
/// The pre-image used by the payment.
502+
#[prost(string, optional, tag = "2")]
503+
pub preimage: ::core::option::Option<::prost::alloc::string::String>,
504+
}
505+
/// Limits applying to how much fee we allow an LSP to deduct from the payment amount.
506+
/// See \[`LdkChannelConfig::accept_underpaying_htlcs`\] for more information.
507+
///
508+
/// \[`LdkChannelConfig::accept_underpaying_htlcs`\]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
509+
#[allow(clippy::derive_partial_eq_without_eq)]
510+
#[derive(Clone, PartialEq, ::prost::Message)]
511+
pub struct LspFeeLimits {
512+
/// The maximal total amount we allow any configured LSP withhold from us when forwarding the
513+
/// payment.
514+
#[prost(uint64, optional, tag = "1")]
515+
pub max_total_opening_fee_msat: ::core::option::Option<u64>,
516+
/// The maximal proportional fee, in parts-per-million millisatoshi, we allow any configured
517+
/// LSP withhold from us when forwarding the payment.
518+
#[prost(uint64, optional, tag = "2")]
519+
pub max_proportional_opening_fee_ppm_msat: ::core::option::Option<u64>,
520+
}
325521
#[allow(clippy::derive_partial_eq_without_eq)]
326522
#[derive(Clone, PartialEq, ::prost::Message)]
327523
pub struct Channel {
@@ -473,3 +669,65 @@ pub struct BestBlock {
473669
#[prost(uint32, tag = "2")]
474670
pub height: u32,
475671
}
672+
/// Represents the direction of a payment.
673+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
674+
#[repr(i32)]
675+
pub enum PaymentDirection {
676+
/// The payment is inbound.
677+
Inbound = 0,
678+
/// The payment is outbound.
679+
Outbound = 1,
680+
}
681+
impl PaymentDirection {
682+
/// String value of the enum field names used in the ProtoBuf definition.
683+
///
684+
/// The values are not transformed in any way and thus are considered stable
685+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
686+
pub fn as_str_name(&self) -> &'static str {
687+
match self {
688+
PaymentDirection::Inbound => "INBOUND",
689+
PaymentDirection::Outbound => "OUTBOUND",
690+
}
691+
}
692+
/// Creates an enum from field names used in the ProtoBuf definition.
693+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
694+
match value {
695+
"INBOUND" => Some(Self::Inbound),
696+
"OUTBOUND" => Some(Self::Outbound),
697+
_ => None,
698+
}
699+
}
700+
}
701+
/// Represents the current status of a payment.
702+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
703+
#[repr(i32)]
704+
pub enum PaymentStatus {
705+
/// The payment is still pending.
706+
Pending = 0,
707+
/// The payment succeeded.
708+
Succeeded = 1,
709+
/// The payment failed.
710+
Failed = 2,
711+
}
712+
impl PaymentStatus {
713+
/// String value of the enum field names used in the ProtoBuf definition.
714+
///
715+
/// The values are not transformed in any way and thus are considered stable
716+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
717+
pub fn as_str_name(&self) -> &'static str {
718+
match self {
719+
PaymentStatus::Pending => "PENDING",
720+
PaymentStatus::Succeeded => "SUCCEEDED",
721+
PaymentStatus::Failed => "FAILED",
722+
}
723+
}
724+
/// Creates an enum from field names used in the ProtoBuf definition.
725+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
726+
match value {
727+
"PENDING" => Some(Self::Pending),
728+
"SUCCEEDED" => Some(Self::Succeeded),
729+
"FAILED" => Some(Self::Failed),
730+
_ => None,
731+
}
732+
}
733+
}

0 commit comments

Comments
 (0)