+ fn build_signed_closing_transaction(&self, tx: &mut Transaction, their_sig: &Signature, our_sig: &Signature) {
+ if tx.input.len() != 1 { panic!("Tried to sign closing transaction that had input count != 1!"); }
+ if tx.input[0].witness.len() != 0 { panic!("Tried to re-sign closing transaction"); }
+ if tx.output.len() > 2 { panic!("Tried to sign bogus closing transaction"); }
+
+ 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(self.get_funding_redeemscript().into_bytes());
+ }
+