func NewMiner(miningAddrs []btcutil.Address, exit chan struct{},
	height chan<- int32, txpool chan<- struct{}) (*Miner, error) {
	ntfnHandlers := &rpc.NotificationHandlers{
		OnBlockConnected: func(hash *chainhash.Hash, h int32, time time.Time) {
			if h >= int32(*startBlock)-1 {
				if height != nil {
					height <- h
				}
			} else {
				fmt.Printf("\r%d/%d", h, *startBlock)
			}
		},
		OnTxAccepted: func(hash *chainhash.Hash, amount btcutil.Amount) {
			if txpool != nil {
				txpool <- struct{}{}
			}
		},
	}
	log.Println("Starting miner on simnet...")
	args, err := newBtcdArgs("miner")
	if err != nil {
		return nil, err
	}
	args.Listen = "127.0.0.1:18550"
	args.RPCListen = "127.0.0.1:18551"
	args.DebugLevel = "MINR=trace"
	args.Extra = []string{fmt.Sprintf("--blockmaxsize=%d", *maxBlockSize)}
	for _, addr := range miningAddrs {
		if addr != nil {
			args.Extra = append(args.Extra, "--miningaddr="+addr.EncodeAddress())
		}
	}
	logFile, err := getLogFile(args.prefix)
	if err != nil {
		log.Printf("Cannot get log file, logging disabled: %v", err)
	}
	node, err := NewNodeFromArgs(args, ntfnHandlers, logFile)
	miner := &Miner{
		Node: node,
	}
	if err := node.Start(); err != nil {
		log.Printf("%s: Cannot start mining node: %v", miner, err)
		return nil, err
	}
	if err := node.Connect(); err != nil {
		log.Printf("%s: Cannot connect to node: %v", miner, err)
		return nil, err
	}
	if err := miner.client.NotifyNewTransactions(false); err != nil {
		log.Printf("%s: Cannot register for transactions notifications: %v", miner, err)
		return miner, err
	}
	if err := miner.StartMining(); err != nil {
		return miner, err
	}
	if err := miner.client.NotifyBlocks(); err != nil {
		log.Printf("%s: Cannot register for block notifications: %v", miner, err)
		return miner, err
	}
	log.Printf("%s: Generating %v blocks...", miner, *startBlock)
	return miner, nil
}
NewMiner starts a cpu-mining enabled btcd instane and returns an rpc client
to control it.
package main
import (
	"fmt"
	"log"
	"time"
	"github.com/btcsuite/btcd/chaincfg/chainhash"
	rpc "github.com/btcsuite/btcd/rpcclient"
	"github.com/btcsuite/btcutil"
)
type Miner struct {
	*Node
}