Skip to content

Commit 9990e51

Browse files
authored
Merge pull request #256 from tnull/2024-02-add-bolt12-support
2 parents 246775d + 82b85c1 commit 9990e51

File tree

12 files changed

+954
-119
lines changed

12 files changed

+954
-119
lines changed

bindings/ldk_node.udl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ interface Node {
5454
PublicKey node_id();
5555
sequence<SocketAddress>? listening_addresses();
5656
Bolt11Payment bolt11_payment();
57+
Bolt12Payment bolt12_payment();
5758
SpontaneousPayment spontaneous_payment();
5859
OnchainPayment onchain_payment();
5960
[Throws=NodeError]
@@ -99,6 +100,21 @@ interface Bolt11Payment {
99100
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]string description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
100101
};
101102

103+
interface Bolt12Payment {
104+
[Throws=NodeError]
105+
PaymentId send([ByRef]Offer offer, string? payer_note);
106+
[Throws=NodeError]
107+
PaymentId send_using_amount([ByRef]Offer offer, string? payer_note, u64 amount_msat);
108+
[Throws=NodeError]
109+
Offer receive(u64 amount_msat, [ByRef]string description);
110+
[Throws=NodeError]
111+
Offer receive_variable_amount([ByRef]string description);
112+
[Throws=NodeError]
113+
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
114+
[Throws=NodeError]
115+
Refund initiate_refund(u64 amount_msat, u32 expiry_secs);
116+
};
117+
102118
interface SpontaneousPayment {
103119
[Throws=NodeError]
104120
PaymentId send(u64 amount_msat, PublicKey node_id);
@@ -122,6 +138,9 @@ enum NodeError {
122138
"OnchainTxCreationFailed",
123139
"ConnectionFailed",
124140
"InvoiceCreationFailed",
141+
"InvoiceRequestCreationFailed",
142+
"OfferCreationFailed",
143+
"RefundCreationFailed",
125144
"PaymentSendingFailed",
126145
"ProbeSendingFailed",
127146
"ChannelCreationFailed",
@@ -139,15 +158,19 @@ enum NodeError {
139158
"InvalidSocketAddress",
140159
"InvalidPublicKey",
141160
"InvalidSecretKey",
161+
"InvalidOfferId",
142162
"InvalidPaymentId",
143163
"InvalidPaymentHash",
144164
"InvalidPaymentPreimage",
145165
"InvalidPaymentSecret",
146166
"InvalidAmount",
147167
"InvalidInvoice",
168+
"InvalidOffer",
169+
"InvalidRefund",
148170
"InvalidChannelId",
149171
"InvalidNetwork",
150172
"DuplicatePayment",
173+
"UnsupportedCurrency",
151174
"InsufficientFunds",
152175
"LiquiditySourceUnavailable",
153176
"LiquidityFeeTooHigh",
@@ -225,6 +248,8 @@ interface PaymentKind {
225248
Onchain();
226249
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret);
227250
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, LSPFeeLimits lsp_fee_limits);
251+
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id);
252+
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret);
228253
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);
229254
};
230255

@@ -371,6 +396,18 @@ typedef string Address;
371396
[Custom]
372397
typedef string Bolt11Invoice;
373398

399+
[Custom]
400+
typedef string Offer;
401+
402+
[Custom]
403+
typedef string Refund;
404+
405+
[Custom]
406+
typedef string Bolt12Invoice;
407+
408+
[Custom]
409+
typedef string OfferId;
410+
374411
[Custom]
375412
typedef string PaymentId;
376413

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ fn build_with_store_internal(
785785
Arc::clone(&logger),
786786
Arc::clone(&channel_manager),
787787
Arc::new(message_router),
788-
IgnoringMessageHandler {},
788+
Arc::clone(&channel_manager),
789789
IgnoringMessageHandler {},
790790
));
791791
let ephemeral_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();

src/error.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ pub enum Error {
1313
ConnectionFailed,
1414
/// Invoice creation failed.
1515
InvoiceCreationFailed,
16+
/// Invoice request creation failed.
17+
InvoiceRequestCreationFailed,
18+
/// Offer creation failed.
19+
OfferCreationFailed,
20+
/// Refund creation failed.
21+
RefundCreationFailed,
1622
/// Sending a payment has failed.
1723
PaymentSendingFailed,
1824
/// Sending a payment probe has failed.
@@ -47,6 +53,8 @@ pub enum Error {
4753
InvalidPublicKey,
4854
/// The given secret key is invalid.
4955
InvalidSecretKey,
56+
/// The given offer id is invalid.
57+
InvalidOfferId,
5058
/// The given payment id is invalid.
5159
InvalidPaymentId,
5260
/// The given payment hash is invalid.
@@ -59,12 +67,18 @@ pub enum Error {
5967
InvalidAmount,
6068
/// The given invoice is invalid.
6169
InvalidInvoice,
70+
/// The given offer is invalid.
71+
InvalidOffer,
72+
/// The given refund is invalid.
73+
InvalidRefund,
6274
/// The given channel ID is invalid.
6375
InvalidChannelId,
6476
/// The given network is invalid.
6577
InvalidNetwork,
6678
/// A payment with the given hash has already been initiated.
6779
DuplicatePayment,
80+
/// The provided offer was denonminated in an unsupported currency.
81+
UnsupportedCurrency,
6882
/// The available funds are insufficient to complete the given operation.
6983
InsufficientFunds,
7084
/// The given operation failed due to the required liquidity source being unavailable.
@@ -83,6 +97,9 @@ impl fmt::Display for Error {
8397
},
8498
Self::ConnectionFailed => write!(f, "Network connection closed."),
8599
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
100+
Self::InvoiceRequestCreationFailed => write!(f, "Failed to create invoice request."),
101+
Self::OfferCreationFailed => write!(f, "Failed to create offer."),
102+
Self::RefundCreationFailed => write!(f, "Failed to create refund."),
86103
Self::PaymentSendingFailed => write!(f, "Failed to send the given payment."),
87104
Self::ProbeSendingFailed => write!(f, "Failed to send the given payment probe."),
88105
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
@@ -102,12 +119,15 @@ impl fmt::Display for Error {
102119
Self::InvalidSocketAddress => write!(f, "The given network address is invalid."),
103120
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
104121
Self::InvalidSecretKey => write!(f, "The given secret key is invalid."),
122+
Self::InvalidOfferId => write!(f, "The given offer id is invalid."),
105123
Self::InvalidPaymentId => write!(f, "The given payment id is invalid."),
106124
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
107125
Self::InvalidPaymentPreimage => write!(f, "The given payment preimage is invalid."),
108126
Self::InvalidPaymentSecret => write!(f, "The given payment secret is invalid."),
109127
Self::InvalidAmount => write!(f, "The given amount is invalid."),
110128
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
129+
Self::InvalidOffer => write!(f, "The given offer is invalid."),
130+
Self::InvalidRefund => write!(f, "The given refund is invalid."),
111131
Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
112132
Self::InvalidNetwork => write!(f, "The given network is invalid."),
113133
Self::DuplicatePayment => {
@@ -116,6 +136,9 @@ impl fmt::Display for Error {
116136
Self::InsufficientFunds => {
117137
write!(f, "The available funds are insufficient to complete the given operation.")
118138
},
139+
Self::UnsupportedCurrency => {
140+
write!(f, "The provided offer was denonminated in an unsupported currency.")
141+
},
119142
Self::LiquiditySourceUnavailable => {
120143
write!(f, "The given operation failed due to the required liquidity source being unavailable.")
121144
},

0 commit comments

Comments
 (0)