Skip to content

Commit

Permalink
Merge pull request #256 from tnull/2024-02-add-bolt12-support
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull authored May 31, 2024
2 parents 246775d + 82b85c1 commit 9990e51
Show file tree
Hide file tree
Showing 12 changed files with 954 additions and 119 deletions.
37 changes: 37 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface Node {
PublicKey node_id();
sequence<SocketAddress>? listening_addresses();
Bolt11Payment bolt11_payment();
Bolt12Payment bolt12_payment();
SpontaneousPayment spontaneous_payment();
OnchainPayment onchain_payment();
[Throws=NodeError]
Expand Down Expand Up @@ -99,6 +100,21 @@ interface Bolt11Payment {
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]string description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
};

interface Bolt12Payment {
[Throws=NodeError]
PaymentId send([ByRef]Offer offer, string? payer_note);
[Throws=NodeError]
PaymentId send_using_amount([ByRef]Offer offer, string? payer_note, u64 amount_msat);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description);
[Throws=NodeError]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs);
};

interface SpontaneousPayment {
[Throws=NodeError]
PaymentId send(u64 amount_msat, PublicKey node_id);
Expand All @@ -122,6 +138,9 @@ enum NodeError {
"OnchainTxCreationFailed",
"ConnectionFailed",
"InvoiceCreationFailed",
"InvoiceRequestCreationFailed",
"OfferCreationFailed",
"RefundCreationFailed",
"PaymentSendingFailed",
"ProbeSendingFailed",
"ChannelCreationFailed",
Expand All @@ -139,15 +158,19 @@ enum NodeError {
"InvalidSocketAddress",
"InvalidPublicKey",
"InvalidSecretKey",
"InvalidOfferId",
"InvalidPaymentId",
"InvalidPaymentHash",
"InvalidPaymentPreimage",
"InvalidPaymentSecret",
"InvalidAmount",
"InvalidInvoice",
"InvalidOffer",
"InvalidRefund",
"InvalidChannelId",
"InvalidNetwork",
"DuplicatePayment",
"UnsupportedCurrency",
"InsufficientFunds",
"LiquiditySourceUnavailable",
"LiquidityFeeTooHigh",
Expand Down Expand Up @@ -225,6 +248,8 @@ interface PaymentKind {
Onchain();
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id);
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret);
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);
};

Expand Down Expand Up @@ -371,6 +396,18 @@ typedef string Address;
[Custom]
typedef string Bolt11Invoice;

[Custom]
typedef string Offer;

[Custom]
typedef string Refund;

[Custom]
typedef string Bolt12Invoice;

[Custom]
typedef string OfferId;

[Custom]
typedef string PaymentId;

Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ fn build_with_store_internal(
Arc::clone(&logger),
Arc::clone(&channel_manager),
Arc::new(message_router),
IgnoringMessageHandler {},
Arc::clone(&channel_manager),
IgnoringMessageHandler {},
));
let ephemeral_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
Expand Down
23 changes: 23 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub enum Error {
ConnectionFailed,
/// Invoice creation failed.
InvoiceCreationFailed,
/// Invoice request creation failed.
InvoiceRequestCreationFailed,
/// Offer creation failed.
OfferCreationFailed,
/// Refund creation failed.
RefundCreationFailed,
/// Sending a payment has failed.
PaymentSendingFailed,
/// Sending a payment probe has failed.
Expand Down Expand Up @@ -47,6 +53,8 @@ pub enum Error {
InvalidPublicKey,
/// The given secret key is invalid.
InvalidSecretKey,
/// The given offer id is invalid.
InvalidOfferId,
/// The given payment id is invalid.
InvalidPaymentId,
/// The given payment hash is invalid.
Expand All @@ -59,12 +67,18 @@ pub enum Error {
InvalidAmount,
/// The given invoice is invalid.
InvalidInvoice,
/// The given offer is invalid.
InvalidOffer,
/// The given refund is invalid.
InvalidRefund,
/// The given channel ID is invalid.
InvalidChannelId,
/// The given network is invalid.
InvalidNetwork,
/// A payment with the given hash has already been initiated.
DuplicatePayment,
/// The provided offer was denonminated in an unsupported currency.
UnsupportedCurrency,
/// The available funds are insufficient to complete the given operation.
InsufficientFunds,
/// The given operation failed due to the required liquidity source being unavailable.
Expand All @@ -83,6 +97,9 @@ impl fmt::Display for Error {
},
Self::ConnectionFailed => write!(f, "Network connection closed."),
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
Self::InvoiceRequestCreationFailed => write!(f, "Failed to create invoice request."),
Self::OfferCreationFailed => write!(f, "Failed to create offer."),
Self::RefundCreationFailed => write!(f, "Failed to create refund."),
Self::PaymentSendingFailed => write!(f, "Failed to send the given payment."),
Self::ProbeSendingFailed => write!(f, "Failed to send the given payment probe."),
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
Expand All @@ -102,12 +119,15 @@ impl fmt::Display for Error {
Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
Self::InvalidOfferId => write!(f, "The given offer id is invalid."),
Self::InvalidPaymentId => write!(f, "The given payment id is invalid."),
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
Self::InvalidPaymentPreimage => write!(f, "The given payment preimage is invalid."),
Self::InvalidPaymentSecret => write!(f, "The given payment secret is invalid."),
Self::InvalidAmount => write!(f, "The given amount is invalid."),
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
Self::InvalidOffer => write!(f, "The given offer is invalid."),
Self::InvalidRefund => write!(f, "The given refund is invalid."),
Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
Self::InvalidNetwork => write!(f, "The given network is invalid."),
Self::DuplicatePayment => {
Expand All @@ -116,6 +136,9 @@ impl fmt::Display for Error {
Self::InsufficientFunds => {
write!(f, "The available funds are insufficient to complete the given operation.")
},
Self::UnsupportedCurrency => {
write!(f, "The provided offer was denonminated in an unsupported currency.")
},
Self::LiquiditySourceUnavailable => {
write!(f, "The given operation failed due to the required liquidity source being unavailable.")
},
Expand Down
Loading

0 comments on commit 9990e51

Please sign in to comment.