Skip to content

Commit 6319690

Browse files
author
Antoine Riard
committed
keysinterface: replace Result match with map_err
1 parent 55eccfa commit 6319690

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,7 @@ impl BaseSign for InMemorySigner {
608608
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_tx.feerate_per_kw(), self.holder_selected_contest_delay(), htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
609609
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys);
610610
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]);
611-
let holder_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
612-
Ok(s) => s,
613-
Err(_) => return Err(()),
614-
};
611+
let holder_htlc_key = chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key).map_err(|_| ())?;
615612
htlc_sigs.push(secp_ctx.sign(&htlc_sighash, &holder_htlc_key));
616613
}
617614

@@ -640,20 +637,11 @@ impl BaseSign for InMemorySigner {
640637
}
641638

642639
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
643-
let revocation_key = match chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key) {
644-
Ok(revocation_key) => revocation_key,
645-
Err(_) => return Err(())
646-
};
640+
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| ())?;
647641
let per_commitment_point = PublicKey::from_secret_key(secp_ctx, &per_commitment_key);
648-
let revocation_pubkey = match chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
649-
Ok(revocation_pubkey) => revocation_pubkey,
650-
Err(_) => return Err(())
651-
};
642+
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| ())?;
652643
let witness_script = {
653-
let counterparty_delayedpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().delayed_payment_basepoint) {
654-
Ok(counterparty_delayedpubkey) => counterparty_delayedpubkey,
655-
Err(_) => return Err(())
656-
};
644+
let counterparty_delayedpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().delayed_payment_basepoint).map_err(|_| ())?;
657645
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.holder_selected_contest_delay(), &counterparty_delayedpubkey)
658646
};
659647
let mut sighash_parts = bip143::SigHashCache::new(justice_tx);
@@ -662,24 +650,12 @@ impl BaseSign for InMemorySigner {
662650
}
663651

664652
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
665-
let revocation_key = match chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key) {
666-
Ok(revocation_key) => revocation_key,
667-
Err(_) => return Err(())
668-
};
653+
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| ())?;
669654
let per_commitment_point = PublicKey::from_secret_key(secp_ctx, &per_commitment_key);
670-
let revocation_pubkey = match chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
671-
Ok(revocation_pubkey) => revocation_pubkey,
672-
Err(_) => return Err(())
673-
};
655+
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| ())?;
674656
let witness_script = {
675-
let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) {
676-
Ok(counterparty_htlcpubkey) => counterparty_htlcpubkey,
677-
Err(_) => return Err(())
678-
};
679-
let holder_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
680-
Ok(holder_htlcpubkey) => holder_htlcpubkey,
681-
Err(_) => return Err(())
682-
};
657+
let counterparty_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint).map_err(|_| ())?;
658+
let holder_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint).map_err(|_| ())?;
683659
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &holder_htlcpubkey, &revocation_pubkey)
684660
};
685661
let mut sighash_parts = bip143::SigHashCache::new(justice_tx);

0 commit comments

Comments
 (0)