本文整理匯總了Golang中github.com/piotrnar/gocoin/btc.Block.Bits方法的典型用法代碼示例。如果您正苦於以下問題:Golang Block.Bits方法的具體用法?Golang Block.Bits怎麽用?Golang Block.Bits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/piotrnar/gocoin/btc.Block
的用法示例。
在下文中一共展示了Block.Bits方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: chkblock
func chkblock(bl *btc.Block) (er error) {
// Check timestamp (must not be higher than now +2 hours)
if int64(bl.BlockTime()) > time.Now().Unix()+2*60*60 {
er = errors.New("CheckBlock() : block timestamp too far in the future")
return
}
if prv, pres := MemBlockChain.BlockIndex[bl.Hash.BIdx()]; pres {
if prv.Parent == nil {
// This is genesis block
er = errors.New("Genesis")
return
} else {
return
}
}
prevblk, ok := MemBlockChain.BlockIndex[btc.NewUint256(bl.ParentHash()).BIdx()]
if !ok {
er = errors.New("CheckBlock: " + bl.Hash.String() + " parent not found")
return
}
// Check proof of work
gnwr := MemBlockChain.GetNextWorkRequired(prevblk, bl.BlockTime())
if bl.Bits() != gnwr {
if !Testnet || ((prevblk.Height+1)%2016) != 0 {
er = errors.New(fmt.Sprint("CheckBlock: Incorrect proof of work at block", prevblk.Height+1))
}
}
cur := new(btc.BlockTreeNode)
cur.BlockHash = bl.Hash
cur.Parent = prevblk
cur.Height = prevblk.Height + 1
cur.TxCount = uint32(bl.TxCount)
copy(cur.BlockHeader[:], bl.Raw[:80])
prevblk.Childs = append(prevblk.Childs, cur)
MemBlockChain.BlockIndex[cur.BlockHash.BIdx()] = cur
LastBlock.Mutex.Lock()
if cur.Height > LastBlock.node.Height {
LastBlock.node = cur
}
LastBlock.Mutex.Unlock()
return
}