Skip to content

Commit 41eaa1b

Browse files
committed
Add Impl for Bolt11Send Api
1 parent 70fb33d commit 41eaa1b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

server/src/api/bolt11_send.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use bytes::Bytes;
2+
use ldk_node::lightning_invoice::Bolt11Invoice;
3+
use ldk_node::Node;
4+
use protos::{Bolt11SendRequest, Bolt11SendResponse};
5+
use std::str::FromStr;
6+
use std::sync::Arc;
7+
8+
pub(crate) const BOLT11_SEND_PATH: &str = "Bolt11Send";
9+
10+
pub(crate) fn handle_bolt11_send_request(
11+
node: Arc<Node>, request: Bolt11SendRequest,
12+
) -> Result<Bolt11SendResponse, ldk_node::NodeError> {
13+
let invoice = Bolt11Invoice::from_str(&request.invoice.as_str())
14+
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;
15+
16+
let payment_id = match request.amount_msat {
17+
None => node.bolt11_payment().send(&invoice),
18+
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
19+
}?;
20+
21+
let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
22+
Ok(response)
23+
}

server/src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub(crate) mod bolt11_receive;
2+
pub(crate) mod bolt11_send;
23
pub(crate) mod onchain_receive;
34
pub(crate) mod onchain_send;
45
pub(crate) mod open_channel;

server/src/service.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use crate::api::bolt11_receive::handle_bolt11_receive_request;
1919
use crate::api::bolt11_receive::BOLT11_RECEIVE_PATH;
2020
use crate::api::open_channel::handle_open_channel;
2121
use crate::api::open_channel::OPEN_CHANNEL_PATH;
22+
use crate::api::bolt11_send::handle_bolt11_send_request;
23+
use crate::api::bolt11_send::BOLT11_SEND_PATH;
2224

2325
#[derive(Clone)]
2426
pub struct NodeService {
@@ -46,6 +48,7 @@ impl Service<Request<Incoming>> for NodeService {
4648
BOLT11_RECEIVE_PATH => {
4749
Box::pin(handle_request(node, req, handle_bolt11_receive_request))
4850
},
51+
BOLT11_SEND_PATH => Box::pin(handle_request(node, req, handle_bolt11_send_request)),
4952
OPEN_CHANNEL_PATH => Box::pin(handle_request(node, req, handle_open_channel)),
5053
path => {
5154
let error = format!("Unknown request: {}", path).into_bytes();

0 commit comments

Comments
 (0)