Skip to content

Commit 677a60e

Browse files
committed
feat(kyoto): Add optional new wallet sync height
For users recovering an old wallet, it is best to used the pre-defined points like segwit or taproot; however, new users that have definitely not used their descriptor may be caught off guard if they have to wait for their wallet to sync for more than a couple seconds. This change allows for a recovery from any hash and height, with the idea being the developer can provide a recent block via a service like mempool(dot)space
1 parent 1ff5631 commit 677a60e

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

bdk-ffi/src/kyoto.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::bitcoin::BlockHash;
2727
use crate::bitcoin::Transaction;
2828
use crate::bitcoin::Wtxid;
2929
use crate::error::CbfError;
30+
use crate::types::BlockId;
3031
use crate::types::Update;
3132
use crate::wallet::Wallet;
3233
use crate::FeeRate;
@@ -185,7 +186,7 @@ impl CbfBuilder {
185186
trusted_peers.push(peer.clone().into());
186187
}
187188

188-
let scan_type = match self.scan_type {
189+
let scan_type = match self.scan_type.clone() {
189190
ScanType::Sync => bdk_kyoto::ScanType::Sync,
190191
ScanType::Recovery {
191192
used_script_index,
@@ -212,6 +213,10 @@ impl CbfBuilder {
212213
used_script_index,
213214
checkpoint: HeaderCheckpoint::taproot_activation(),
214215
},
216+
RecoveryPoint::Other { birthday } => bdk_kyoto::ScanType::Recovery {
217+
used_script_index,
218+
checkpoint: HeaderCheckpoint::new(birthday.height, birthday.hash.0),
219+
},
215220
}
216221
}
217222
}
@@ -457,7 +462,7 @@ impl From<Warn> for Warning {
457462

458463
/// Sync a wallet from the last known block hash or recover a wallet from a specified recovery
459464
/// point.
460-
#[derive(Debug, Clone, Copy, Default, uniffi::Enum)]
465+
#[derive(Debug, Clone, Default, uniffi::Enum)]
461466
pub enum ScanType {
462467
/// Sync an existing wallet from the last stored chain checkpoint.
463468
#[default]
@@ -472,12 +477,15 @@ pub enum ScanType {
472477
},
473478
}
474479

475-
#[derive(Debug, Clone, Copy, Default, uniffi::Enum)]
480+
#[derive(Debug, Clone, Default, uniffi::Enum)]
476481
pub enum RecoveryPoint {
477482
GenesisBlock,
478483
#[default]
479484
SegwitActivation,
480485
TaprootActivation,
486+
Other {
487+
birthday: BlockId,
488+
},
481489
}
482490

483491
/// A peer to connect to over the Bitcoin peer-to-peer network.

0 commit comments

Comments
 (0)