I wrote the code for transmitting btc from p2sh-p2wpkh based on the information I found, but when I tried to broadcast the original transaction in https://live.blockcypher.com/btc-testnet/pushtx/, an exception occurred and the exception message was :
Error validating transaction: Error running script for input 0 referencing
f6ff7b391590c3c161f012e7313c9bd7379846a209219a4722cb8864190466ae at 0: Script was NOT verified successfully..
This is my broadcast data:
01000000000101ae6604196488cb22479a2109a2469837d79b3c31e712f061c1c39015397bfff600000000160014208a8852a3cec93382c8bebbbd6c9ef4676f5120ffffffff02a08601000000000017a9141f396a0c4994cae1820224bb249a21de3ad4e73287acfd13000000000017a91466e9ecd8e67b63a4022f0420f772a070fa7d6e608702483045022100f3e5b7483760ff764b5a7620ba341499ec41c5b2fd67917bfef233b547f6e5e7022071b3f96e9c1d271b723f161a7a0aeafddef16aeb053fe2b443c0e4d31a785a7a012103ca65ac405e0ea1b514c61b797035674a27457fea63a8972cd473eef05871247400000000
I have checked a lot of information, but I can't find the problem. I hope to get help!
The test method I executed: https://github.com/lingting/VirtualCurrency/blob/0.3.4/src/test/java/live/lingting/virtual/currency/omni/Transfer.java#L387
I signed the p2sh-p2wpkh address processing code: https://github.com/lingting/VirtualCurrency/blob/0.3.4/src/main/java/live/lingting/virtual/currency/service/impl/BtcOmniServiceImpl.java#L414
// Custom redemption script
Script redeemScript = new ScriptBuilder().smallNum(0).data(keys.get(0).getPubKeyHash()).build();
TransactionSignature signature;
signature = tx.calculateWitnessSignature(inputIndex, key, redeemScript, txIn.getValue(), SigHash.ALL,false);
txIn.setScriptSig(redeemScript);
// p2sh-p2wpkh 设置 witness
txIn.setWitness(TransactionWitness.redeemP2WPKH(signature, keys.get(0)));