func (n *NodeBlockMaker) CompleteBlock() (*structures.Block, error) {
	if n.PreparedBlock == nil {
		return nil, errors.New("Block was not prepared")
	}
	b := n.PreparedBlock
	n.Logger.Trace.Printf("Minting: Start proof of work for the block\n")
	starttime := time.Now()
	pow := NewProofOfWork(b)
	nonce, hash, err := pow.Run()
	if err != nil {
		return nil, err
	}
	b.Hash = hash[:]
	b.Nonce = nonce
	if config.MinimumBlockBuildingTime > 0 {
		for t := time.Since(starttime).Seconds(); t < float64(config.MinimumBlockBuildingTime); t = time.Since(starttime).Seconds() {
			time.Sleep(1 * time.Second)
			n.Logger.Trace.Printf("Sleep")
		}
	}
	n.Logger.Trace.Printf("Minting: New hash is %x\n", b.Hash)
	return b, nil
}
finalise a block. in this place we do MIMING
Block was prepared. Now do final work for this block. In our case it is PoW process
package consensus
import (
	"errors"
	"fmt"
	"time"
	"github.com/gelembjuk/democoin/lib/utils"
	"github.com/gelembjuk/democoin/node/blockchain"
	"github.com/gelembjuk/democoin/node/config"
	"github.com/gelembjuk/democoin/node/database"
	"github.com/gelembjuk/democoin/node/structures"
	"github.com/gelembjuk/democoin/node/transactions"
)
type NodeBlockMaker struct {
	DB            database.DBManager
	Logger        *utils.LoggerMan
	MinterAddress string  
	PreparedBlock *structures.Block
}
func (n *NodeBlockMaker) SetDBManager(DB database.DBManager) {
	n.DB = DB
}
func (n *NodeBlockMaker) SetLogManager(Logger *utils.LoggerMan) {
	n.Logger = Logger
}
func (n *NodeBlockMaker) SetMinterAddress(minter string) {
	n.MinterAddress = minter
}
func (n *NodeBlockMaker) PrepareNewBlock() (int, error) {
	if n.PreparedBlock != nil {
		return BlockPrepare_Error, errors.New("There is a block prepared already")
	}
	if !n.checkGoodTimeToMakeBlock() {
		return BlockPrepare_NotGoodTime, nil
	}
	if !n.checkUnapprovedCache() {
		return BlockPrepare_NoTransactions, nil
	}
	n.PreparedBlock = nil
	err := n.doPrepareNewBlock()
	if err != nil {
		return BlockPrepare_Error, err
	}
	if n.PreparedBlock == nil {
		return BlockPrepare_NoTransactions, nil
	}
	return BlockPrepare_Done, nil
}
func (n *NodeBlockMaker) IsBlockPrepared() bool {
	return n.PreparedBlock != nil
}
func (n *NodeBlockMaker) getTransactionsManager() transactions.TransactionsManagerInterface {
	return transactions.NewManager(n.DB, n.Logger)
}
func (n *NodeBlockMaker) getBlockchainManager() *blockchain.Blockchain {
	bcm, _ := blockchain.NewBlockchainManager(n.DB, n.Logger)
	return bcm
}
func (n *NodeBlockMaker) checkGoodTimeToMakeBlock() bool {
	return true
}
func (n *NodeBlockMaker) checkUnapprovedCache() bool {
	count, err := n.getTransactionsManager().GetUnapprovedCount()
	if err != nil {
		n.Logger.Trace.Printf("Error when check unapproved cache: %s", err.Error())
		return false
	}
	n.Logger.Trace.Printf("Transaction in cache - %d", count)
	min, max, err := n.getTransactionNumbersLimits(nil)
	if count >= min {
		if count > max {
			count = max
		}
		return true
	}
	return false
}
func (n *NodeBlockMaker) SetPreparedBlock(block *structures.Block) error {
	n.PreparedBlock = block
	return nil
}
func (n *NodeBlockMaker) doPrepareNewBlock() error {
	count, err := n.getTransactionsManager().GetUnapprovedCount()
	if err != nil {
		return err
	}
	min, max, err := n.getTransactionNumbersLimits(nil)
	if err != nil {
		return err
	}
	n.Logger.Trace.Printf("Minting: Found %d transaction from minimum %d\n", count, min)
	if count >= min {
		if count > max {
			count = max
		}
		txs, err := n.getTransactionsManager().GetUnapprovedTransactionsForNewBlock(count)
		if err != nil {
			return err
		}
		if len(txs) < min {
			return errors.New("No enought valid transactions! Waiting for new ones...")
		}
		n.Logger.Trace.Printf("Minting: All good. New block assigned to address %s\n", n.MinterAddress)
		newBlock, err := n.makeNewBlockFromTransactions(txs)
		if err != nil {
			return err
		}
		n.Logger.Trace.Printf("Minting: New block Prepared. Not yet complete\n")
		n.PreparedBlock = newBlock
	}
	return nil
}