From dea80bae9b230744441a5e0a72f3c98085e6847d Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 28 Oct 2013 14:10:37 -0400 Subject: [PATCH] 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. --- cmdmgr.go | 6 +++--- createtx.go | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmdmgr.go b/cmdmgr.go index 93b446d..b607eaf 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -194,7 +194,7 @@ func GetBalance(reply chan []byte, msg *btcjson.Message) { func GetBalances(reply chan []byte, msg *btcjson.Message) { wallets.RLock() for _, w := range wallets.m { - balance := w.CalculateBalance(6) + balance := w.CalculateBalance(1) unconfirmed := w.CalculateBalance(0) - balance NotifyWalletBalance(reply, w.name, balance) NotifyWalletBalanceUnconfirmed(reply, w.name, unconfirmed) @@ -411,7 +411,7 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) { } // Notify all frontends of new account balances. - confirmed := w.CalculateBalance(6) + confirmed := w.CalculateBalance(1) unconfirmed := w.CalculateBalance(0) - confirmed NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed) NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed) @@ -566,7 +566,7 @@ func SendMany(reply chan []byte, msg *btcjson.Message) { } // Notify all frontends of new account balances. - confirmed := w.CalculateBalance(6) + confirmed := w.CalculateBalance(1) unconfirmed := w.CalculateBalance(0) - confirmed NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed) NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed) diff --git a/createtx.go b/createtx.go index 191b812..6c6844a 100644 --- a/createtx.go +++ b/createtx.go @@ -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 // inputs, and sort by the amount in reverse order so a minimum number // of inputs is needed. - var eligible []*tx.Utxo + eligible := make([]*tx.Utxo, 0, len(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) } }