I'm trying to extract the bech32 address associated to an input or output using the txinwitness
field included in every pure SegWit transaction.
An example with transaction 0x6b6167a3d35efb043639837bbac853903d2c800ba1e324be0fffb2858e251da0
would return this output:
$ bitcoin-cli decoderawtransaction "$TX_DATA"
[...]
"vin": [
{
"txid": "22b3f827d5574045f4b9b1dea448d66d92b2f334741687b8a3d778672530cfea",
"vout": 1,
"scriptSig": {
"asm": "",
"hex": ""
},
"txinwitness": [
"30450221008695b35cee8bd73fe870868b9f281ffd6f375b6082369310c910f35d524536fe022050c7c8442823af465acec6034283adb13b9481d57741a2be668d59322ea50b3701",
"02959a2410df7168279d9c8372bbd7b7e2d27959987dd3fae64b10e9c2d62b2e75"
],
"sequence": 4294967295
},
[...]
I'm using the API in Bitcoin Core 0.16 but I haven't find any way of querying the Segregated Witness tree with that txinwitness
data. The documentation or Google hits about this are almost non-existent, other than people commenting that sites like e.g. blockchain.info don't use Bitcoin Core and they have other ways of getting that information (because they show the bech32 address in the transaction info page).