Skip to content

Commit e63d1ae

Browse files
committed
Add Impl for Bolt12Send Api
1 parent ac90b8f commit e63d1ae

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

server/src/api/bolt12_send.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use bytes::Bytes;
2+
use ldk_node::lightning::offers::offer::Offer;
3+
use ldk_node::Node;
4+
use protos::{Bolt12SendRequest, Bolt12SendResponse};
5+
use std::str::FromStr;
6+
use std::sync::Arc;
7+
8+
pub(crate) const BOLT12_SEND_PATH: &str = "Bolt12Send";
9+
10+
pub(crate) fn handle_bolt12_send_request(
11+
node: Arc<Node>, request: Bolt12SendRequest,
12+
) -> Result<Bolt12SendResponse, ldk_node::NodeError> {
13+
let offer =
14+
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;
15+
16+
let payment_id = match request.amount_msat {
17+
None => node.bolt12_payment().send(&offer, request.payer_note),
18+
Some(amount_msat) => {
19+
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
20+
},
21+
}?;
22+
23+
let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
24+
Ok(response)
25+
}

server/src/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub(crate) mod bolt11_receive;
22
pub(crate) mod bolt11_send;
33
pub(crate) mod bolt12_receive;
4+
pub(crate) mod bolt12_send;
45
pub(crate) mod onchain_receive;
56
pub(crate) mod onchain_send;
67
pub(crate) mod open_channel;

server/src/service.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use crate::api::bolt11_send::handle_bolt11_send_request;
2323
use crate::api::bolt11_send::BOLT11_SEND_PATH;
2424
use crate::api::bolt12_receive::handle_bolt12_receive_request;
2525
use crate::api::bolt12_receive::BOLT12_RECEIVE_PATH;
26+
use crate::api::bolt12_send::handle_bolt12_send_request;
27+
use crate::api::bolt12_send::BOLT12_SEND_PATH;
2628

2729
#[derive(Clone)]
2830
pub struct NodeService {
@@ -54,6 +56,7 @@ impl Service<Request<Incoming>> for NodeService {
5456
BOLT12_RECEIVE_PATH => {
5557
Box::pin(handle_request(node, req, handle_bolt12_receive_request))
5658
},
59+
BOLT12_SEND_PATH => Box::pin(handle_request(node, req, handle_bolt12_send_request)),
5760
OPEN_CHANNEL_PATH => Box::pin(handle_request(node, req, handle_open_channel)),
5861
path => {
5962
let error = format!("Unknown request: {}", path).into_bytes();

0 commit comments

Comments
 (0)