Skip to content

Commit

Permalink
feat(testenv): add make_checkpoint_tip
Browse files Browse the repository at this point in the history
This creates a checkpoint linked list which contains all blocks.
  • Loading branch information
evanlinjin committed Apr 16, 2024
1 parent ee21ffe commit 1e99793
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions crates/testenv/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use bdk_chain::bitcoin::{
address::NetworkChecked, block::Header, hash_types::TxMerkleNode, hashes::Hash,
secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, CompactTarget,
ScriptBuf, ScriptHash, Transaction, TxIn, TxOut, Txid,
use bdk_chain::{
bitcoin::{
address::NetworkChecked, block::Header, hash_types::TxMerkleNode, hashes::Hash, secp256k1::rand::random, transaction, Address, Amount, Block, BlockHash, CompactTarget, ScriptBuf, ScriptHash, Transaction, TxIn, TxOut, Txid
},
local_chain::CheckPoint,
BlockId,
};
use bitcoincore_rpc::{
bitcoincore_rpc_json::{GetBlockTemplateModes, GetBlockTemplateRules},
Expand Down Expand Up @@ -234,6 +236,18 @@ impl TestEnv {
.send_to_address(address, amount, None, None, None, None, None, None)?;
Ok(txid)
}

/// Create a checkpoint linked list of all the blocks in the chain.
pub fn make_checkpoint_tip(&self) -> CheckPoint {
CheckPoint::from_block_ids((0_u32..).map_while(|height| {
self.bitcoind
.client
.get_block_hash(height as u64)
.ok()
.map(|hash| BlockId { height, hash })
}))
.expect("must craft tip")
}
}

#[cfg(test)]
Expand Down

0 comments on commit 1e99793

Please sign in to comment.