Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions e2e-tests/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ use e2e_tests::{
find_available_port, mine_and_sync, run_cli, run_cli_raw, setup_funded_channel,
wait_for_onchain_balance, LdkServerHandle, RabbitMqEventConsumer, TestBitcoind,
};
use hex_conservative::DisplayHex;
use hex_conservative::{DisplayHex, FromHex};
use ldk_node::bitcoin::hashes::{sha256, Hash};
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::lightning::offers::offer::Offer;
use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_server_client::ldk_server_protos::api::{
Bolt11ReceiveRequest, Bolt12ReceiveRequest, OnchainReceiveRequest,
};
Expand Down Expand Up @@ -136,8 +138,14 @@ async fn test_cli_bolt11_receive() {
let server = LdkServerHandle::start(&bitcoind).await;

let output = run_cli(&server, &["bolt11-receive", "50000sat", "-d", "test"]);
let invoice = output["invoice"].as_str().unwrap();
assert!(invoice.starts_with("lnbcrt"), "Expected lnbcrt prefix, got: {}", invoice);
let invoice_str = output["invoice"].as_str().unwrap();
assert!(invoice_str.starts_with("lnbcrt"), "Expected lnbcrt prefix, got: {}", invoice_str);

let invoice: Bolt11Invoice = invoice_str.parse().unwrap();
let payment_hash = sha256::Hash::from_str(output["payment_hash"].as_str().unwrap()).unwrap();
assert_eq!(*invoice.payment_hash(), payment_hash);
let payment_secret = <[u8; 32]>::from_hex(output["payment_secret"].as_str().unwrap()).unwrap();
assert_eq!(invoice.payment_secret().0, payment_secret);
}

#[tokio::test]
Expand All @@ -149,8 +157,12 @@ async fn test_cli_bolt12_receive() {
setup_funded_channel(&bitcoind, &server_a, &server_b, 100_000).await;

let output = run_cli(&server_a, &["bolt12-receive", "test offer"]);
let offer = output["offer"].as_str().unwrap();
assert!(offer.starts_with("lno"), "Expected lno prefix, got: {}", offer);
let offer_str = output["offer"].as_str().unwrap();
assert!(offer_str.starts_with("lno"), "Expected lno prefix, got: {}", offer_str);

let offer: Offer = offer_str.parse().unwrap();
let offer_id = <[u8; 32]>::from_hex(output["offer_id"].as_str().unwrap()).unwrap();
assert_eq!(offer.id().0, offer_id);
}

#[tokio::test]
Expand Down
9 changes: 9 additions & 0 deletions ldk-server-protos/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ pub struct Bolt11ReceiveResponse {
/// to the recipient.
#[prost(string, tag = "1")]
pub invoice: ::prost::alloc::string::String,
/// The hex-encoded 32-byte payment hash.
#[prost(string, tag = "2")]
pub payment_hash: ::prost::alloc::string::String,
/// The hex-encoded 32-byte payment secret.
#[prost(string, tag = "3")]
pub payment_secret: ::prost::alloc::string::String,
}
/// Return a BOLT11 payable invoice for a given payment hash.
/// The inbound payment will NOT be automatically claimed upon arrival.
Expand Down Expand Up @@ -389,6 +395,9 @@ pub struct Bolt12ReceiveResponse {
/// to the recipient.
#[prost(string, tag = "1")]
pub offer: ::prost::alloc::string::String,
/// The hex-encoded offer id.
#[prost(string, tag = "2")]
pub offer_id: ::prost::alloc::string::String,
}
/// Send a payment for a BOLT12 offer.
/// See more:
Expand Down
9 changes: 9 additions & 0 deletions ldk-server-protos/src/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ message Bolt11ReceiveResponse {
// With the details of the invoice, the sender has all the data necessary to send a payment
// to the recipient.
string invoice = 1;

// The hex-encoded 32-byte payment hash.
string payment_hash = 2;

// The hex-encoded 32-byte payment secret.
string payment_secret = 3;
}

// Return a BOLT11 payable invoice for a given payment hash.
Expand Down Expand Up @@ -322,6 +328,9 @@ message Bolt12ReceiveResponse {
// With the details of the offer, the sender has all the data necessary to send a payment
// to the recipient.
string offer = 1;

// The hex-encoded offer id.
string offer_id = 2;
}

// Send a payment for a BOLT12 offer.
Expand Down
6 changes: 5 additions & 1 deletion ldk-server/src/api/bolt11_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use hex::DisplayHex;
use ldk_server_protos::api::{Bolt11ReceiveRequest, Bolt11ReceiveResponse};

use crate::api::error::LdkServerError;
Expand All @@ -27,6 +28,9 @@ pub(crate) fn handle_bolt11_receive_request(
.receive_variable_amount(&description, request.expiry_secs)?,
};

let response = Bolt11ReceiveResponse { invoice: invoice.to_string() };
let payment_hash = invoice.payment_hash().0.to_lower_hex_string();
let payment_secret = invoice.payment_secret().0.to_lower_hex_string();
let response =
Bolt11ReceiveResponse { invoice: invoice.to_string(), payment_hash, payment_secret };
Ok(response)
}
4 changes: 3 additions & 1 deletion ldk-server/src/api/bolt12_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use hex::DisplayHex;
use ldk_server_protos::api::{Bolt12ReceiveRequest, Bolt12ReceiveResponse};

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

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
let offer_id = offer.id().0.to_lower_hex_string();
let response = Bolt12ReceiveResponse { offer: offer.to_string(), offer_id };
Ok(response)
}
Loading