func (u unspentTransactions) Reindex() (int, error) {
	u.Logger.Trace.Println("Reindex UTXO: Prepare")
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return 0, err
	}
	err = uodb.TruncateDB()
	if err != nil {
		return 0, err
	}
	u.Logger.Trace.Println("Reindex UTXO: Prepare done")
	UTXO, err := u.FindunspentTransactions()
	if err != nil {
		return 0, err
	}
	u.Logger.Trace.Println("Reindex UTXO: Store records")
	for txID, outs := range UTXO {
		u.Logger.Trace.Printf("Reindex UTXO: Save %s %d", txID, len(outs))
		key, err := hex.DecodeString(txID)
		if err != nil {
			return 0, err
		}
		outsData, err := u.serializeOutputs(outs)
		if err != nil {
			return 0, err
		}
		err = uodb.PutDataForTransaction(key, outsData)
		if err != nil {
			return 0, err
		}
	}
	u.Logger.Trace.Println("Reindex UTXO: Done. Return counts")
	return u.CountUnspentOutputs()
}
Rebuilds the DB of unspent transactions
NOTE . We don't really need this. Normal code should work without reindexing.
TODO to remove this function in future
package transactions
import (
	"bytes"
	"encoding/gob"
	"encoding/hex"
	"errors"
	"log"
	"sort"
	"github.com/gelembjuk/democoin/lib/utils"
	"github.com/gelembjuk/democoin/lib/wallet"
	"github.com/gelembjuk/democoin/node/blockchain"
	"github.com/gelembjuk/democoin/node/database"
	"github.com/gelembjuk/democoin/node/structures"
)
type unspentTransactions struct {
	DB     database.DBManager
	Logger *utils.LoggerMan
}
func (u unspentTransactions) newTransactionIndex() *transactionsIndex {
	return newTransactionIndex(u.DB, u.Logger)
}
func (u unspentTransactions) serializeOutputs(outs []structures.TXOutputIndependent) ([]byte, error) {
	var buff bytes.Buffer
	enc := gob.NewEncoder(&buff)
	err := enc.Encode(outs)
	if err != nil {
		return nil, err
	}
	return buff.Bytes(), nil
}
func (u unspentTransactions) deserializeOutputs(data []byte) ([]structures.TXOutputIndependent, error) {
	var outputs []structures.TXOutputIndependent
	dec := gob.NewDecoder(bytes.NewReader(data))
	err := dec.Decode(&outputs)
	if err != nil {
		return nil, err
		log.Panic(err)
	}
	return outputs, nil
}
func (u unspentTransactions) GetAddressBalance(address string) (float64, error) {
	if address == "" {
		return 0, errors.New("Address is missed")
	}
	w := wallet.Wallet{}
	if !w.ValidateAddress(address) {
		return 0, errors.New("Address is not valid")
	}
	balance := float64(0)
	UnspentTXs, err2 := u.GetunspentTransactionsOutputs(address)
	if err2 != nil {
		return 0, err2
	}
	for _, out := range UnspentTXs {
		balance += out.Value
	}
	return balance, nil
}
func (u unspentTransactions) GetInputValue(input structures.TXInput) (float64, error) {
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return 0, err
	}
	outsBytes, err := uodb.GetDataForTransaction(input.Txid)
	if err != nil {
		u.Logger.Trace.Printf("Data reading error: %s", err.Error())
		return 0, err
	}
	if outsBytes == nil {
		return 0, NewTXNotFoundUOTError("Input TX is not found in unspent outputs")
	}
	outs, err := u.deserializeOutputs(outsBytes)
	if err != nil {
		return 0, err
	}
	for _, o := range outs {
		if o.OIndex == input.Vout {
			return o.Value, nil
		}
	}
	return 0, errors.New("Output index is not found in unspent outputs")
}
func (u unspentTransactions) ChooseSpendableOutputs(pubKeyHash []byte, amount float64,
	pendinguse []structures.TXInput) (float64, []structures.TXOutputIndependent, error) {
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return 0, nil, err
	}
	unspentOutputs := []structures.TXOutputIndependent{}
	accumulated := float64(0)
	err = uodb.ForEach(func(txID, txData []byte) error {
		outs, err := u.deserializeOutputs(txData)
		if err != nil {
			return err
		}
		for _, out := range outs {
			if out.IsLockedWithKey(pubKeyHash) {
				used := false
				for _, pin := range pendinguse {
					if bytes.Compare(pin.Txid, out.TXID) == 0 &&
						pin.Vout == out.OIndex {
						used = true
						break
					}
				}
				if used {
					continue
				}
				accumulated += out.Value
				unspentOutputs = append(unspentOutputs, out)
			}
		}
		return nil
	})
	if err != nil {
		return 0, nil, err
	}
	if accumulated >= amount {
		sort.Sort(structures.TXOutputIndependentList(unspentOutputs))
		accumulated = 0
		uo := []structures.TXOutputIndependent{}
		for _, out := range unspentOutputs {
			accumulated += out.Value
			uo = append(uo, out)
			if accumulated >= amount {
				break
			}
		}
		unspentOutputs = uo
	}
	return accumulated, unspentOutputs, nil
}
func (u unspentTransactions) forEachUnspentOutput(address string, callback UnspentTransactionOutputCallbackInterface) error {
	pubKeyHash, err := utils.AddresToPubKeyHash(address)
	if err != nil {
		return err
	}
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return err
	}
	err = uodb.ForEach(func(txID, txData []byte) error {
		outs, err := u.deserializeOutputs(txData)
		if err != nil {
			return err
		}
		for _, out := range outs {
			if out.IsLockedWithKey(pubKeyHash) {
				var fromaddr string
				if len(out.SendPubKeyHash) > 0 {
					fromaddr, _ = utils.PubKeyHashToAddres(out.SendPubKeyHash)
				} else {
					fromaddr = "Coin base"
				}
				err := callback(fromaddr, out.Value, out.TXID, out.OIndex, out.IsBase)
				if err != nil {
					return err
				}
			}
		}
		return nil
	})
	if err != nil {
		return err
	}
	return nil
}
func (u unspentTransactions) GetunspentTransactionsOutputs(address string) ([]structures.TXOutputIndependent, error) {
	if address == "" {
		return nil, errors.New("Address is missed")
	}
	w := wallet.Wallet{}
	if !w.ValidateAddress(address) {
		return nil, errors.New("Address is not valid")
	}
	pubKeyHash, err := utils.AddresToPubKeyHash(address)
	if err != nil {
		return nil, err
	}
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return nil, err
	}
	UTXOs := []structures.TXOutputIndependent{}
	err = uodb.ForEach(func(txID, txData []byte) error {
		outs, err := u.deserializeOutputs(txData)
		if err != nil {
			return err
		}
		for _, out := range outs {
			if out.IsLockedWithKey(pubKeyHash) {
				UTXOs = append(UTXOs, out)
			}
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return UTXOs, nil
}
func (u unspentTransactions) CountTransactions() (int, error) {
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return 0, err
	}
	return uodb.GetCount()
}
func (u unspentTransactions) CountUnspentOutputs() (int, error) {
	uodb, err := u.DB.GetUnspentOutputsObject()
	if err != nil {
		return 0, err
	}
	counter := 0
	err = uodb.ForEach(func(txID, txData []byte) error {
		outs, err := u.deserializeOutputs(txData)
		if err != nil {
			return err
		}
		counter += len(outs)
		return nil
	})
	if err != nil {
		return 0, err
	}
	return counter, nil
}