diff --git a/examples/3l-node/cli.rs b/examples/3l-node/cli.rs index 3cdbcd3c..7c7f64e1 100644 --- a/examples/3l-node/cli.rs +++ b/examples/3l-node/cli.rs @@ -1,10 +1,5 @@ use crate::hinter::{CommandHint, CommandHinter}; -use uniffi_lipalightninglib::{ - Amount, FiatValue, MaxRoutingFeeMode, OfferKind, PaymentState, TopupCurrency, -}; - -use bitcoin::hashes::hex::ToHex; use chrono::offset::FixedOffset; use chrono::{DateTime, Local, Utc}; use colored::Colorize; @@ -15,6 +10,9 @@ use rustyline::Editor; use std::collections::HashSet; use std::path::Path; use uniffi_lipalightninglib::LiquidityLimit; +use uniffi_lipalightninglib::{ + Amount, FiatValue, MaxRoutingFeeMode, OfferKind, PaymentState, TopupCurrency, +}; use crate::LightningNode; use crate::TzConfig; @@ -133,22 +131,22 @@ pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) { Ok(uuid) => println!("{uuid}"), Err(message) => eprintln!("{}", message.red()), }, - "drain" => { - let vec: Vec = vec![0; 64]; - println!("{}", vec.to_hex()); + "sweep" => { let address = words .next() .ok_or_else(|| "Address is required".to_string()); - if let Err(e) = address { - println!("{}", e.red()); - return; - } - let address = address.unwrap().to_string(); - match drain(node, address.clone()) { + let address = match address { + Ok(a) => a.to_string(), + Err(e) => { + println!("{}", e.red()); + return; + } + }; + match sweep(node, address.clone()) { Ok(txid) => { println!(); - println!("Transaction Id: {}", txid.to_hex()); + println!("Transaction Id: {}", txid); println!("Payout address: {}", address) } Err(e) => println!("{}", e.red()), @@ -227,7 +225,7 @@ fn setup_editor(history_path: &Path) -> Editor { "paymentuuid ", "paymentuuid", )); - hints.insert(CommandHint::new("drain
", "drain")); + hints.insert(CommandHint::new("sweep
", "sweep")); hints.insert(CommandHint::new("foreground", "foreground")); hints.insert(CommandHint::new("background", "background")); hints.insert(CommandHint::new("stop", "stop")); @@ -263,7 +261,7 @@ fn help() { println!(" listpayments"); println!(" paymentuuid "); println!(); - println!(" drain
"); + println!(" sweep
"); println!(); println!(" foreground"); println!(" background"); @@ -706,10 +704,10 @@ fn payment_uuid( }; } -fn drain(node: &LightningNode, address: String) -> Result, String> { +fn sweep(node: &LightningNode, address: String) -> Result { let fee_rate = node.query_onchain_fee().map_err(|e| e.to_string())?; - node.drain(address.to_string(), fee_rate) + node.sweep(address.to_string(), fee_rate) .map_err(|e| e.to_string()) } diff --git a/src/lib.rs b/src/lib.rs index 80244023..2a4c5336 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -843,13 +843,14 @@ impl LightningNode { } // TODO return txid when exposed by breez sdk https://github.com/breez/breez-sdk/issues/476 - pub fn drain(&self, address: String, onchain_fee: u64) -> Result> { + pub fn sweep(&self, address: String, onchain_fee: u64) -> Result { self.rt .handle() .block_on(self.sdk.sweep(address, onchain_fee)) .map_to_runtime_error(NodeUnavailable, "Failed to drain funds")?; - Ok(vec![0; 64]) + let txid: Vec = vec![0; 64]; + Ok(txid.to_hex()) } } diff --git a/src/lipalightninglib.udl b/src/lipalightninglib.udl index 67f66347..f69c078a 100644 --- a/src/lipalightninglib.udl +++ b/src/lipalightninglib.udl @@ -170,14 +170,12 @@ interface LightningNode { // TODO: Currently doesn't return the correct txid until exposed by breez sdk https://github.com/breez/breez-sdk/issues/476 // - // Drain all onchain funds to a specified address - // - // Drains all available onchain funds on the specified onchain address. + // 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 draining transaction. + // Returns the txid of the sweeping transaction. [Throws=LnError] - sequence drain(string address, u64 onchain_fee); + string sweep(string address, u64 onchain_fee); }; // An object that holds all configuration needed to start a LightningNode instance.