本文整理汇总了Golang中github.com/piotrnar/gocoin/lib/chain.BlockTreeNode.Parent方法的典型用法代码示例。如果您正苦于以下问题:Golang BlockTreeNode.Parent方法的具体用法?Golang BlockTreeNode.Parent怎么用?Golang BlockTreeNode.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/piotrnar/gocoin/lib/chain.BlockTreeNode
的用法示例。
在下文中一共展示了BlockTreeNode.Parent方法的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
}
MemBlockChainMutex.Lock()
if prv, pres := MemBlockChain.BlockIndex[bl.Hash.BIdx()]; pres {
MemBlockChainMutex.Unlock()
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 {
MemBlockChainMutex.Unlock()
er = errors.New(fmt.Sprint("CheckBlock: Incorrect proof of work at block", prevblk.Height+1))
return
}
}
cur := new(chain.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
MemBlockChainMutex.Unlock()
LastBlock.Mutex.Lock()
if cur.Height > LastBlock.node.Height {
LastBlock.node = cur
}
LastBlock.Mutex.Unlock()
return
}