Skip to content

Commit 14c1478

Browse files
committed
Account for FeeRate in OnchainSend.
1 parent 5b97b26 commit 14c1478

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

ldk-server-cli/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ enum Commands {
3232
amount_sats: Option<u64>,
3333
#[arg(long)]
3434
send_all: Option<bool>,
35+
#[arg(long)]
36+
fee_rate_sat_per_vb: Option<u64>,
3537
},
3638
Bolt11Receive {
3739
#[arg(short, long)]
@@ -100,9 +102,16 @@ async fn main() {
100102
Commands::OnchainReceive => {
101103
handle_response_result(client.onchain_receive(OnchainReceiveRequest {}).await);
102104
},
103-
Commands::OnchainSend { address, amount_sats, send_all } => {
105+
Commands::OnchainSend { address, amount_sats, send_all, fee_rate_sat_per_vb } => {
104106
handle_response_result(
105-
client.onchain_send(OnchainSendRequest { address, amount_sats, send_all }).await,
107+
client
108+
.onchain_send(OnchainSendRequest {
109+
address,
110+
amount_sats,
111+
send_all,
112+
fee_rate_sat_per_vb,
113+
})
114+
.await,
106115
);
107116
},
108117
Commands::Bolt11Receive { description, description_hash, expiry_secs, amount_msat } => {

ldk-server-protos/src/api.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ pub struct OnchainSendRequest {
8383
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.send_all_to_address>
8484
#[prost(bool, optional, tag = "3")]
8585
pub send_all: ::core::option::Option<bool>,
86+
/// If `fee_rate_sat_per_vb` is set it will be used on the resulting transaction. Otherwise we'll retrieve
87+
/// a reasonable estimate from BitcoinD.
88+
#[prost(uint64, optional, tag = "4")]
89+
pub fee_rate_sat_per_vb: ::core::option::Option<u64>,
8690
}
8791
/// The response `content` for the `OnchainSend` API, when HttpStatusCode is OK (200).
8892
/// When HttpStatusCode is not OK (non-200), the response `content` contains a serialized `ErrorResponse`.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ message OnchainSendRequest {
8484
// the counterparty to spend the Anchor output after channel closure.
8585
// See more: https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.send_all_to_address
8686
optional bool send_all = 3;
87+
88+
// If `fee_rate_sat_per_vb` is set it will be used on the resulting transaction. Otherwise we'll retrieve
89+
// a reasonable estimate from BitcoinD.
90+
optional uint64 fee_rate_sat_per_vb = 4;
8791
}
8892

8993
// The response `content` for the `OnchainSend` API, when HttpStatusCode is OK (200).

ldk-server/src/api/onchain_send.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::service::Context;
2-
use ldk_node::bitcoin::Address;
2+
use ldk_node::bitcoin::{Address, FeeRate};
33
use ldk_server_protos::api::{OnchainSendRequest, OnchainSendResponse};
44
use std::str::FromStr;
55

@@ -12,13 +12,15 @@ pub(crate) fn handle_onchain_send_request(
1212
.map_err(|_| ldk_node::NodeError::InvalidAddress)?
1313
.require_network(context.node.config().network)
1414
.map_err(|_| ldk_node::NodeError::InvalidAddress)?;
15+
16+
let fee_rate = request.fee_rate_sat_per_vb.map(FeeRate::from_sat_per_vb).flatten();
1517
let txid = match (request.amount_sats, request.send_all) {
1618
(Some(amount_sats), None) => {
17-
context.node.onchain_payment().send_to_address(&address, amount_sats)?
19+
context.node.onchain_payment().send_to_address(&address, amount_sats, fee_rate)?
1820
},
1921
// Retain existing api behaviour to not retain reserves on `send_all_to_address`.
2022
(None, Some(true)) => {
21-
context.node.onchain_payment().send_all_to_address(&address, false)?
23+
context.node.onchain_payment().send_all_to_address(&address, false, fee_rate)?
2224
},
2325
_ => return Err(ldk_node::NodeError::InvalidAmount),
2426
};

0 commit comments

Comments
 (0)