Skip to content

Commit b8ee6bd

Browse files
committed
Make as_ecdsa return types optional.
1 parent e369bbf commit b8ee6bd

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,7 +2324,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
23242324
log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
23252325
log_bytes!(self.channel_id()), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
23262326

2327-
let counterparty_signature = self.holder_signer.as_ecdsa().sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
2327+
let counterparty_signature = self.holder_signer.as_ecdsa().unwrap().sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
23282328
.map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0;
23292329

23302330
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
@@ -3506,7 +3506,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
35063506
*self.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
35073507
}
35083508

3509-
self.holder_signer.as_ecdsa().validate_counterparty_revocation(
3509+
self.holder_signer.as_ecdsa().unwrap().validate_counterparty_revocation(
35103510
self.cur_counterparty_commitment_transaction_number + 1,
35113511
&secret
35123512
).map_err(|_| ChannelError::Close("Failed to validate revocation from peer".to_owned()))?;
@@ -4346,7 +4346,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
43464346
log_trace!(logger, "Proposing initial closing_signed for our counterparty with a fee range of {}-{} sat (with initial proposal {} sats)",
43474347
our_min_fee, our_max_fee, total_fee_satoshis);
43484348

4349-
let sig = self.holder_signer.as_ecdsa()
4349+
let sig = self.holder_signer.as_ecdsa().unwrap()
43504350
.sign_closing_transaction(&closing_tx, &self.secp_ctx)
43514351
.map_err(|()| ChannelError::Close("Failed to get signature for closing transaction.".to_owned()))?;
43524352

@@ -4556,7 +4556,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
45564556
self.build_closing_transaction($new_fee, false)
45574557
};
45584558

4559-
let sig = self.holder_signer.as_ecdsa()
4559+
let sig = self.holder_signer.as_ecdsa().unwrap()
45604560
.sign_closing_transaction(&closing_tx, &self.secp_ctx)
45614561
.map_err(|_| ChannelError::Close("External signer refused to sign closing transaction".to_owned()))?;
45624562

@@ -4929,7 +4929,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
49294929
#[cfg(test)]
49304930
pub fn get_signer(&self) -> &Signer {
49314931
// the Signer parameterization will only ever be used for the ECDSA signer
4932-
self.holder_signer.as_ecdsa()
4932+
self.holder_signer.as_ecdsa().unwrap()
49334933
}
49344934

49354935
#[cfg(test)]
@@ -5507,7 +5507,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
55075507
fn get_outbound_funding_created_signature<L: Deref>(&mut self, logger: &L) -> Result<Signature, ChannelError> where L::Target: Logger {
55085508
let counterparty_keys = self.build_remote_transaction_keys();
55095509
let counterparty_initial_commitment_tx = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
5510-
Ok(self.holder_signer.as_ecdsa().sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
5510+
Ok(self.holder_signer.as_ecdsa().unwrap().sign_counterparty_commitment(&counterparty_initial_commitment_tx, Vec::new(), &self.secp_ctx)
55115511
.map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0)
55125512
}
55135513

@@ -5641,7 +5641,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
56415641
},
56425642
Ok(v) => v
56435643
};
5644-
let our_bitcoin_sig = match self.holder_signer.as_ecdsa().sign_channel_announcement_with_funding_key(&announcement, &self.secp_ctx) {
5644+
let our_bitcoin_sig = match self.holder_signer.as_ecdsa().unwrap().sign_channel_announcement_with_funding_key(&announcement, &self.secp_ctx) {
56455645
Err(_) => {
56465646
log_error!(logger, "Signer rejected channel_announcement signing. Channel will not be announced!");
56475647
return None;
@@ -5670,7 +5670,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
56705670

56715671
let our_node_sig = node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelAnnouncement(&announcement))
56725672
.map_err(|_| ChannelError::Ignore("Failed to generate node signature for channel_announcement".to_owned()))?;
5673-
let our_bitcoin_sig = self.holder_signer.as_ecdsa().sign_channel_announcement_with_funding_key(&announcement, &self.secp_ctx)
5673+
let our_bitcoin_sig = self.holder_signer.as_ecdsa().unwrap().sign_channel_announcement_with_funding_key(&announcement, &self.secp_ctx)
56745674
.map_err(|_| ChannelError::Ignore("Signer rejected channel_announcement".to_owned()))?;
56755675
Ok(msgs::ChannelAnnouncement {
56765676
node_signature_1: if were_node_one { our_node_sig } else { their_node_sig },
@@ -6050,7 +6050,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
60506050
htlcs.push(htlc);
60516051
}
60526052

6053-
let res = self.holder_signer.as_ecdsa().sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.secp_ctx)
6053+
let res = self.holder_signer.as_ecdsa().unwrap().sign_counterparty_commitment(&commitment_stats.tx, commitment_stats.preimages, &self.secp_ctx)
60546054
.map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?;
60556055
signature = res.0;
60566056
htlc_signatures = res.1;
@@ -6362,7 +6362,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
63626362
self.latest_monitor_update_id.write(writer)?;
63636363

63646364
let mut key_data = VecWriter(Vec::new());
6365-
self.holder_signer.as_ecdsa().write(&mut key_data)?;
6365+
self.holder_signer.as_ecdsa().unwrap().write(&mut key_data)?;
63666366
assert!(key_data.0.len() < core::usize::MAX);
63676367
assert!(key_data.0.len() < core::u32::MAX as usize);
63686368
(key_data.0.len() as u32).write(writer)?;

lightning/src/sign/type_resolver.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ impl<ECS: EcdsaChannelSigner> ChannelSignerType<ECS> {
1818
}
1919
}
2020

21-
pub(crate) fn as_ecdsa(&self) -> &ECS {
21+
pub(crate) fn as_ecdsa(&self) -> Option<&ECS> {
2222
match self {
23-
ChannelSignerType::Ecdsa(ecs) => ecs
23+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
24+
#[cfg(taproot)]
25+
_ => None
2426
}
2527
}
2628

27-
pub(crate) fn as_mut_ecdsa(&mut self) -> &mut ECS {
29+
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> {
2830
match self {
29-
ChannelSignerType::Ecdsa(ecs) => ecs
31+
ChannelSignerType::Ecdsa(ecs) => Some(ecs),
32+
#[cfg(taproot)]
33+
_ => None
3034
}
3135
}
3236
}

0 commit comments

Comments
 (0)