func fetchMinedBalance(ns walletdb.ReadBucket) (dcrutil.Amount, error) {
	v := ns.Get(rootMinedBalance)
	if len(v) != 8 {
		return 0, errors.E(errors.IO, errors.Errorf("mined balance len %d", len(v)))
	}
	return dcrutil.Amount(byteOrder.Uint64(v)), nil
}
The root bucket's mined balance k/v pair records the total balance for all
unspent credits from mined transactions.  This includes immature outputs, and
outputs spent by mempool transactions, which must be considered when
returning the actual balance for a given number of block confirmations.  The
value is the amount serialized as a uint64.
package udb
import (
	"bytes"
	"encoding/binary"
	"runtime/debug"
	"time"
	"decred.org/dcrwallet/v2/errors"
	"decred.org/dcrwallet/v2/wallet/walletdb"
	"github.com/decred/dcrd/blockchain/stake/v4"
	"github.com/decred/dcrd/chaincfg/chainhash"
	"github.com/decred/dcrd/chaincfg/v3"
	"github.com/decred/dcrd/crypto/ripemd160"
	"github.com/decred/dcrd/dcrutil/v4"
	"github.com/decred/dcrd/txscript/v4"
	"github.com/decred/dcrd/wire"
)
const (
	accountExistsMask = uint8(0x80)
)
type scriptType uint8
const (
	scriptTypeNonexisting = iota
	scriptTypeUnspecified
	scriptTypeP2PKH
	scriptTypeP2PK
	scriptTypeP2PKHAlt
	scriptTypeP2PKAlt
	scriptTypeP2SH
	scriptTypeSP2PKH
	scriptTypeSP2SH
)
const (
	scriptLocNotStored = 0
)
var byteOrder = binary.BigEndian
var _ [32]byte = chainhash.Hash{}
var (
	bucketBlocks                  = []byte("b")
	bucketHeaders                 = []byte("h")
	bucketTxRecords               = []byte("t")
	bucketCredits                 = []byte("c")
	bucketUnspent                 = []byte("u")
	bucketDebits                  = []byte("d")
	bucketUnmined                 = []byte("m")
	bucketUnpublished             = []byte("up")
	bucketUnminedCredits          = []byte("mc")
	bucketUnminedInputs           = []byte("mi")
	bucketTickets                 = []byte("tix")
	bucketScripts                 = []byte("sc")  
	bucketMultisig                = []byte("ms")
	bucketMultisigUsp             = []byte("mu")
	bucketStakeInvalidatedCredits = []byte("ic")
	bucketStakeInvalidatedDebits  = []byte("id")
	bucketCFilters                = []byte("cf")
	bucketTicketCommitments       = []byte("cmt")
	bucketTicketCommitmentsUsp    = []byte("cmu")
)
var (
	rootCreateDate   = []byte("date")
	rootVersion      = []byte("vers")
	rootMinedBalance = []byte("bal")
	rootTipBlock     = []byte("tip")
	rootHaveCFilters = []byte("havecfilters")
	rootLastTxsBlock = []byte("lasttxsblock")
	rootVSPHostIndex = []byte("vsphostindex")
)