- fn sign_commitment_transaction(&self, tx: &mut Transaction, their_sig: &Signature) -> Signature {
- if tx.input.len() != 1 {
- panic!("Tried to sign commitment transaction that had input count != 1!");
- }
- if tx.input[0].witness.len() != 0 {
- panic!("Tried to re-sign commitment transaction");
- }
-
- let funding_redeemscript = self.get_funding_redeemscript();
-
- let sighash = hash_to_message!(&bip143::SighashComponents::new(&tx).sighash_all(&tx.input[0], &funding_redeemscript, self.channel_value_satoshis)[..]);
- let our_sig = self.secp_ctx.sign(&sighash, self.local_keys.funding_key());
-
- tx.input[0].witness.push(Vec::new()); // First is the multisig dummy
-
- let our_funding_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()).serialize();
- let their_funding_key = self.their_funding_pubkey.unwrap().serialize();
- if our_funding_key[..] < their_funding_key[..] {
- tx.input[0].witness.push(our_sig.serialize_der().to_vec());
- tx.input[0].witness.push(their_sig.serialize_der().to_vec());
- } else {
- tx.input[0].witness.push(their_sig.serialize_der().to_vec());
- tx.input[0].witness.push(our_sig.serialize_der().to_vec());
- }
- tx.input[0].witness[1].push(SigHashType::All as u8);
- tx.input[0].witness[2].push(SigHashType::All as u8);
-
- tx.input[0].witness.push(funding_redeemscript.into_bytes());
-
- our_sig
- }
-