Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 303152c

Browse files
allow for optional chain parameters
1 parent f848b39 commit 303152c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/transport/message_handler.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ pub struct LiquidityManager<
142142
provider_config: Option<LiquidityProviderConfig>,
143143
channel_manager: Arc<ChannelManager<M, T, ES, NS, SP, F, R, L>>,
144144
chain_source: Option<C>,
145-
genesis_hash: BlockHash,
146-
best_block: RwLock<BestBlock>,
145+
genesis_hash: Option<BlockHash>,
146+
best_block: Option<RwLock<BestBlock>>,
147147
}
148148

149149
impl<
@@ -183,7 +183,7 @@ where
183183
pub fn new(
184184
entropy_source: ES, provider_config: Option<LiquidityProviderConfig>,
185185
channel_manager: Arc<ChannelManager<M, T, ES, NS, SP, F, R, L>>, chain_source: Option<C>,
186-
chain_params: ChainParameters,
186+
chain_params: Option<ChainParameters>,
187187
) -> Self
188188
where {
189189
let pending_messages = Arc::new(Mutex::new(vec![]));
@@ -229,8 +229,8 @@ where {
229229
provider_config,
230230
channel_manager,
231231
chain_source,
232-
genesis_hash: genesis_block(chain_params.network).header.block_hash(),
233-
best_block: RwLock::new(chain_params.best_block),
232+
genesis_hash: chain_params.map(|chain_params| genesis_block(chain_params.network).header.block_hash()),
233+
best_block: chain_params.map(|chain_params| RwLock::new(chain_params.best_block)),
234234
}
235235
}
236236

@@ -684,8 +684,8 @@ where
684684
&self, header: &bitcoin::BlockHeader, txdata: &chain::transaction::TransactionData,
685685
height: u32,
686686
) {
687-
{
688-
let best_block = self.best_block.read().unwrap();
687+
if let Some(best_block) = &self.best_block {
688+
let best_block = best_block.read().unwrap();
689689
assert_eq!(best_block.block_hash(), header.prev_blockhash,
690690
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
691691
assert_eq!(best_block.height(), height - 1,
@@ -698,8 +698,8 @@ where
698698

699699
fn block_disconnected(&self, header: &bitcoin::BlockHeader, height: u32) {
700700
let new_height = height - 1;
701-
{
702-
let mut best_block = self.best_block.write().unwrap();
701+
if let Some(best_block) = &self.best_block {
702+
let mut best_block = best_block.write().unwrap();
703703
assert_eq!(best_block.block_hash(), header.block_hash(),
704704
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
705705
assert_eq!(best_block.height(), height,

0 commit comments

Comments
 (0)