OSDN Git Service

delete generate block for api
[bytom/vapor.git] / mining / mining.go
index e2dfcac..5943904 100644 (file)
@@ -78,97 +78,7 @@ func createCoinbaseTx(accountManager *account.Manager, amount uint64, blockHeigh
 }
 
 // NewBlockTemplate returns a new block template that is ready to be solved
-func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager) (b *types.Block, err error) {
-       view := state.NewUtxoViewpoint()
-       txStatus := bc.NewTransactionStatus()
-       if err := txStatus.SetStatus(0, false); err != nil {
-               return nil, err
-       }
-       txEntries := []*bc.Tx{nil}
-       gasUsed := uint64(0)
-       txFee := uint64(0)
-
-       // get preblock info for generate next block
-       preBlockHeader := c.BestBlockHeader()
-       preBlockHash := preBlockHeader.Hash()
-       nextBlockHeight := preBlockHeader.Height + 1
-
-       header := types.BlockHeader{
-               Version:           1,
-               Height:            nextBlockHeight,
-               PreviousBlockHash: preBlockHash,
-               Timestamp:         uint64(time.Now().Unix()),
-               BlockCommitment:   types.BlockCommitment{},
-       }
-
-       b = &types.Block{BlockHeader: header}
-       bcBlock := &bc.Block{BlockHeader: &bc.BlockHeader{Height: nextBlockHeight}}
-       b.Transactions = []*types.Tx{nil}
-
-       txs := txPool.GetTransactions()
-       sort.Sort(byTime(txs))
-       for _, txDesc := range txs {
-               tx := txDesc.Tx.Tx
-               gasOnlyTx := false
-
-               if err := c.GetTransactionsUtxo(view, []*bc.Tx{tx}); err != nil {
-                       blkGenSkipTxForErr(txPool, &tx.ID, err)
-                       continue
-               }
-
-               gasStatus, err := validation.ValidateTx(tx, bcBlock)
-               if err != nil {
-                       if !gasStatus.GasValid {
-                               blkGenSkipTxForErr(txPool, &tx.ID, err)
-                               continue
-                       }
-                       gasOnlyTx = true
-               }
-
-               if gasUsed+uint64(gasStatus.GasUsed) > consensus.MaxBlockGas {
-                       break
-               }
-
-               if err := view.ApplyTransaction(bcBlock, tx, gasOnlyTx); err != nil {
-                       blkGenSkipTxForErr(txPool, &tx.ID, err)
-                       continue
-               }
-
-               if err := txStatus.SetStatus(len(b.Transactions), gasOnlyTx); err != nil {
-                       return nil, err
-               }
-
-               b.Transactions = append(b.Transactions, txDesc.Tx)
-               txEntries = append(txEntries, tx)
-               gasUsed += uint64(gasStatus.GasUsed)
-               txFee += txDesc.Fee
-
-               if gasUsed == consensus.MaxBlockGas {
-                       break
-               }
-       }
-       if txFee == 0 {
-               return nil, err
-       }
-
-       // creater coinbase transaction
-       b.Transactions[0], err = createCoinbaseTx(accountManager, txFee, nextBlockHeight)
-       if err != nil {
-               return nil, errors.Wrap(err, "fail on createCoinbaseTx")
-       }
-       txEntries[0] = b.Transactions[0].Tx
-
-       b.BlockHeader.BlockCommitment.TransactionsMerkleRoot, err = types.TxMerkleRoot(txEntries)
-       if err != nil {
-               return nil, err
-       }
-
-       b.BlockHeader.BlockCommitment.TransactionStatusHash, err = types.TxStatusMerkleRoot(txStatus.VerifyStatus)
-       return b, err
-}
-
-// NewBlockTemplate returns a new block template that is ready to be solved
-func NewBlockTemplate1(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager, engine engine.Engine) (b *types.Block, err error) {
+func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager, engine engine.Engine) (b *types.Block, err error) {
        view := state.NewUtxoViewpoint()
        txStatus := bc.NewTransactionStatus()
        if err := txStatus.SetStatus(0, false); err != nil {