How to get an outpoint in a transaction?
I'm trying to parse the structure of an unprocessed transaction.
-snip-
Help me figure it out.
Can you give an example of generating this hash?
Here's an example then:
Let's say you want to spend the first output of this transaction:
blockstream.info/tx/4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306The short version is, that's the TXID that should be used in your transaction input's outpoint.
The long version is, you can get that by hashing (
SHA256D) the to-be-spent RAW transaction;
for SegWit, witness data should be omitted first.
getrawtransaction 4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306:
02000000
↓----Witness----↓
0001
↑----Witness----↑
01
edbc78c31ef4beb3f99727513772c95438ab938d0e9e012fb63c21d971d59eed
16000000
17
160014bfe3f2baee0e4e0acb9a09564d85f95f64a08644
fdffffff
02
a086010000000000
22
5120c7da8b195d9e93cb321000adfd2c56ffe30969780cf4e09b782966e38d76761d
70e1080000000000
16
0014eee8c12b1093ef4780509809116f931b1fc6ea5a
↓----Witness----↓
02473044022002a98b8b8745339ddeb3d485e240035ab4e42e5836ea3cbe6b324a13cd8b8334022062e8e047e1dcb4a7d9f826ca8194be66a116108021fe7e7139fec22ef5f677b6012102dcfa3aff14e12c8eb96f3cf03880aca6ba451798533f58bd30de8eac93fc047c
↑----Witness----↑
dc8b0b00
Without the witnesses, you'll be left with:
0200000001edbc78c31ef4beb3f99727513772c95438ab938d0e9e012fb63c21d971d59eed1600000017160014bfe3f2baee0e4e0acb9a09564d85f95f64a08644fdffffff02a086010000000000225120c7da8b195d9e93cb321000adfd2c56ffe30969780cf4e09b782966e38d76761d70e1080000000000160014eee8c12b1093ef4780509809116f931b1fc6ea5adc8b0b00
SHA256: 19911b5338814ae41175533e224bfdadbe1319f78c194659baaa4ac80fbb9f91
SHA256: 06434a888fda769b0255deb79bc447555c60c28bfdbadfb9e6043b397e2eca4a
Reverse byte order:
4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306A few references:
This is understandable, but how to get this hash from json?
ed9ed571d9213cb62f019e0e8d93ab3854c97237512797f9b3bef41ec378bced
{
"hash": "4aca2e7e393b04e6b9dfbafd8bc2605c5547c49bb7de55029b76da8f884a4306",
"ver": 2,
"vin_sz": 1,
"vout_sz": 2,
"size": 257,
"weight": 701,
"fee": 500,
"relayed_by": "0.0.0.0",
"lock_time": 756700,
"tx_index": 220354657254222,
"double_spend": false,
"time": 1664710026,
"block_index": 756701,
"block_height": 756701,
"inputs": [
{
"sequence": 4294967293,
"witness": "02473044022002a98b8b8745339ddeb3d485e240035ab4e42e5836ea3cbe6b324a13cd8b8334022062e8e047e1dcb4a7d9f826ca8194be66a116108021fe7e7139fec22ef5f677b6012102dcfa3aff14e12c8eb96f3cf03880aca6ba451798533f58bd30de8eac93fc047c",
"script": "160014bfe3f2baee0e4e0acb9a09564d85f95f64a08644",
"index": 0,
"prev_out": {
"tx_index": 8364599542013591,
"value": 682500,
"n": 22,
"type": 0,
"spent": true,
"script": "a91453f6e374ee53ef349d5293c49547438bb55f8b7a87",
"spending_outpoints": [
{
"tx_index": 220354657254222,
"n": 0
}
],
"addr": "39Lymaa222Ryp9DMdDcRviYcBijTJS2e5j"
}
}
],
"out": [
{
"type": 0,
"spent": true,
"value": 100000,
"spending_outpoints": [
{
"tx_index": 6930009354916659,
"n": 0
}
],
"n": 0,
"tx_index": 220354657254222,
"script": "5120c7da8b195d9e93cb321000adfd2c56ffe30969780cf4e09b782966e38d76761d",
"addr": "bc1pcldgkx2an6fukvssqzkl6tzkll3sj6tcpn6wpxmc99nw8rtkwcws04nvas"
},
{
"type": 0,
"spent": true,
"value": 582000,
"spending_outpoints": [
{
"tx_index": 3451925364636683,
"n": 41
}
],
"n": 1,
"tx_index": 220354657254222,
"script": "0014eee8c12b1093ef4780509809116f931b1fc6ea5a",
"addr": "bc1qam5vz2csj0h50qzsnqy3zmunrv0ud6j6m9szd7"
}
]
}