Skip to content

Commit b5d81bf

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

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ use crate::error::{
55
LoadWithPersistError, SignerError, SqliteError, TxidParseError,
66
};
77
use crate::store::Connection;
8-
use crate::types::{
9-
AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput,
10-
Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, UnconfirmedTx, Update,
11-
};
8+
use crate::types::{AddressInfo, Balance, BlockId, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput, Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, UnconfirmedTx, Update};
129

1310
use bdk_wallet::bitcoin::{Network, Txid};
1411
use bdk_wallet::rusqlite::Connection as BdkConnection;
@@ -416,6 +413,11 @@ impl Wallet {
416413
rusqlite_error: e.to_string(),
417414
})
418415
}
416+
417+
/// Returns the latest checkpoint.
418+
pub fn latest_checkpoint(&self) -> BlockId {
419+
self.get_wallet().latest_checkpoint().block_id().into()
420+
}
419421
}
420422

421423
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)