function mine()
{
while(true)
{
longestChain = getLongestValidChain()
-- A number that changes every time, so that you don't waste time
-- trying to calculate a valid blockHash with the same input.
nonce = getNewNonce()
currentTXs = getUnconfirmedTransactionsFromNetwork()
newBlock = getNewBlock(longestChain, currentTX, nonce)
-- http://en.wikipedia.org/wiki/SHA-2
-- and this is what all the "mining machines" are doing.
blockHash = sha256(newBlock)
if(meetReqirements(blockHash))
{
broadcast(newBlock)
-- Now the height the block chain is incremented by 1
-- (if the new block is accepted by other peers),
-- and all the TXs in the new block are "confirmed"
}
}
}
////////////////////////////////////////////////// ///////////////
function sendBTC(amount)
{
sourceTXs = pickConfirmedTransactionsToBeSpent(amount)
tx = generateTX(sourceTXs, targetAddrs, amount, fee)
signedTx = sign(tx, privateKeysOfAllInputAddress)
broadcast(signedTx)
}
////////////////////////////////////////////////// ///////////////
文章來自知乎:深入淺出比特幣 作者:Wu Hao
作者在 2013-11-22 新增了「第負一章 第二節 刪節版」,並提供了一段原始碼:
現在雖然沒有分析,不過靜待作者的更新吧。
----2013-12-10 13:16 更新---
非常遺憾,作者的回信是:「沒有繼續寫的打算」。
MAIN函數在 bitcoinGUI.cpp 或bitcoind.cpp 裡面。 看看DOC/BUILD-WIN.MD裡面有編譯方法