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

Commit 284f84b

Browse files
allow for optional chain parameters
1 parent f848b39 commit 284f84b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/transport/message_handler.rs

Lines changed: 10 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,9 @@ 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
233+
.map(|chain_params| genesis_block(chain_params.network).header.block_hash()),
234+
best_block: chain_params.map(|chain_params| RwLock::new(chain_params.best_block)),
234235
}
235236
}
236237

@@ -684,8 +685,8 @@ where
684685
&self, header: &bitcoin::BlockHeader, txdata: &chain::transaction::TransactionData,
685686
height: u32,
686687
) {
687-
{
688-
let best_block = self.best_block.read().unwrap();
688+
if let Some(best_block) = &self.best_block {
689+
let best_block = best_block.read().unwrap();
689690
assert_eq!(best_block.block_hash(), header.prev_blockhash,
690691
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
691692
assert_eq!(best_block.height(), height - 1,
@@ -698,8 +699,8 @@ where
698699

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

0 commit comments

Comments
 (0)