-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Add an option for building SegWit transactions.
Sources:
- Main article: "Segregated Witness Wallet Development Guide" https://bitcoincore.org/en/segwit_wallet_dev/
- SegWit info: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc#segregated-witness
- Tool for tx check: http://n.bitcoin.ninja/checktx?txid=d869f854e1f8788bcff294cc83b280942a8c728de71eb709a2c29d10bfe21b7c
- Testnet SegNet: https://bitcoincore.org/en/2016/01/21/launch_segwit_testnet/
Details:
- SegWit outputs are constructed so that older systems that are not segwit-aware can still validate them. To an old wallet or node, a SegWit output looks like an output that anyone can spend.
- Newer wallets and mining nodes, however, see the Segregated Witness output and expect to find a valid witness for it in the transaction’s witness data.
- Pay-to-Witness-Public-Key-Hash (P2WPKH) https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc#pay-to-witness-public-key-hash-p2wpkh
Examples:
// P2PKH output script
DUP HASH160 ab68025513c3dbd2f7b92a94e0581f5d50f654e7 EQUALVERIFY CHECKSIG
// P2WPKH output script (includes: a witness version 0)
0 ab68025513c3dbd2f7b92a94e0581f5d50f654e7
// To spend the Segregated Witness output:
[...]
"vin" : [{
"txid": "0627052b6f28912f2703066a912ea577f2ce4da4caa5a5fbd8a57286c345c2f2",
"vout": 0,
"scriptSig": ""
}]
[...]
"witness": "<Bob’s witness data>"
[...]
- Pay-to-Witness-Script-Hash (P2WSH)
The second type of witness program corresponds to a Pay-to-Script-Hash (P2SH) script.
Examples:
// 1. P2SH
// Includes 20-byte RIPEMD160(SHA256(script)) hash:
HASH160 54c557e07dde5bb6cb791c7a540e0a4796f5e97e EQUAL
// P2SH output being spent:
"vout": 0,
"scriptSig": “<SigA> <SigB> <2 PubA PubB PubC PubD PubE 5 CHECKMULTISIG>”,
]
// 2. P2WSH output script
// Includes a witness version (0) and 32-byte SHA256 hash of the redeem script.
0 a9b7b38d972cabc7961dbfbcb841ad4508d133c47ba87457b4a0e8aae86dbb89
// P2WSH output being spent with separate witness data
"vout": 0,
"scriptSig": “”,
]
[...]
"witness": "<SigA> <SigB> <2 PubA PubB PubC PubD PubE 5 CHECKMULTISIG>"
- Wallet construction of P2WPKH
- It is extremely important to note that P2WPKH should only be created by the payee (recipient) and not converted by the sender from a known public key, P2PKH script, or address. Sender does not know if the recipient has SegWit support.
- P2WPKH outputs must be constructed from the hash of a compressed public key.
Transaction:
- If all txins in a transaction are not associated with any witness data, the transaction MUST be serialized in the original transaction format.
- Under segwit, each transaction will have 2 IDs.
Metadata
Metadata
Assignees
Labels
No labels