Rationale
The CLI can provide you with everything about transactions and blocks that you need to reconstruct the block structure and raw block itself except for the witness commitment nonce which is stored in the scriptWitness of the coinbase and is not printed. You could manually parse the raw "hex" fields for transactions if you really wanted to, but this seems to defeat the point of having a JSONification of the raw block/transaction data.
Without the nonce you can't:
- calculate and validate the witness commitment yourself, you can generate the witness tx merkle root but you don't have the nonce to combine it with
- reconstruct the raw block form because you don't have
scriptWitnessstack associated with the coinbase (although you know how big it will be and can guess the common case of[0x000...000])
I'm building some archiving tooling for block data and being able to do a validated two-way conversion is very helpful.
What
This PR simply makes the txinwitness field not dependent on whether we are working with the coinbase or not. So you get it for the coinbase as well as the rest.
Examples
Common case of a [0x000...000] nonce: 00000000000000000000140a7289f3aada855dfd23b0bb13bb5502b0ca60cdd7
"vin": [
{
"coinbase": "0368890904c1fe8d5e2f706f6f6c696e2e636f6d2ffabe6d6d5565843a681160cf7b08b1b74ac90a719e6d6ab28c16d336b924f0dc2fcabdc6010000000000000051bf2ad74af345dbe642154b2658931612a70d195e007add0100ffffffff",
"txinwitness": [
"0000000000000000000000000000000000000000000000000000000000000000"
],
"sequence": 4294967295
}
],
...
Novel nonce value: 000000000000000000008c31945b2012258366cc600a3e9a3ee0598e8f797731
"vin": [
{
"coinbase": "031862082cfabe6d6d80c099b5e21f4c186d54eb292e17026932e52b1b807fa1380574c5adc1c843450200000000000000",
"txinwitness": [
"5b5032506f6f6c5d5b5032506f6f6c5d5b5032506f6f6c5d5b5032506f6f6c5d"
],
"sequence": 4294967295
}
],
...
Alternatives
This field could be renamed for the coinbase, "witnessnonce" perhaps. It could also be omitted when null/zero (0x000...000).
Tests
This didn't break any tests and I couldn't find an obvious way to include a test for this. If this is desired I'd apreicate some pointers.