Skip to content

Commit 30a41dd

Browse files
author
Antoine Riard
committed
keysinterface: replace Result match with map_err
1 parent 953bbbe commit 30a41dd

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
@@ -609,10 +609,7 @@ impl BaseSign for InMemorySigner {
609609
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);
610610
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &keys);
611611
let htlc_sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, htlc.amount_msat / 1000, SigHashType::All)[..]);
612-
let holder_htlc_key = match chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key) {
613-
Ok(s) => s,
614-
Err(_) => return Err(()),
615-
};
612+
let holder_htlc_key = chan_utils::derive_private_key(&secp_ctx, &keys.per_commitment_point, &self.htlc_base_key).map_err(|_| ())?;
616613
htlc_sigs.push(secp_ctx.sign(&htlc_sighash, &holder_htlc_key));
617614
}
618615

@@ -641,20 +638,11 @@ impl BaseSign for InMemorySigner {
641638
}
642639

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

665653
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, ()> {
666-
let revocation_key = match chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key) {
667-
Ok(revocation_key) => revocation_key,
668-
Err(_) => return Err(())
669-
};
654+
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| ())?;
670655
let per_commitment_point = PublicKey::from_secret_key(secp_ctx, &per_commitment_key);
671-
let revocation_pubkey = match chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint) {
672-
Ok(revocation_pubkey) => revocation_pubkey,
673-
Err(_) => return Err(())
674-
};
656+
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| ())?;
675657
let witness_script = {
676-
let counterparty_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint) {
677-
Ok(counterparty_htlcpubkey) => counterparty_htlcpubkey,
678-
Err(_) => return Err(())
679-
};
680-
let holder_htlcpubkey = match chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint) {
681-
Ok(holder_htlcpubkey) => holder_htlcpubkey,
682-
Err(_) => return Err(())
683-
};
658+
let counterparty_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint).map_err(|_| ())?;
659+
let holder_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint).map_err(|_| ())?;
684660
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, &counterparty_htlcpubkey, &holder_htlcpubkey, &revocation_pubkey)
685661
};
686662
let mut sighash_parts = bip143::SigHashCache::new(justice_tx);

0 commit comments

Comments
 (0)