- let sighash = hash_to_message!(&bip143::SigHashCache::new(&spend_tx).signature_hash(input_idx, &witness_script, output.value, SigHashType::All)[..]);
- let sig = sign(secp_ctx, &sighash, &secret.private_key.key);
- spend_tx.input[input_idx].witness.push(sig.serialize_der().to_vec());
- spend_tx.input[input_idx].witness[0].push(SigHashType::All as u8);
- spend_tx.input[input_idx].witness.push(pubkey.key.serialize().to_vec());
+ let sighash = hash_to_message!(&sighash::SighashCache::new(&spend_tx).segwit_signature_hash(input_idx, &witness_script, output.value, EcdsaSighashType::All).unwrap()[..]);
+ let sig = sign(secp_ctx, &sighash, &secret.private_key);
+ let mut sig_ser = sig.serialize_der().to_vec();
+ sig_ser.push(EcdsaSighashType::All as u8);
+ spend_tx.input[input_idx].witness.push(sig_ser);
+ spend_tx.input[input_idx].witness.push(pubkey.inner.serialize().to_vec());