一. 數(shù)據(jù)結(jié)構(gòu)介紹
1. CTxOut
An output of a transaction. It contains the public key that the next input must be able to sign with to claim it.字段屬性 | 說明 |
---|---|
nValue | 交易輸出對應(yīng)的金額 |
scriptPubKey | 交易對應(yīng)的公鑰 |
2. COutPoint
對應(yīng)交易的第幾個(gè)輸出字段屬性 | 說明 |
---|---|
hash | 交易對應(yīng)的hash |
n | 交易對應(yīng)的第幾個(gè)輸出 |
3. CTxIn
An input of a transaction. It contains the location of the previous transaction's output that it claims and a signature that matches the output's public key.字段屬性 | 說明 |
---|---|
prevout | 前一個(gè)交易對應(yīng)的輸出(叫一個(gè)交易對應(yīng)的hash值和對應(yīng)的第幾個(gè)輸出) |
scriptSig | 輸入腳本對應(yīng)的簽名 |
nSequence | 主要是用于判斷相同輸入的交易哪一個(gè)更新部服,值越大越新 |
4. CTransaction
The basic transaction that is broadcasted on the network and contained in blocks. A transaction can contain multiple inputs and outputs.字段屬性 | 說明 |
---|---|
nVersion | 交易的版本號节腐,用于升級 |
vin | 交易對應(yīng)的輸入列表 |
vout | 交易對應(yīng)的輸出列表 |
nLockTime | 交易對應(yīng)的鎖定時(shí)間,目前沒有使用(在最初版本的比特幣中) |
5. CMerkleTx
A transaction with a merkle branch linking it to the block chain字段屬性 | 說明 |
---|---|
hashBlock | 交易所在block對應(yīng)的hash值寿冕,因?yàn)閎lock中有對應(yīng)整個(gè)交易的默克爾樹拜马,這樣才能根據(jù)分支來校驗(yàn)當(dāng)前交易是否在block中 |
vMerkleBranch | 當(dāng)前交易對應(yīng)的默克爾分支 |
nIndex | 當(dāng)前交易在對應(yīng)的block對應(yīng)的輸入vtx列表中的索引彤枢,CMerkleTx就是根據(jù)索引來計(jì)算這個(gè)交易對應(yīng)的默克爾樹分支的 |
fMerkleVerified | 標(biāo)記默克爾交易是否已經(jīng)校驗(yàn)惨篱,如果沒有校驗(yàn)則進(jìn)行校驗(yàn),校驗(yàn)之后將這個(gè)值設(shè)為true |
6. CWalletTx
A transaction with a bunch of additional info that only the owner cares about. It includes any unrecorded transactions needed to link it back to the block chain.字段屬性 | 說明 |
---|---|
vtxPrev | 當(dāng)前交易A對應(yīng)的輸入對應(yīng)的交易B收厨,如果B所在block到最長鏈末尾的長度小于3晋柱,則將次交易放入 |
fTimeReceivedIsTxTime | 接收時(shí)間是否是交易時(shí)間標(biāo)記 |
nTimeReceived | 交易被這個(gè)節(jié)點(diǎn)接收的時(shí)間 |
7. CBlock
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce values to make the block's hash satisfy proof-of-work requirements. When they solve the proof-of-work, they broadcast the block to everyone and the block is added to the block chain. The first transaction in the block is a special one that creates a new coin owned by the creator of the block. Blocks are appended to blk0001.dat files on disk. Their location on disk is indexed by CBlockIndex objects in memory.字段屬性 | 說明 |
---|---|
nVersion | 塊的版本,主要為了后續(xù)的升級使用 |
hashPrevBlock | 前一個(gè)塊對應(yīng)的hash |
hashMerkleRoot | 默克爾對應(yīng)的根 |
nTime | 區(qū)塊創(chuàng)建時(shí)間:這個(gè)值取max(前11個(gè)區(qū)塊對應(yīng)創(chuàng)建時(shí)間中位數(shù)诵叁,當(dāng)前時(shí)間) |
nBits | 記錄本區(qū)塊難度 |
nNonce | 工作量證明獲得隨機(jī)數(shù)雁竞,這個(gè)隨機(jī)數(shù)正好滿足當(dāng)前挖礦對應(yīng)的難度 |
vtx | 塊中交易列表 |
vMerkleTree | 整個(gè)交易對應(yīng)的默克爾樹列表 |
8. CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root, with each block potentially having multiple candidates to be the next block. pprev and pnext link a path through the main/longest chain. A blockindex may have multiple pprev pointing back to it, but pnext will only point forward to the longest branch, or will be null if the block is not part of the longest chain. 如果塊索引對應(yīng)的pNext不為空,則這個(gè)塊索引一定對應(yīng)的是主鏈字段屬性 | 說明 |
---|---|
phashBlock | 對應(yīng)塊hash值指針 |
pprev | 指向前一個(gè)blockIndex |
pnext | 指向當(dāng)前區(qū)塊索引的下一個(gè)拧额,只有當(dāng)前區(qū)塊索引在主鏈上的時(shí)候碑诉,這個(gè)值才是非空 |
nFile | 塊所在文件的信息,而且塊文件的命名一般是blk${nFile}.dat |
nBlockPos | 塊在文件中的偏移 |
nHeight | 塊索引在最長鏈的深度侥锦,即是中間隔了多少個(gè)block进栽,即是從創(chuàng)世區(qū)塊到當(dāng)前區(qū)塊中間隔了多少個(gè)區(qū)塊 |
nVersion | 塊的版本,主要為了后續(xù)的升級使用 |
hashMerkleRoot | 默克爾對應(yīng)的根 |
nTime | 區(qū)塊創(chuàng)建時(shí)間:這個(gè)值取max(前11個(gè)區(qū)塊對應(yīng)創(chuàng)建時(shí)間中位數(shù)恭垦,當(dāng)前時(shí)間) |
nBits | 記錄本區(qū)塊難度 |
nNonce | 工作量證明獲得隨機(jī)數(shù)快毛,這個(gè)隨機(jī)數(shù)正好滿足當(dāng)前挖礦對應(yīng)的難度 |
9. CDiskTxPos
交易在文件中對應(yīng)的索引位置字段屬性 | 說明 |
---|---|
nFile | 塊所在文件的信息,而且塊文件的命名一般是blk${nFile}.dat |
nBlockPos | 塊在文件中的偏移 |
nTxPos | 交易在對應(yīng)塊中的偏移 |
10. CTxIndex
A txdb record that contains the disk location of a transaction and the locations of transactions that spend its outputs. vSpent is really only used as a flag, but having the location is very helpful for debugging. 交易索引---每一個(gè)交易對應(yīng)一個(gè)索引字段屬性 | 說明 |
---|---|
pos | 交易對應(yīng)的在硬盤中文件的位置 |
vSpent | 標(biāo)記交易的輸出是否已經(jīng)被消費(fèi)了番挺,根據(jù)下標(biāo)來標(biāo)記對應(yīng)交易指定位置的輸出是否已經(jīng)被消費(fèi)了 |
11. CDataStream
Double ended buffer combining vector and stream-like interfaces. >> and << read and write unformatted data using the above serialization templates. Fills with data in linear time; some stringstream implementations take N^2 time.字段屬性 | 說明 |
---|---|
vch | 流中存放的數(shù)據(jù) |
nReadPos | 流中讀取的位置 |
nType | 類型 |
nVersion | 版本 |
12. CAddress
地址信息字段屬性 | 說明 |
---|---|
nServices | 服務(wù)標(biāo)識 |
pchReserved | 保留內(nèi)容:{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff } |
ip | Ip地址 |
port | 端口 |
nTime | 時(shí)間 |
nLastFailed | 對應(yīng)這個(gè)地址最近連接失敗時(shí)間 |
13. CNode
節(jié)點(diǎn)定義字段屬性 | 說明 |
---|---|
nServices | 服務(wù)標(biāo)識 |
hSocket | 對應(yīng)本地和這個(gè)節(jié)點(diǎn)連接的套接字 |
vSend | 發(fā)送緩存區(qū) |
vRecv | 接收緩沖區(qū) |
nPushPos | 指定發(fā)送區(qū)已經(jīng)發(fā)送的位置 |
addr | 對應(yīng)這個(gè)節(jié)點(diǎn)的地址信息 |
nVersion | 節(jié)點(diǎn)對應(yīng)的版本唠帝,如果節(jié)點(diǎn)版本為0,則消息發(fā)送不出去 |
fClient | 標(biāo)記是否是客戶端玄柏,如果是客戶端則需要區(qū)塊的頭部進(jìn)行校驗(yàn)就可以了,不需要保存整個(gè)區(qū)塊的內(nèi)容 |
fNetworkNode | 設(shè)置對應(yīng)的節(jié)點(diǎn)為網(wǎng)絡(luò)節(jié)點(diǎn) |
fDisconnect | 節(jié)點(diǎn)斷開連接的標(biāo)記 |
nRefCount | 引用計(jì)數(shù)器 |
nReleaseTime | 節(jié)點(diǎn)釋放的時(shí)間 |
vAddrToSend | flood 洪泛:消息需要發(fā)送對應(yīng)的地址襟衰,對需要發(fā)送的地址進(jìn)行已知地址的集合過濾之后再發(fā)送 |
setAddrKnown | 已知地址的集合 |
setInventoryKnown | 基于轉(zhuǎn)播的庫存:已知庫存的集合 |
vInventoryToSend | 庫存準(zhǔn)備發(fā)送的集合,對庫存準(zhǔn)備發(fā)送的集合根據(jù)已知庫存的集合進(jìn)行過濾之后在發(fā)送 |
二. 源碼地址
我對比特幣bitcoin-0.1.0源碼加了詳細(xì)的注釋粪摘,對應(yīng)的下載地址:https://github.com/lwjaiyjk/bitcoin-comment-0.1.0.git