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

Do not let user try recovery if one block left #1144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions gui/src/app/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ impl State for Home {
if coin.block_height.is_some() {
self.balance += coin.amount;
let timelock = self.wallet.main_descriptor.first_timelock_value();
let seq =
remaining_sequence(&coin, cache.blockheight as u32, timelock);
let seq = remaining_sequence(
&coin,
cache.blockheight as u32,
timelock,
false,
);
// Warn user for coins that are expiring in less than 10 percent of
// the timelock.
if seq <= timelock as u32 * 10 / 100 {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/state/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ fn recovery_paths(wallet: &Wallet, coins: &[Coin], blockheight: i32) -> Vec<Reco
.iter()
.filter(|coin| {
coin.spend_info.is_none()
&& remaining_sequence(coin, blockheight as u32, sequence) <= 1
&& remaining_sequence(coin, blockheight as u32, sequence, true) <= 1
})
.fold(
(0, Amount::from_sat(0)),
Expand Down
4 changes: 2 additions & 2 deletions gui/src/app/state/spend/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ impl DefineSpend {
self.coins.sort_by(|(a, a_selected), (b, b_selected)| {
if *a_selected && !b_selected || !a_selected && *b_selected {
b_selected.cmp(a_selected)
} else if remaining_sequence(a, blockheight, timelock)
== remaining_sequence(b, blockheight, timelock)
} else if remaining_sequence(a, blockheight, timelock, false)
== remaining_sequence(b, blockheight, timelock, false)
{
// bigger amount first
b.amount.cmp(&a.amount)
Expand Down
3 changes: 2 additions & 1 deletion gui/src/app/view/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ fn coin_list_view<'a>(
} else if coin.block_height.is_none() {
badge::unconfirmed()
} else {
let seq = remaining_sequence(coin, blockheight, timelock);
let seq =
remaining_sequence(coin, blockheight, timelock, false);
coin_sequence_label(seq, timelock as u32)
})
.spacing(10)
Expand Down
14 changes: 9 additions & 5 deletions gui/src/app/view/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ pub fn recovery<'a>(
Container::new(
Column::new()
.spacing(20)
.push(text(format!(
"{} recovery paths will be available at the next block, select one:",
recovery_paths.len()
)))
.push(text(if recovery_paths.len() == 1 {
"1 recovery path is available, please select:".to_string()
} else {
format!(
"{} recovery paths are available, select one:",
recovery_paths.len()
)
}))
.push(Column::with_children(recovery_paths).spacing(20)),
)
.style(theme::Container::Card(theme::Card::Simple))
Expand Down Expand Up @@ -190,7 +194,7 @@ pub fn recovery_path_view<'a>(
.push(text(format!(
"{} coin{} totalling",
number_of_coins,
if number_of_coins > 0 { "s" } else { "" }
if number_of_coins > 1 { "s" } else { "" }
)))
.push(amount(&total_amount)),
)
Expand Down
2 changes: 1 addition & 1 deletion gui/src/app/view/spend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn coin_list_view<'a>(
} else if coin.block_height.is_none() {
badge::unconfirmed()
} else {
let seq = remaining_sequence(coin, blockheight, timelock);
let seq = remaining_sequence(coin, blockheight, timelock, false);
coins::coin_sequence_label(seq, timelock as u32)
})
.spacing(10)
Expand Down
6 changes: 5 additions & 1 deletion gui/src/daemon/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pub use liana::{

pub type Coin = ListCoinsEntry;

pub fn remaining_sequence(coin: &Coin, blockheight: u32, timelock: u16) -> u32 {
pub fn remaining_sequence(coin: &Coin, blockheight: u32, mut timelock: u16, recovery: bool) -> u32 {
// `createrecovery` command does not consider unconfirmed coins
if timelock == 1 && recovery {
timelock += 1;
}
if let Some(coin_blockheight) = coin.block_height {
if blockheight > coin_blockheight as u32 + timelock as u32 {
0
Expand Down
Loading