-func (c *ConsensusResult) Fork() *ConsensusResult {
- f := &ConsensusResult{
- Seq: c.Seq,
- NumOfVote: map[string]uint64{},
- CoinbaseReward: map[string]uint64{},
- BlockHash: c.BlockHash,
- BlockHeight: c.BlockHeight,
- }
-
- for key, value := range c.NumOfVote {
- f.NumOfVote[key] = value
- }
-
- for key, value := range c.CoinbaseReward {
- f.CoinbaseReward[key] = value
- }
- return f
-}
-
-func (c *ConsensusResult) IsFinalize() bool {
- return c.BlockHeight%consensus.RoundVoteBlockNums == 0
-}
-
-// AttachCoinbaseReward attach coinbase reward
-func (c *ConsensusResult) AttachCoinbaseReward(block *types.Block) error {
- reward, err := CalCoinbaseReward(block)
- if err != nil {
- return err
- }
-
- if block.Height%consensus.RoundVoteBlockNums == 1 {
- c.CoinbaseReward = map[string]uint64{}
- }
-
- var ok bool
- program := hex.EncodeToString(reward.ControlProgram)
- c.CoinbaseReward[program], ok = checked.AddUint64(c.CoinbaseReward[program], reward.Amount)
- if !ok {
- return checked.ErrOverflow
- }
- return nil
-}
-