Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor sweep command of CLI app #1308

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
41 changes: 20 additions & 21 deletions examples/node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,8 @@ pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) {
}
}
"sweep" => {
let address = words
.next()
.ok_or_else(|| "Address is required".to_string());

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}");
println!("Payout address: {address}")
}
Err(message) => println!("{}", format!("{message:#}").red()),
if let Err(message) = sweep(node, &mut words) {
println!("{}", format!("{message:#}").red());
}
}
"clearwalletinfo" => {
Expand Down Expand Up @@ -1451,10 +1435,25 @@ fn set_personal_note(node: &LightningNode, words: &mut dyn Iterator<Item = &str>
Ok(())
}

fn sweep(node: &LightningNode, address: String) -> Result<String> {
let address_data = get_bitcoin_address_data(node.util().decode_data(address)?)?;
fn sweep(node: &LightningNode, words: &mut dyn Iterator<Item = &str>) -> Result<()> {
let address = words.next().ok_or(anyhow!("Address is required"))?;
let address_data = node.util().decode_data(address.to_string())?;
let address_data = get_bitcoin_address_data(address_data)?;
let sweep_info = node.onchain().channel_close().prepare_sweep(address_data)?;
Ok(node.onchain().channel_close().sweep(sweep_info)?)
println!(" Payout address: {}", sweep_info.address);
println!(
" Amount: {}",
amount_to_string(&sweep_info.amount)
);
println!(
"On-chain fee amount: {}",
amount_to_string(&sweep_info.onchain_fee_amount)
);
println!(" On-chain fee rate: {}", sweep_info.onchain_fee_rate);

let txid = node.onchain().channel_close().sweep(sweep_info)?;
println!(" Transaction Id: {txid}");
Ok(())
}

fn clear_wallet_info(node: &LightningNode) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion mock/breez-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ impl BreezServices {
let prefix: Vec<u8> = (0..10).map(|_| rng.gen_range(b'a'..=b'z')).collect();
Some(format!(
"{}@wallet.lipa.swiss",
String::from_utf8(prefix.to_vec()).unwrap()
String::from_utf8(prefix).unwrap()
))
} else {
None
Expand Down
3 changes: 1 addition & 2 deletions src/actions_required.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ impl ActionsRequired {
self.support
.data_store
.lock_unwrap()
.store_hidden_channel_close_onchain_funds_amount_sat(onchain_balance_sat)?;
Ok(())
.store_hidden_channel_close_onchain_funds_amount_sat(onchain_balance_sat)
}

/// Hides the unresolved failed swap action required item in case the amount cannot be
Expand Down
Loading