Thank you for the pointers. I tried without success to make a proper SegWit Coinbase Transaction after researching and trying a lot... I read Bip 141 and other pages about SegWit transactions.
I am trying to mine a block with tNWRWWGvr8GGKXWXDYBPoyzmkVDt7a93fy as payout address. I modified the code and am now generating Coinbase Transactions like this one:
01000000 Version
0001 Marker and Flag
01 Input Count (and then the said input)
0000000000000000000000000000000000000000000000000000000000000000ffffffff10024133007269654d696e6572d74710b1ffffffff
02 Output Count (Reward Output + Dummy Segwit Output containing the GBT's default_witness_commitment)
00f2052a01000000 1976a914aaef3b4a202dd2632afa32dacc6018c7c00787dd88ac
0000000000000000 266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9
01 1 witness (1 stack item)
20 Witness Length (0x20 = 32 bytes, then Witness of the Coinbase Input)
0000000000000000000000000000000000000000000000000000000000000000
00000000 Lock Time
But the block is rejected with a bad-txnmrklroot error ("ERROR: ProcessNewBlock: AcceptBlock FAILED (hashMerkleRoot mismatch)" in the Debug.Log). For the Merkle Root, I tried to use sha256^2([nVersion][txins][txouts][nLockTime]) = txid instead of hashing the whole Coinbase Transaction like usual without success... Same using a 00...0 hash (they say that wtxid of Coinbase Transaction is this). Changing the version to 2 do not help either... Placing sha256^2(default_witness_commitment . 00...0) instead of just default_witness_commitment for "Commitment hash: Double-SHA256(witness root hash|witness reserved value)" is not working either.
Without the Marker and Flag and the Witness section, but with the default_witness_commitment (current implementation), the block is accepted but the payout address is not rewarded at all... However, if I use a regular "r" address, it is properly credited...
I compared to an
actual Segwit Coinbase Transaction and do not really know what I missed... The syntax seems correct, and this one just contains a third output...
02000000 Version
0001 Marker and Flag
01 Input Count (and then the said input)
0000000000000000000000000000000000000000000000000000000000000000ffffffff4b03f76e0804e64a085c622f4254432e434f4d2ffabe6d6d34709a7c9b51f6b39ffb6723b0ff703c0453910db7860b06de9d1ec1c2bc0a3601000000000000007034ae82d92b000000000000ffffffff
03 Output Count (Reward Output + Dummy Segwit Output containing the default_witness_commitment + a third output)
2acefb4a00000000 16001497cfc76442fe717f2a3f0cc9c175f7561b661997
0000000000000000 266a24aa21a9eddb07ed2a146a68ee1ddc9be6c483f9ad7927c49b541d5ad6dbb24d37abb31e46
0000000000000000 2952534b424c4f434b3a939a8f772155dcc0dd9bf27f3d4e56323c5ed325299c799432395496f7126181
01 1 witness (1 stack item)
20 Witness Length (32 bytes, then Witness of the Coinbase Input)
0000000000000000000000000000000000000000000000000000000000000000
00000000 Lock Time
I guess that I will just renounce to it and only allow legacy payout addresses for now...
Contributions to the code are welcome if anyone is motivated to implement SegWit payout addresses support in rieMiner.