+/// Returns the witness required to satisfy and spend a HTLC input.
+pub fn build_htlc_input_witness(
+ local_sig: &Signature, remote_sig: &Signature, preimage: &Option<PaymentPreimage>,
+ redeem_script: &Script, opt_anchors: bool,
+) -> Witness {
+ let remote_sighash_type = if opt_anchors {
+ EcdsaSighashType::SinglePlusAnyoneCanPay
+ } else {
+ EcdsaSighashType::All
+ };
+ let mut remote_sig = remote_sig.serialize_der().to_vec();
+ remote_sig.push(remote_sighash_type as u8);
+
+ let mut local_sig = local_sig.serialize_der().to_vec();
+ local_sig.push(EcdsaSighashType::All as u8);
+
+ let mut witness = Witness::new();
+ // First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
+ witness.push(vec![]);
+ witness.push(remote_sig);
+ witness.push(local_sig);
+ if let Some(preimage) = preimage {
+ witness.push(preimage.0.to_vec());
+ } else {
+ // Due to BIP146 (MINIMALIF) this must be a zero-length element to relay.
+ witness.push(vec![]);