// createCoinbaseTx returns a coinbase transaction paying an appropriate subsidy
// based on the passed block height to the provided address. When the address
// is nil, the coinbase transaction will instead be redeemable by anyone.
-func createCoinbaseTx(accountManager *account.Manager, amount uint64, blockHeight uint64) (tx *types.Tx, err error) {
- amount += consensus.BlockSubsidy(blockHeight)
+func createCoinbaseTx(accountManager *account.Manager, blockHeight uint64, rewards []state.CoinbaseReward) (tx *types.Tx, err error) {
arbitrary := append([]byte{0x00}, []byte(strconv.FormatUint(blockHeight, 10))...)
-
var script []byte
if accountManager == nil {
script, err = vmutil.DefaultCoinbaseProgram()
return nil, err
}
- if len(arbitrary) > consensus.CoinbaseArbitrarySizeLimit {
+ if len(arbitrary) > consensus.ActiveNetParams.CoinbaseArbitrarySizeLimit {
return nil, validation.ErrCoinbaseArbitraryOversize
}
if err = builder.AddInput(types.NewCoinbaseInput(arbitrary), &txbuilder.SigningInstruction{}); err != nil {
return nil, err
}
- if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, amount, script)); err != nil {
+ if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, 0, script)); err != nil {
return nil, err
}
+
+ for _, r := range rewards {
+ if err = builder.AddOutput(types.NewIntraChainOutput(*consensus.BTMAssetID, r.Amount, r.ControlProgram)); err != nil {
+ return nil, err
+ }
+ }
+
_, txData, err := builder.Build()
if err != nil {
return nil, err
if err != nil {
return nil, err
}
- txData.SerializedSize = uint64(len(byteData))
+ txData.SerializedSize = uint64(len(byteData))
tx = &types.Tx{
TxData: *txData,
Tx: types.MapTx(txData),
}
txEntries := []*bc.Tx{nil}
gasUsed := uint64(0)
- txFee := uint64(0)
// get preblock info for generate next block
preBlockHeader := c.BestBlockHeader()
PreviousBlockHash: preBlockHash,
Timestamp: timestamp,
BlockCommitment: types.BlockCommitment{},
- BlockWitness: types.BlockWitness{Witness: make([][]byte, consensus.NumOfConsensusNode)},
+ BlockWitness: types.BlockWitness{Witness: make([][]byte, consensus.ActiveNetParams.NumOfConsensusNode)},
},
}
bcBlock := &bc.Block{BlockHeader: &bc.BlockHeader{Height: nextBlockHeight}}
continue
}
- if gasUsed+uint64(gasStatus.GasUsed) > consensus.MaxBlockGas {
+ if gasUsed+uint64(gasStatus.GasUsed) > consensus.ActiveNetParams.MaxBlockGas {
break
}
b.Transactions = append(b.Transactions, txDesc.Tx)
txEntries = append(txEntries, tx)
gasUsed += uint64(gasStatus.GasUsed)
- txFee += txDesc.Fee
-
- if gasUsed == consensus.MaxBlockGas {
+ if gasUsed == consensus.ActiveNetParams.MaxBlockGas {
break
}
}
- // creater coinbase transaction
- b.Transactions[0], err = createCoinbaseTx(accountManager, txFee, nextBlockHeight)
+ consensusResult, err := c.GetConsensusResultByHash(&preBlockHash)
+ if err != nil {
+ return nil, err
+ }
+
+ rewards, err := consensusResult.GetCoinbaseRewards(preBlockHeader.Height)
+ if err != nil {
+ return nil, err
+ }
+
+ // create coinbase transaction
+ b.Transactions[0], err = createCoinbaseTx(accountManager, nextBlockHeight, rewards)
if err != nil {
return nil, errors.Wrap(err, "fail on createCoinbaseTx")
}
- txEntries[0] = b.Transactions[0].Tx
+ txEntries[0] = b.Transactions[0].Tx
b.BlockHeader.BlockCommitment.TransactionsMerkleRoot, err = types.TxMerkleRoot(txEntries)
if err != nil {
return nil, err