本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.ConsensusChange.ChildTarget方法的典型用法代碼示例。如果您正苦於以下問題:Golang ConsensusChange.ChildTarget方法的具體用法?Golang ConsensusChange.ChildTarget怎麽用?Golang ConsensusChange.ChildTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/modules.ConsensusChange
的用法示例。
在下文中一共展示了ConsensusChange.ChildTarget方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: computeConsensusChange
// computeConsensusChange computes the consensus change from the change entry
// at index 'i' in the change log. If i is out of bounds, an error is returned.
func (cs *ConsensusSet) computeConsensusChange(tx *bolt.Tx, ce changeEntry) (modules.ConsensusChange, error) {
cc := modules.ConsensusChange{
ID: ce.ID(),
}
for _, revertedBlockID := range ce.RevertedBlocks {
revertedBlock, err := getBlockMap(tx, revertedBlockID)
if err != nil {
cs.log.Critical("getBlockMap failed in computeConsensusChange:", err)
return modules.ConsensusChange{}, err
}
// Because the direction is 'revert', the order of the diffs needs to
// be flipped and the direction of the diffs also needs to be flipped.
cc.RevertedBlocks = append(cc.RevertedBlocks, revertedBlock.Block)
for i := len(revertedBlock.SiacoinOutputDiffs) - 1; i >= 0; i-- {
scod := revertedBlock.SiacoinOutputDiffs[i]
scod.Direction = !scod.Direction
cc.SiacoinOutputDiffs = append(cc.SiacoinOutputDiffs, scod)
}
for i := len(revertedBlock.FileContractDiffs) - 1; i >= 0; i-- {
fcd := revertedBlock.FileContractDiffs[i]
fcd.Direction = !fcd.Direction
cc.FileContractDiffs = append(cc.FileContractDiffs, fcd)
}
for i := len(revertedBlock.SiafundOutputDiffs) - 1; i >= 0; i-- {
sfod := revertedBlock.SiafundOutputDiffs[i]
sfod.Direction = !sfod.Direction
cc.SiafundOutputDiffs = append(cc.SiafundOutputDiffs, sfod)
}
for i := len(revertedBlock.DelayedSiacoinOutputDiffs) - 1; i >= 0; i-- {
dscod := revertedBlock.DelayedSiacoinOutputDiffs[i]
dscod.Direction = !dscod.Direction
cc.DelayedSiacoinOutputDiffs = append(cc.DelayedSiacoinOutputDiffs, dscod)
}
for i := len(revertedBlock.SiafundPoolDiffs) - 1; i >= 0; i-- {
sfpd := revertedBlock.SiafundPoolDiffs[i]
sfpd.Direction = modules.DiffRevert
cc.SiafundPoolDiffs = append(cc.SiafundPoolDiffs, sfpd)
}
}
for _, appliedBlockID := range ce.AppliedBlocks {
appliedBlock, err := getBlockMap(tx, appliedBlockID)
if err != nil {
cs.log.Critical("getBlockMap failed in computeConsensusChange:", err)
return modules.ConsensusChange{}, err
}
cc.AppliedBlocks = append(cc.AppliedBlocks, appliedBlock.Block)
for _, scod := range appliedBlock.SiacoinOutputDiffs {
cc.SiacoinOutputDiffs = append(cc.SiacoinOutputDiffs, scod)
}
for _, fcd := range appliedBlock.FileContractDiffs {
cc.FileContractDiffs = append(cc.FileContractDiffs, fcd)
}
for _, sfod := range appliedBlock.SiafundOutputDiffs {
cc.SiafundOutputDiffs = append(cc.SiafundOutputDiffs, sfod)
}
for _, dscod := range appliedBlock.DelayedSiacoinOutputDiffs {
cc.DelayedSiacoinOutputDiffs = append(cc.DelayedSiacoinOutputDiffs, dscod)
}
for _, sfpd := range appliedBlock.SiafundPoolDiffs {
cc.SiafundPoolDiffs = append(cc.SiafundPoolDiffs, sfpd)
}
}
// Grab the child target and the minimum valid child timestamp.
recentBlock := ce.AppliedBlocks[len(ce.AppliedBlocks)-1]
pb, err := getBlockMap(tx, recentBlock)
if err != nil {
cs.log.Critical("could not find process block for known block")
}
cc.ChildTarget = pb.ChildTarget
cc.MinimumValidChildTimestamp = cs.blockRuleHelper.minimumValidChildTimestamp(tx.Bucket(BlockMap), pb)
currentBlock := currentBlockID(tx)
if cs.synced && recentBlock == currentBlock {
cc.Synced = true
}
return cc, nil
}