Skip to content

Commit 3cf40d7

Browse files
committed
feat: Expose latest_checkpoint in Wallet implementation
1 parent ed7064f commit 3cf40d7

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

bdk-ffi/src/types.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use crate::bitcoin::{Address, Amount, OutPoint, Script, Transaction, TxOut};
1+
use crate::bitcoin::{Address, Amount, BlockHash, OutPoint, Script, Transaction, TxOut};
22
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;
@@ -66,7 +67,7 @@ impl From<BdkChainPosition<BdkConfirmationBlockTime>> for ChainPosition {
6667
} => {
6768
let block_id = BlockId {
6869
height: anchor.block_id.height,
69-
hash: anchor.block_id.hash.to_string(),
70+
hash: Arc::new(BlockHash(anchor.block_id.hash)),
7071
};
7172
ChainPosition::Confirmed {
7273
confirmation_block_time: ConfirmationBlockTime {
@@ -98,7 +99,16 @@ pub struct BlockId {
9899
/// The height of the block.
99100
pub height: u32,
100101
/// The hash of the block.
101-
pub hash: String,
102+
pub hash: Arc<BlockHash>,
103+
}
104+
105+
impl From<BdkBlockId> for BlockId {
106+
fn from(block_id: BdkBlockId) -> Self {
107+
BlockId {
108+
height: block_id.height,
109+
hash: Arc::from(BlockHash(block_id.hash)),
110+
}
111+
}
102112
}
103113

104114
/// A transaction that is deemed to be part of the canonical history.

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)