Skip to content

Commit

Permalink
Return txid on sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
dleutenegger committed Oct 5, 2023
1 parent e1a06c3 commit 65388e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 13 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use bitcoin::Network;
use breez_sdk_core::{
parse, BreezEvent, BreezServices, EventListener, GreenlightCredentials, GreenlightNodeConfig,
InputType, ListPaymentsRequest, LnUrlWithdrawResult, NodeConfig, OpenChannelFeeRequest,
OpeningFeeParams, PaymentDetails, PaymentStatus, PaymentTypeFilter,
OpeningFeeParams, PaymentDetails, PaymentStatus, PaymentTypeFilter, SweepRequest,
};
use cipher::generic_array::typenum::U32;
use crow::{CountryCode, LanguageCode, OfferManager, TopupInfo, TopupStatus};
Expand Down Expand Up @@ -832,25 +832,27 @@ impl LightningNode {
.map_to_permanent_failure("Failed to persist payment info")
}

pub fn query_onchain_fee(&self) -> Result<u64> {
pub fn query_onchain_fee(&self) -> Result<u32> {
let recommended_fees = self
.rt
.handle()
.block_on(self.sdk.recommended_fees())
.map_to_runtime_error(NodeUnavailable, "Couldn't fetch recommended fees")?;

Ok(recommended_fees.half_hour_fee)
Ok(recommended_fees.half_hour_fee as u32)
}

// TODO return txid when exposed by breez sdk https://github.com/breez/breez-sdk/issues/476
pub fn sweep(&self, address: String, onchain_fee: u64) -> Result<String> {
self.rt
pub fn sweep(&self, address: String, onchain_fee: u32) -> Result<String> {
Ok(self
.rt
.handle()
.block_on(self.sdk.sweep(address, onchain_fee))
.map_to_runtime_error(NodeUnavailable, "Failed to drain funds")?;

let txid: Vec<u8> = vec![0; 64];
Ok(txid.to_hex())
.block_on(self.sdk.sweep(SweepRequest {
to_address: address,
fee_rate_sats_per_vbyte: onchain_fee,
}))
.map_to_runtime_error(NodeUnavailable, "Failed to drain funds")?
.txid
.to_hex())
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/lipalightninglib.udl
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,14 @@ interface LightningNode {

// Query the current recommended onchain fee rate
[Throws=LnError]
u64 query_onchain_fee();
u32 query_onchain_fee();

// TODO: Currently doesn't return the correct txid until exposed by breez sdk https://github.com/breez/breez-sdk/issues/476
//
// Sweeps all available onchain funds on the specified onchain address.
// - address - the funds will be drained to this address
// - onchain_fee - the fees that should be applied for the transaction
// Returns the txid of the sweeping transaction.
[Throws=LnError]
string sweep(string address, u64 onchain_fee);
string sweep(string address, u32 onchain_fee);
};

// An object that holds all configuration needed to start a LightningNode instance.
Expand Down

0 comments on commit 65388e7

Please sign in to comment.