refactor: get first timelock from descriptor

This commit is contained in:
Michael Mallan 2025-04-16 09:57:46 +01:00
parent 0514f743da
commit 83c90b085a
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB
2 changed files with 12 additions and 15 deletions

View File

@ -27,13 +27,12 @@ pub struct CreateSpendPanel {
impl CreateSpendPanel {
pub fn new(wallet: Arc<Wallet>, coins: &[Coin], blockheight: u32, network: Network) -> Self {
let descriptor = wallet.main_descriptor.clone();
let timelock = descriptor.first_timelock_value();
Self {
draft: step::TransactionDraft::new(network),
current: 0,
steps: vec![
Box::new(
step::DefineSpend::new(network, descriptor, coins, timelock)
step::DefineSpend::new(network, descriptor, coins)
.with_coins_sorted(blockheight),
),
Box::new(step::SaveSpend::new(wallet)),
@ -49,13 +48,12 @@ impl CreateSpendPanel {
network: Network,
) -> Self {
let descriptor = wallet.main_descriptor.clone();
let timelock = descriptor.first_timelock_value();
Self {
draft: step::TransactionDraft::new(network),
current: 0,
steps: vec![
Box::new(
step::DefineSpend::new(network, descriptor, coins, timelock)
step::DefineSpend::new(network, descriptor, coins)
.with_preselected_coins(preselected_coins)
.with_coins_sorted(blockheight)
.self_send(),

View File

@ -105,7 +105,6 @@ pub struct DefineSpend {
network: Network,
descriptor: LianaDescriptor,
curve: secp256k1::Secp256k1<secp256k1::VerifyOnly>,
timelock: u16,
coins: Vec<(Coin, bool)>,
coins_labels: HashMap<String, String>,
batch_label: form::Value<String>,
@ -117,19 +116,13 @@ pub struct DefineSpend {
}
impl DefineSpend {
pub fn new(
network: Network,
descriptor: LianaDescriptor,
coins: &[Coin],
timelock: u16,
) -> Self {
pub fn new(network: Network, descriptor: LianaDescriptor, coins: &[Coin]) -> Self {
let coins = filter_coins(coins, None);
Self {
network,
descriptor,
curve: secp256k1::Secp256k1::verification_only(),
timelock,
generated: None,
coins,
coins_labels: HashMap::new(),
@ -159,7 +152,7 @@ impl DefineSpend {
}
fn sort_coins(&mut self, blockheight: u32) {
let timelock = self.timelock;
let timelock = self.timelock();
self.coins.sort_by(|(a, a_selected), (b, b_selected)| {
if *a_selected && !b_selected || !a_selected && *b_selected {
b_selected.cmp(a_selected)
@ -180,6 +173,13 @@ impl DefineSpend {
self
}
/// This is used for calculating a coin's remaining sequence.
///
/// It returns the descriptor's first timelock.
pub fn timelock(&self) -> u16 {
self.descriptor.first_timelock_value()
}
// If `is_redraft`, the validation of recipients will take into account
// whether any should receive the max amount. Otherwise, all recipients
// will be fully validated.
@ -433,7 +433,6 @@ impl Step for DefineSpend {
.map(|(c, _)| c.clone())
.collect::<Vec<ListCoinsEntry>>()
.as_slice(),
self.timelock,
);
return Task::none();
}
@ -647,7 +646,7 @@ impl Step for DefineSpend {
.collect(),
self.is_valid,
self.is_duplicate,
self.timelock,
self.timelock(),
&self.coins,
&self.coins_labels,
&self.batch_label,