本文整理匯總了Golang中github.com/NebulousLabs/Sia/types.Block.MerkleRoot方法的典型用法代碼示例。如果您正苦於以下問題:Golang Block.MerkleRoot方法的具體用法?Golang Block.MerkleRoot怎麽用?Golang Block.MerkleRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/types.Block
的用法示例。
在下文中一共展示了Block.MerkleRoot方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SolveBlock
// SolveBlock takes a block, target, and number of iterations as input and
// tries to find a block that meets the target. This function can take a long
// time to complete, and should not be called with a lock.
func (m *Miner) SolveBlock(b types.Block, target types.Target) (types.Block, bool) {
// Assemble the header.
merkleRoot := b.MerkleRoot()
header := make([]byte, 80)
copy(header, b.ParentID[:])
binary.LittleEndian.PutUint64(header[40:48], uint64(b.Timestamp))
copy(header[48:], merkleRoot[:])
nonce := (*uint64)(unsafe.Pointer(&header[32]))
for i := 0; i < iterationsPerAttempt; i++ {
id := crypto.HashBytes(header)
if bytes.Compare(target[:], id[:]) >= 0 {
copy(b.Nonce[:], header[32:40])
return b, true
}
*nonce++
}
return b, false
}