func createCoinbaseTx(coinbaseScript []byte, nextBlockHeight int32,
	addr provautil.Address, net *chaincfg.Params) (*provautil.Tx, error) {
	pkScript, err := txscript.PayToAddrScript(addr)
	if err != nil {
		return nil, err
	}
	tx := wire.NewMsgTx(wire.TxVersion)
	tx.AddTxIn(&wire.TxIn{
		PreviousOutPoint: *wire.NewOutPoint(&chainhash.Hash{},
			wire.MaxPrevOutIndex),
		SignatureScript: coinbaseScript,
		Sequence:        wire.MaxTxInSequenceNum,
	})
	tx.AddTxOut(&wire.TxOut{
		Value:    blockchain.CalcBlockSubsidy(nextBlockHeight, net),
		PkScript: pkScript,
	})
	return provautil.NewTx(tx), nil
}
createCoinbaseTx returns a coinbase transaction paying an appropriate
subsidy based on the passed block height to the provided address.
package rpctest
import (
	"errors"
	"math"
	"math/big"
	"runtime"
	"time"
	"github.com/bitgo/prova/blockchain"
	"github.com/bitgo/prova/chaincfg"
	"github.com/bitgo/prova/chaincfg/chainhash"
	"github.com/bitgo/prova/provautil"
	"github.com/bitgo/prova/txscript"
	"github.com/bitgo/prova/wire"
)
func solveBlock(header *wire.BlockHeader, targetDifficulty *big.Int) bool {
	type sbResult struct {
		found bool
		nonce uint64
	}
	quit := make(chan bool)
	results := make(chan sbResult)
	solver := func(hdr wire.BlockHeader, startNonce, stopNonce uint64) {
		for i := startNonce; i >= startNonce && i <= stopNonce; i++ {
			select {
			case <-quit:
				return
			default:
				hdr.Nonce = i
				hash := hdr.BlockHash()
				if blockchain.HashToBig(&hash).Cmp(targetDifficulty) <= 0 {
					results <- sbResult{true, i}
					return
				}
			}
		}
		results <- sbResult{false, 0}
	}
	startNonce := uint64(0)
	stopNonce := uint64(math.MaxUint64)
	numCores := uint64(runtime.NumCPU())
	noncesPerCore := (stopNonce - startNonce) / numCores
	for i := uint64(0); i < numCores; i++ {
		rangeStart := startNonce + (noncesPerCore * i)
		rangeStop := startNonce + (noncesPerCore * (i + 1)) - 1
		if i == numCores-1 {
			rangeStop = stopNonce
		}
		go solver(*header, rangeStart, rangeStop)
	}
	for i := uint64(0); i < numCores; i++ {
		result := <-results
		if result.found {
			close(quit)
			header.Nonce = result.nonce
			return true
		}
	}
	return false
}
func standardCoinbaseScript(nextBlockHeight int32) ([]byte, error) {
	return txscript.NewScriptBuilder().AddInt64(int64(nextBlockHeight)).Script()
}