Bitcoin
Separated Witness – Failed to sign Segwit transaction entry in bitcoinj.

I want to spend from a Segwit address and I have a P2WPH script. I created this transaction like I would create a regular P2PKH transaction, but changed the input address to a Segwit address. I don’t know if this is correct. I signed this transaction using the following method, but it says the script was not successfully verified…
Transaction signedtx = signInput(rawtx.getHashAsString(),privkey,rawtx);
public static Transaction signInput(String hash, String prvKey,Transaction spendTx)
ECKey ecKey = ECKey.fromPrivate(Utils.HEX.decode(prvKey));
ECKey.ECDSASignature signature = ecKey.sign(Sha256Hash.wrap(hash));
TransactionSignature transactionSignature = new TransactionSignature(signature,Transaction.SigHash.ALL,true);
TransactionWitness witness = TransactionWitness.redeemP2WPKH(transactionSignature,ecKey);
TransactionInput input = spendTx.getInput(0);
input.setWitness(witness);
return spendTx;
I don’t know much about bitcoinj and there is currently very little technical guidance regarding segwit. Hope someone can help me!