func (w *Wallet) checkOutput(tx *bolt.Tx, currentHeight types.BlockHeight, id types.SiacoinOutputID, output types.SiacoinOutput, dustThreshold types.Currency) error {
	if output.Value.Cmp(dustThreshold) < 0 {
		return errDustOutput
	}
	spendHeight, err := dbGetSpentOutput(tx, types.OutputID(id))
	if err == nil {
		if spendHeight+RespendTimeout > currentHeight {
			return errSpendHeightTooHigh
		}
	}
	outputUnlockConditions := w.keys[output.UnlockHash].UnlockConditions
	if currentHeight < outputUnlockConditions.Timelock {
		return errOutputTimelock
	}
	return nil
}
checkOutput is a helper function used to determine if an output is usable.
package wallet
import (
	"bytes"
	"errors"
	"sort"
	"github.com/NebulousLabs/Sia/crypto"
	"github.com/NebulousLabs/Sia/encoding"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/types"
	"github.com/coreos/bbolt"
)
var (
	errBuilderAlreadySigned = errors.New("sign has already been called on this transaction builder, multiple calls can cause issues")
	errDustOutput = errors.New("output is too small")
	errOutputTimelock = errors.New("wallet consensus set height is lower than the output timelock")
	errSpendHeightTooHigh = errors.New("output spend height exceeds the allowed height")
)
type transactionBuilder struct {
	parents     []types.Transaction
	signed      bool
	transaction types.Transaction
	newParents            []int
	siacoinInputs         []int
	siafundInputs         []int
	transactionSignatures []int
	wallet *Wallet
}
func addSignatures(txn *types.Transaction, cf types.CoveredFields, uc types.UnlockConditions, parentID crypto.Hash, spendKey spendableKey) (newSigIndices []int) {
	totalSignatures := uint64(0)
	for i, siaPubKey := range uc.PublicKeys {
		for j := range spendKey.SecretKeys {
			pubKey := spendKey.SecretKeys[j].PublicKey()
			if !bytes.Equal(siaPubKey.Key, pubKey[:]) {
				continue
			}
			sig := types.TransactionSignature{
				ParentID:       parentID,
				CoveredFields:  cf,
				PublicKeyIndex: uint64(i),
			}
			newSigIndices = append(newSigIndices, len(txn.TransactionSignatures))
			txn.TransactionSignatures = append(txn.TransactionSignatures, sig)
			sigIndex := len(txn.TransactionSignatures) - 1
			sigHash := txn.SigHash(sigIndex)
			encodedSig := crypto.SignHash(sigHash, spendKey.SecretKeys[j])
			txn.TransactionSignatures[sigIndex].Signature = encodedSig[:]
			totalSignatures++
			break
		}
		if totalSignatures == uc.SignaturesRequired {
			break
		}
	}
	return newSigIndices
}