func pickUnspentOutputs(pickUnspentOutputSlice []unspentOutputStruct, value int64) ([]unspentOutputStruct, int64) {
	var unspentOutputStructTemp = unspentOutputStruct{}
	var useUnspentOutputSlice []unspentOutputStruct
	var change int64
	var runningTotal int64
	for _, unspentOutput := range pickUnspentOutputSlice {
		unspentOutputStructTemp.TxID = unspentOutput.TxID
		unspentOutputStructTemp.Value = unspentOutput.Value
		useUnspentOutputSlice = append(useUnspentOutputSlice, unspentOutputStructTemp)
		runningTotal = runningTotal + unspentOutput.Value
		if value < runningTotal {
			change = runningTotal - value
			break
		}
	}
	return useUnspentOutputSlice, change
}
STEP 4 - PICK THE UNSPENT OUTPUTS TO USE
package main
import (
	"encoding/json"
	"fmt"
	"sort"
	"strconv"
	log "github.com/sirupsen/logrus"
)
type blockStruct struct {
	BlockID      int64               `json:"blockID"`
	Transactions []transactionStruct `json:"transactions"`
}
var pendingBlock = blockStruct{}
type blockchainSlice []blockStruct
var blockchain = blockchainSlice{}
type transactionStruct struct {
	TxID    int64           `json:"txID"`
	Inputs  []inputsStruct  `json:"inputs"`
	Outputs []outputsStruct `json:"outputs"`
}
type inputsStruct struct {
	RefTxID   int64  `json:"refTxID"`
	InPubKey  string `json:"inPubKey"`
	Signature string `json:"signature"`
}
type outputsStruct struct {
	OutPubKey string `json:"outPubKey"`
	Value     int64  `json:"value"`
}
type unspentOutputStruct struct {
	TxID  int64 `json:"txID"`
	Value int64 `json:"value"`
}
func checkErr(err error) {
	if err != nil {
		fmt.Printf("Error is %+v\n", err)
		log.Fatal("ERROR:", err)
	}
}
func genesisBlockchain(transactionDataString string) {
	var tempTransaction transactionStruct
	transactionDataByte := []byte(transactionDataString)
	err := json.Unmarshal(transactionDataByte, &tempTransaction)
	checkErr(err)
	var transactionSlice []transactionStruct
	transactionSlice = append(transactionSlice, tempTransaction)
	pendingBlock.BlockID = 0
	pendingBlock.Transactions = transactionSlice
	blockchain = append(blockchain, pendingBlock)
}
func resetPendingBlock() {
	var transactionSlice []transactionStruct
	var transaction transactionStruct
	pendingBlock.BlockID = pendingBlock.BlockID + 1
	transaction.TxID = pendingBlock.Transactions[len(pendingBlock.Transactions)-1].TxID + 1
	transactionSlice = append(transactionSlice, transaction)
	pendingBlock.Transactions = transactionSlice
}
func (trms txRequestMessageSignedStruct) processTransactionRequest() string {
	s := "STEP 1 - MOCK - VERIFY SIGNATURE"
	log.Info("processTransactionRequest()      " + s)
	if !(trms.verifySignature()) {
		return "Signature failed"
	}
	s = "STEP 2 - GET BALANCE AND A LIST OF UNSPENT OUTPUTS"
	log.Info("processTransactionRequest()      " + s)
	balance, unspentOutput := getBalance(trms.TxRequestMessage.SourceAddress)
	s = "STEP 3 - CHECK IF YOU HAVE ENOUGH jeffCoins"
	log.Info("processTransactionRequest()      " + s)
	var value int64
	for _, destinations := range trms.TxRequestMessage.Destinations {
		value = value + destinations.Value
	}
	s = "The balance for " + trms.TxRequestMessage.SourceAddress + " is " + strconv.FormatInt(balance, 10) +
		" and value to remove is " + strconv.FormatInt(value, 10) + " from " + fmt.Sprint(unspentOutput)
	log.Info("processTransactionRequest()      " + s)
	if balance < value {
		return "Not enough money"
	}
	s = "STEP 4 - PICK THE UNSPENT OUTPUTS TO USE AND PROVIDE CHANGE"
	log.Info("processTransactionRequest()      " + s)
	useUnspentOutput, change := pickUnspentOutputs(unspentOutput, value)
	s = "You are using unspent outputs " + fmt.Sprint(useUnspentOutput)
	log.Info("processTransactionRequest()      " + s)
	s = "The change will be " + strconv.FormatInt(change, 10)
	log.Info("processTransactionRequest()      " + s)
	s = "STEP 5 - ADD TRANSACTION to pendingBlock and MAKE CHANGE"
	log.Info("processTransactionRequest()      " + s)
	trms.addTransactionToPendingBlock(useUnspentOutput, change)
	return "Pending"
}
func (trms txRequestMessageSignedStruct) verifySignature() bool {
	if trms.Signature == "Bad" {
		return false
	}
	return true
}
func getBalance(address string) (int64, []unspentOutputStruct) {
	unspentOutputMap := make(map[int64]int64)
	var unspentOutput unspentOutputStruct
	unspentOutputSlice := []unspentOutputStruct{}
	s := "STEP 2.1 - GET UNSPENT OUTPUT TRANSACTIONS  - Make unspentOutputSlice"
	log.Info("getBalance()                     " + s)
	for _, blocks := range blockchain {
		for _, transaction := range blocks.Transactions {
			for _, input := range transaction.Inputs {
				if address == input.InPubKey {
					refTxID := input.RefTxID
					if unspentOutputMap[refTxID] != 0 {
						delete(unspentOutputMap, refTxID)
					}
				}
			}
			for _, output := range transaction.Outputs {
				if address == output.OutPubKey {
					unspentOutputMap[transaction.TxID] = output.Value
				}
			}
		}
	}
	for k, v := range unspentOutputMap {
		unspentOutput = unspentOutputStruct{k, v}
		unspentOutputSlice = append(unspentOutputSlice, unspentOutput)
	}
	sort.Slice(unspentOutputSlice, func(i, j int) bool {
		return unspentOutputSlice[i].TxID < unspentOutputSlice[j].TxID
	})
	s = "STEP 2.2 - GET BALANCE from unspentOutputSlice"
	log.Info("getBalance()                     " + s)
	var balance int64
	balance = 0
	for _, unspentOutput := range unspentOutputSlice {
		balance = balance + unspentOutput.Value
	}
	return balance, unspentOutputSlice
}