上一篇文章分享了普通 rawtx 的解析過程,接下來,我們一起看看coinbase 的 rawtx 該如何解析:
coinBase rawtx 解析
coinbase是沒有輸入的,但是這個字段還是沒有,只是礦工在挖出來這個塊的時候,添加了20-100個字節(jié)的塊數(shù)據(jù),如果不是coinbase,那么這個字段就是對上一個腳本輸出的一個驗證。
01000000 //4 byte version
00 //1 byte marker
01 //1 byte flag
01 //1 byte tx_in count
0000000000000000000000000000000000000000000000000000000000000000 //32 byte hash
ffffffff //4 byte index
50 //1 byte script length(80 byte)
03
d3aa07
174d696e656420627920416e74506f6f6c6851205a4dba3efabe6d6d4d3b08032c85f61efdd1681cbe49e72e3faae7fcd20d679e8cd1b392b47829e704000000000000004c42000091780300 //80 byte script
ffffffff //4 byte sequence
02 // 2 tx out
//first tx out
353d6a5e00000000 //15.84020789 btc
19 //pk_script length(25字節(jié))
//25 byte P2PKH 輸出腳本
>>>>>>>>>>>>>>>>>>
76
a9
14
8349212dc27ce3ab4c5b29b85c4dec643d764b17
88
ac
>>>>>>>>>>>>>>>>>>>
//second tx out
0000000000000000 //0 btc (SegWit commitment output)
26 //pk_script length(38字節(jié)) 至少 38 byte
6a24aa21a9ed //6 byte 固定
a02fb7425dc44e19e02bfa5a87cb02b4b092adc35f9f3d248894d957a4958742 //32 commit hash
01 //只有一個iterm。 coinbase(是一種共識)
20 //iterm的長度32 字節(jié)
0000000000000000000000000000000000000000000000000000000000000000 //32 byte witness
00000000 //4 byte lock_time
Commitment structure
- The commitment is recorded in a scriptPubKey of the coinbase transaction. It must be at least 38 bytes, with the first 6-byte of
0x6a24aa21a9ed
, that is:
1-byte - OP_RETURN (0x6a)
1-byte - Push the following 36 bytes (0x24)
4-byte - Commitment header (0xaa21a9ed)
32-byte - Commitment hash: Double-SHA256(witness root hash|witness reserved value)
39th byte onwards: Optional data with no consensus meaning
繼續(xù)解析 coinbase 80 字節(jié)的 pubKey 輸入腳本
03 //1 byte 表示有3個字節(jié)代表塊高度
d3aa07 //當(dāng)前塊的高度 (little endian)
//76 bytes //剩下的沒有實際含義,只有礦工自己知道,只要在100字節(jié)內(nèi)就屬于合法的范圍。
174d696e656420627920416e74506f6f6c6851205a4dba3efabe6d6d4d3b08032c85f61efdd1681cbe49e72e3faae7fcd20d679e8cd1b392b47829e704000000000000004c42000091780300
本文由
Copernicus 團(tuán)隊 冉小龍
總結(jié),轉(zhuǎn)載無需授權(quán)。