Use bitcoin-qt balance/unconfirmed nomenclature.

bitcoin-qt uses "Balance" to mean all spendable outputs that have been
mined into a block, while "Unconfirmed" only refers to outputs that
have not yet been mined into a block.  This change copies that
behavior, instead of the previous required 6 blocks to be confirmed.
This commit is contained in:
Josh Rickmar 2013-10-28 14:10:37 -04:00
parent 851a9d6e41
commit dea80bae9b
2 changed files with 9 additions and 5 deletions

View file

@ -194,7 +194,7 @@ func GetBalance(reply chan []byte, msg *btcjson.Message) {
func GetBalances(reply chan []byte, msg *btcjson.Message) { func GetBalances(reply chan []byte, msg *btcjson.Message) {
wallets.RLock() wallets.RLock()
for _, w := range wallets.m { for _, w := range wallets.m {
balance := w.CalculateBalance(6) balance := w.CalculateBalance(1)
unconfirmed := w.CalculateBalance(0) - balance unconfirmed := w.CalculateBalance(0) - balance
NotifyWalletBalance(reply, w.name, balance) NotifyWalletBalance(reply, w.name, balance)
NotifyWalletBalanceUnconfirmed(reply, w.name, unconfirmed) NotifyWalletBalanceUnconfirmed(reply, w.name, unconfirmed)
@ -411,7 +411,7 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) {
} }
// Notify all frontends of new account balances. // Notify all frontends of new account balances.
confirmed := w.CalculateBalance(6) confirmed := w.CalculateBalance(1)
unconfirmed := w.CalculateBalance(0) - confirmed unconfirmed := w.CalculateBalance(0) - confirmed
NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed) NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed)
NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed) NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed)
@ -566,7 +566,7 @@ func SendMany(reply chan []byte, msg *btcjson.Message) {
} }
// Notify all frontends of new account balances. // Notify all frontends of new account balances.
confirmed := w.CalculateBalance(6) confirmed := w.CalculateBalance(1)
unconfirmed := w.CalculateBalance(0) - confirmed unconfirmed := w.CalculateBalance(0) - confirmed
NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed) NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed)
NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed) NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed)

View file

@ -84,9 +84,13 @@ func selectInputs(s tx.UtxoStore, amt uint64, minconf int) (inputs []*tx.Utxo, b
// Create list of eligible unspent previous outputs to use as tx // Create list of eligible unspent previous outputs to use as tx
// inputs, and sort by the amount in reverse order so a minimum number // inputs, and sort by the amount in reverse order so a minimum number
// of inputs is needed. // of inputs is needed.
var eligible []*tx.Utxo eligible := make([]*tx.Utxo, 0, len(s))
for _, utxo := range s { for _, utxo := range s {
if int(height-utxo.Height) >= minconf { // TODO(jrick): if Height is -1, the UTXO is the result of spending
// to a change address, resulting in a UTXO not yet mined in a block.
// For now, disallow creating transactions until these UTXOs are mined
// into a block and show up as part of the balance.
if utxo.Height != -1 && int(height-utxo.Height) >= minconf {
eligible = append(eligible, utxo) eligible = append(eligible, utxo)
} }
} }