Skip to content

Commit ed9a8bf

Browse files
committed
feat: Expose latest_checkpoint in Wallet implementation
1 parent f0f2e7a commit ed9a8bf

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

bdk-ffi/src/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::error::{CreateTxError, RequestBuilderError};
33

44
use bdk_core::bitcoin::absolute::LockTime as BdkLockTime;
55
use bdk_core::spk_client::SyncItem;
6+
use bdk_core::BlockId as BdkBlockId;
67

78
use bdk_wallet::bitcoin::Transaction as BdkTransaction;
89
use bdk_wallet::chain::spk_client::FullScanRequest as BdkFullScanRequest;
@@ -101,6 +102,15 @@ pub struct BlockId {
101102
pub hash: String,
102103
}
103104

105+
impl From<BdkBlockId> for BlockId {
106+
fn from(block_id: BdkBlockId) -> Self {
107+
BlockId {
108+
height: block_id.height,
109+
hash: block_id.hash.to_string(),
110+
}
111+
}
112+
}
113+
104114
/// A transaction that is deemed to be part of the canonical history.
105115
#[derive(uniffi::Record)]
106116
pub struct CanonicalTx {

bdk-ffi/src/wallet.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use crate::error::{
66
};
77
use crate::store::Connection;
88
use crate::types::{
9-
AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput,
10-
Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, UnconfirmedTx, Update,
9+
AddressInfo, Balance, BlockId, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex,
10+
LocalOutput, Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, UnconfirmedTx,
11+
Update,
1112
};
1213

1314
use bdk_wallet::bitcoin::{Network, Txid};
@@ -416,6 +417,11 @@ impl Wallet {
416417
rusqlite_error: e.to_string(),
417418
})
418419
}
420+
421+
/// Returns the latest checkpoint.
422+
pub fn latest_checkpoint(&self) -> BlockId {
423+
self.get_wallet().latest_checkpoint().block_id().into()
424+
}
419425
}
420426

421427
impl Wallet {

bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveTransactionTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ class LiveTransactionTest {
4040
println("Is explicitly RBF: ${transaction.isExplicitlyRbf()}")
4141
println("Inputs: ${transaction.input()}")
4242
println("Outputs: ${transaction.output()}")
43+
44+
val blockId = wallet.latestCheckpoint().toString()
45+
println("Latest checkpoint: $blockId")
4346
}
4447
}

0 commit comments

Comments
 (0)