Skip to content

Commit 605d30e

Browse files
author
Antoine Riard
committed
Remove get_p2wpkh_redeemscript in favor of lib helper
1 parent 263d76e commit 605d30e

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use bitcoin::blockdata::script::{Script,Builder};
1414
use bitcoin::blockdata::opcodes;
1515
use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction, EcdsaSighashType};
1616
use bitcoin::util::sighash;
17+
use bitcoin::util::address::Payload;
1718

1819
use bitcoin::hashes::{Hash, HashEngine};
1920
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -25,11 +26,11 @@ use crate::ln::msgs::DecodeError;
2526
use crate::util::ser::{Readable, Writeable, Writer};
2627
use crate::util::{byte_utils, transaction_utils};
2728

28-
use bitcoin::hash_types::WPubkeyHash;
2929
use bitcoin::secp256k1::{SecretKey, PublicKey, Scalar};
3030
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature, Message};
3131
use bitcoin::secp256k1::Error as SecpError;
3232
use bitcoin::{PackedLockTime, secp256k1, Sequence, Witness};
33+
use bitcoin::PublicKey as BitcoinPublicKey;
3334

3435
use crate::io;
3536
use crate::prelude::*;
@@ -1279,7 +1280,7 @@ impl CommitmentTransaction {
12791280
let script = if opt_anchors {
12801281
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_v0_p2wsh()
12811282
} else {
1282-
get_p2wpkh_redeemscript(&countersignatory_pubkeys.payment_point)
1283+
Payload::p2wpkh(&BitcoinPublicKey::new(countersignatory_pubkeys.payment_point)).unwrap().script_pubkey()
12831284
};
12841285
txouts.push((
12851286
TxOut {
@@ -1585,25 +1586,21 @@ pub fn get_commitment_transaction_number_obscure_factor(
15851586
| ((res[31] as u64) << 0 * 8)
15861587
}
15871588

1588-
fn get_p2wpkh_redeemscript(key: &PublicKey) -> Script {
1589-
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
1590-
.push_slice(&WPubkeyHash::hash(&key.serialize())[..])
1591-
.into_script()
1592-
}
1593-
15941589
#[cfg(test)]
15951590
mod tests {
15961591
use super::CounterpartyCommitmentSecrets;
15971592
use crate::{hex, chain};
15981593
use crate::prelude::*;
1599-
use crate::ln::chan_utils::{get_htlc_redeemscript, get_to_countersignatory_with_anchors_redeemscript, get_p2wpkh_redeemscript, CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment};
1594+
use crate::ln::chan_utils::{get_htlc_redeemscript, get_to_countersignatory_with_anchors_redeemscript, CommitmentTransaction, TxCreationKeys, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, HTLCOutputInCommitment};
16001595
use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
16011596
use crate::util::test_utils;
16021597
use crate::chain::keysinterface::{KeysInterface, BaseSign};
16031598
use bitcoin::{Network, Txid};
16041599
use bitcoin::hashes::Hash;
16051600
use crate::ln::PaymentHash;
16061601
use bitcoin::hashes::hex::ToHex;
1602+
use bitcoin::util::address::Payload;
1603+
use bitcoin::PublicKey as BitcoinPublicKey;
16071604

16081605
#[test]
16091606
fn test_anchors() {
@@ -1642,7 +1639,7 @@ mod tests {
16421639
&mut htlcs_with_aux, &channel_parameters.as_holder_broadcastable()
16431640
);
16441641
assert_eq!(tx.built.transaction.output.len(), 2);
1645-
assert_eq!(tx.built.transaction.output[1].script_pubkey, get_p2wpkh_redeemscript(&counterparty_pubkeys.payment_point));
1642+
assert_eq!(tx.built.transaction.output[1].script_pubkey, Payload::p2wpkh(&BitcoinPublicKey::new(counterparty_pubkeys.payment_point)).unwrap().script_pubkey());
16461643

16471644
// Generate broadcaster and counterparty outputs as well as two anchors
16481645
let tx = CommitmentTransaction::new_with_auxiliary_htlc_data(

0 commit comments

Comments
 (0)