func (m *Miner) BlockForWork() (b types.Block, t types.Target, err error) {
	unlocked, err := m.wallet.Unlocked()
	if err != nil {
		return types.Block{}, types.Target{}, err
	}
	if !unlocked {
		err = modules.ErrLockedWallet
		return
	}
	m.mu.Lock()
	defer m.mu.Unlock()
	err = m.checkAddress()
	if err != nil {
		return
	}
	b = m.blockForWork()
	return b, m.persist.Target, nil
}
BlockForWork returns a block that is ready for nonce grinding, along with
the root hash of the block.
package miner
import (
	"bytes"
	"encoding/binary"
	"errors"
	"unsafe"
	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/types"
)
const (
	solveAttempts = 16e3
)
func solveBlock(b types.Block, target types.Target) (types.Block, bool) {
	merkleRoot := b.MerkleRoot()
	header := make([]byte, 80)
	copy(header, b.ParentID[:])
	binary.LittleEndian.PutUint64(header[40:48], uint64(b.Timestamp))
	copy(header[48:], merkleRoot[:])
	var nonce uint64
	for i := 0; i < solveAttempts; i++ {
		id := crypto.HashBytes(header)
		if bytes.Compare(target[:], id[:]) >= 0 {
			copy(b.Nonce[:], header[32:40])
			return b, true
		}
		*(*uint64)(unsafe.Pointer(&header[32])) = nonce
		nonce++
	}
	return b, false
}