Skip to content
Open
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
11 changes: 11 additions & 0 deletions ldk-server-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,12 @@ async fn main() {
);
},
Commands::OnchainSend { address, amount, send_all, fee_rate_sat_per_vb } => {
if let Some(rate) = fee_rate_sat_per_vb {
// Mirrors FeeRate::from_sat_per_vb: sat/vb * 1000/4 = sat/kwu
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get into that territory, let's just take a dependency on bitcoin and use bitcoin::FeeRate?

if rate.checked_mul(1000 / 4).is_none() {
handle_error_msg(&format!("Invalid fee rate: {} sat/vB", rate));
}
}
let amount_sats = amount.map(|a| a.to_sat().unwrap_or_else(|e| handle_error_msg(&e)));
handle_response_result::<_, OnchainSendResponse>(
client
Expand Down Expand Up @@ -774,6 +780,11 @@ async fn main() {
);
},
Commands::Bolt12Receive { description, amount, expiry_secs, quantity } => {
if quantity.is_some() && amount.is_none() {
handle_error_msg(
"quantity can only be set for fixed-amount offers (amount must be provided)",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debatable, @TheBlueMatt previously wanted to drop quantity from the LDK Node API (lightningdevkit/ldk-node#642, but was closed as abandoned). Matt, do you still think we should?

);
}
let amount_msat = amount.map(|a| a.to_msat());
handle_response_result::<_, Bolt12ReceiveResponse>(
client
Expand Down
30 changes: 18 additions & 12 deletions ldk-server/src/api/bolt12_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ use hex::DisplayHex;
use ldk_server_protos::api::{Bolt12ReceiveRequest, Bolt12ReceiveResponse};

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;

pub(crate) fn handle_bolt12_receive_request(
context: Context, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, LdkServerError> {
let offer = match request.amount_msat {
Some(amount_msat) => context.node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => context
.node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};
let offer =
match (request.amount_msat, request.quantity) {
(Some(amount_msat), quantity) => context.node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
quantity,
)?,
(None, Some(_)) => return Err(LdkServerError::new(
InvalidRequestError,
"quantity can only be set for fixed-amount offers (amount_msat must be provided)",
)),
(None, None) => context
.node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let offer_id = offer.id().0.to_lower_hex_string();
let response = Bolt12ReceiveResponse { offer: offer.to_string(), offer_id };
Expand Down
7 changes: 6 additions & 1 deletion ldk-server/src/api/onchain_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ pub(crate) fn handle_onchain_send_request(
)
})?;

let fee_rate = request.fee_rate_sat_per_vb.and_then(FeeRate::from_sat_per_vb);
let fee_rate = match request.fee_rate_sat_per_vb {
Some(rate) => Some(FeeRate::from_sat_per_vb(rate).ok_or_else(|| {
LdkServerError::new(InvalidRequestError, format!("Invalid fee rate: {} sat/vB", rate))
})?),
None => None,
};
let txid = match (request.amount_sats, request.send_all) {
(Some(amount_sats), None) => {
context.node.onchain_payment().send_to_address(&address, amount_sats, fee_rate)?
Expand Down