package test
import (
- "github.com/bytom/consensus"
- "github.com/bytom/consensus/difficulty"
- "github.com/bytom/mining/tensority"
- "github.com/bytom/protocol"
- "github.com/bytom/protocol/bc"
- "github.com/bytom/protocol/bc/types"
- "github.com/bytom/protocol/validation"
- "github.com/bytom/protocol/vm"
+ "github.com/bytom/bytom/mining/tensority"
+ "github.com/bytom/bytom/protocol"
+ "github.com/bytom/bytom/protocol/bc"
+ "github.com/bytom/bytom/protocol/bc/types"
+ "github.com/bytom/bytom/protocol/validation"
+ "github.com/bytom/bytom/protocol/vm"
)
// NewBlock create block according to the current status of chain
txsFee := uint64(0)
txEntries := []*bc.Tx{nil}
txStatus := bc.NewTransactionStatus()
- txStatus.SetStatus(0, false)
+ if err := txStatus.SetStatus(0, false); err != nil {
+ return nil, err
+ }
preBlockHeader := chain.BestBlockHeader()
- var compareDiffBH *types.BlockHeader
- if compareDiffBlock, err := chain.GetBlockByHeight(preBlockHeader.Height - consensus.BlocksPerRetarget); err == nil {
- compareDiffBH = &compareDiffBlock.BlockHeader
+ preBlockHash := preBlockHeader.Hash()
+ nextBits, err := chain.CalcNextBits(&preBlockHash)
+ if err != nil {
+ return nil, err
}
b := &types.Block{
PreviousBlockHash: preBlockHeader.Hash(),
Timestamp: preBlockHeader.Timestamp + 1,
BlockCommitment: types.BlockCommitment{},
- Bits: difficulty.CalcNextRequiredDifficulty(preBlockHeader, compareDiffBH),
+ Bits: nextBits,
},
Transactions: []*types.Tx{nil},
}
gasOnlyTx := false
gasStatus, err := validation.ValidateTx(tx.Tx, bcBlock)
if err != nil {
- if !gasStatus.GasVaild {
+ if !gasStatus.GasValid {
continue
}
gasOnlyTx = true
b.Transactions[0] = coinbaseTx
txEntries[0] = coinbaseTx.Tx
- b.TransactionsMerkleRoot, err = bc.TxMerkleRoot(txEntries)
+ b.TransactionsMerkleRoot, err = types.TxMerkleRoot(txEntries)
if err != nil {
return nil, err
}
- b.TransactionStatusHash, err = bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
+ b.TransactionStatusHash, err = types.TxStatusMerkleRoot(txStatus.VerifyStatus)
return b, err
}
txEntires = append(txEntires, block.Transactions[i].Tx)
}
- block.TransactionsMerkleRoot, err = bc.TxMerkleRoot(txEntires)
+ block.TransactionsMerkleRoot, err = types.TxMerkleRoot(txEntires)
return
}