Skip to content

Commit 1a5ce9e

Browse files
committed
Return offer id in Bolt12ReceiveResponse
Same motivation as the bolt11 change, allow us to track bolt 12 receives without having to decode the offer.
1 parent 6d50e31 commit 1a5ce9e

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

e2e-tests/tests/e2e.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use e2e_tests::{
1717
use hex_conservative::{DisplayHex, FromHex};
1818
use ldk_node::bitcoin::hashes::{sha256, Hash};
1919
use ldk_node::lightning::ln::msgs::SocketAddress;
20+
use ldk_node::lightning::offers::offer::Offer;
2021
use ldk_node::lightning_invoice::Bolt11Invoice;
2122
use ldk_server_client::ldk_server_protos::api::{
2223
Bolt11ReceiveRequest, Bolt12ReceiveRequest, OnchainReceiveRequest,
@@ -156,8 +157,12 @@ async fn test_cli_bolt12_receive() {
156157
setup_funded_channel(&bitcoind, &server_a, &server_b, 100_000).await;
157158

158159
let output = run_cli(&server_a, &["bolt12-receive", "test offer"]);
159-
let offer = output["offer"].as_str().unwrap();
160-
assert!(offer.starts_with("lno"), "Expected lno prefix, got: {}", offer);
160+
let offer_str = output["offer"].as_str().unwrap();
161+
assert!(offer_str.starts_with("lno"), "Expected lno prefix, got: {}", offer_str);
162+
163+
let offer: Offer = offer_str.parse().unwrap();
164+
let offer_id = <[u8; 32]>::from_hex(output["offer_id"].as_str().unwrap()).unwrap();
165+
assert_eq!(offer.id().0, offer_id);
161166
}
162167

163168
#[tokio::test]

ldk-server-protos/src/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ pub struct Bolt12ReceiveResponse {
395395
/// to the recipient.
396396
#[prost(string, tag = "1")]
397397
pub offer: ::prost::alloc::string::String,
398+
/// The hex-encoded offer id.
399+
#[prost(string, tag = "2")]
400+
pub offer_id: ::prost::alloc::string::String,
398401
}
399402
/// Send a payment for a BOLT12 offer.
400403
/// See more:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ message Bolt12ReceiveResponse {
328328
// With the details of the offer, the sender has all the data necessary to send a payment
329329
// to the recipient.
330330
string offer = 1;
331+
332+
// The hex-encoded offer id.
333+
string offer_id = 2;
331334
}
332335

333336
// Send a payment for a BOLT12 offer.

ldk-server/src/api/bolt12_receive.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10+
use hex::DisplayHex;
1011
use ldk_server_protos::api::{Bolt12ReceiveRequest, Bolt12ReceiveResponse};
1112

1213
use crate::api::error::LdkServerError;
@@ -28,6 +29,7 @@ pub(crate) fn handle_bolt12_receive_request(
2829
.receive_variable_amount(&request.description, request.expiry_secs)?,
2930
};
3031

31-
let response = Bolt12ReceiveResponse { offer: offer.to_string() };
32+
let offer_id = offer.id().0.to_lower_hex_string();
33+
let response = Bolt12ReceiveResponse { offer: offer.to_string(), offer_id };
3234
Ok(response)
3335
}

0 commit comments

Comments
 (0)