I have been studying lots of docs on BTC transaction construction, and discover it actually complicated in the case of SegWit story.
So, the very very first thing is, if I’ve P2SH-P2WPKH tackle, does it imply that every one outputs to this tackle (UTXOs) are by definition segwit UTXOs ?
Within the docs (https://bitcoincore.org/en/segwit_wallet_dev/) it says:
Signature Era and Verification for P2SH-P2WPKH
For spending of non-segwit UTXO, the signature era algorithm is unchanged.
For spending of P2SH-P2WPKH:
- The scriptSig MUST ONLY include a push of the redeemScript
…
So, both all UTXOs for P2SH-P2WPKH tackle are segwit ones, or they’re SegWit if SegWit transaction was made to this tackle (which does little sense really for me, as then arises chicken-egg drawback).
Why they wrote this “For spending of non-segwit UTXO, the signature era algorithm is unchanged” half, what case it covers? In case you’ve P2SH-P2WPKH tackle however you take some overseas UTXOs to spend(that have been directed to not your tackle)?
One other not clear half are scripts for P2SH-P2WPKH tackle.
So right here is my instance tackle:
3MxYPuvEcKDdaEG1xoGyddqir6C4b66MJi
And right here is transaction that was made to it:
https://blockchain.information/rawtx/6c2806587d5cdb3f0363e43f60b4a84baf37b3012fbde02f108f4eb1bdcede42
Based mostly on it pubKeyScript of output is a914de523116b281c96ff1e204ea2ff435b75d48f0de87 which interprets to:
OP_HASH160 de523116b281c96ff1e204ea2ff435b75d48f0de OP_EQUAL
So, de523116b281c96ff1e204ea2ff435b75d48f0de is hash160 of redeem script.
The one redeem script that matches this hash I’ve discovered is following:
0 389f26d8d616cb96df1cfd6d9989248a30b933b9
Which is witness v0 program script(0 sha160sha256(pubkey), so it means I’ve to create SegWit transactions, proper?
I attempted making P2SH ones and it says that I’ve non-nominal pushes within the redeem script, that is reason for “0” push there I consider.
I really feel that doing one thing mistaken on this half, and consequently signing both mistaken factor or in a mistaken manner…
Very respect any explanations.