From 2541ffae7682a6e8ca41b21cb58d2f897e8913e6 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 15 Oct 2013 10:27:54 -0400 Subject: [PATCH] Update account UtxoStore after creating transactions. This removes inputs spent by a transaction from the stored UTXOs. If the UtxoStore is modified, all frontends are notified of the new confirmed and unconfirmed account balances. More work must be done later to check that the transaction actually does occur in a later block. btcd will make a best try effort to relay the tx to the network, but it is still ultimately btcwallet's responsibility. Added a TODO so I remember to do this in the future. --- cmdmgr.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/cmdmgr.go b/cmdmgr.go index c349210..8285b97 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -482,14 +482,34 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) { return true } + // TODO(jrick): btcd cannot be trusted to successfully relay the + // tx to the Bitcoin network. Even if this succeeds, the rawtx + // must be saved and checked for if it exists in a later block. + // btcd will make a best try effort, but ultimately it's + // btcwallet's responsibility. + + // Remove previous unspent outputs now spent by the tx. + w.UtxoStore.Lock() + modified := w.UtxoStore.s.Remove(inputs) + if modified { + w.UtxoStore.dirty = true + w.UtxoStore.Unlock() + + // Notify all frontends of new account balances. + confirmed := w.CalculateBalance(6) + unconfirmed := w.CalculateBalance(0) - confirmed + NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed) + NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed) + } else { + w.UtxoStore.Unlock() + } + + ReplySuccess(reply, msg.Id, result) + // TODO(jrick): If message succeeded in being sent, save the // transaction details with comments. _, _ = comment, commentto - // TODO(jrick): remove previous unspent outputs now spent by the tx. - _ = inputs - - ReplySuccess(reply, msg.Id, result) return true } replyHandlers.Unlock() @@ -606,14 +626,34 @@ func SendMany(reply chan []byte, msg *btcjson.Message) { return true } + // TODO(jrick): btcd cannot be trusted to successfully relay the + // tx to the Bitcoin network. Even if this succeeds, the rawtx + // must be saved and checked for if it exists in a later block. + // btcd will make a best try effort, but ultimately it's + // btcwallet's responsibility. + + // Remove previous unspent outputs now spent by the tx. + w.UtxoStore.Lock() + modified := w.UtxoStore.s.Remove(inputs) + if modified { + w.UtxoStore.dirty = true + w.UtxoStore.Unlock() + + // Notify all frontends of new account balances. + confirmed := w.CalculateBalance(6) + unconfirmed := w.CalculateBalance(0) - confirmed + NotifyWalletBalance(frontendNotificationMaster, w.name, confirmed) + NotifyWalletBalanceUnconfirmed(frontendNotificationMaster, w.name, unconfirmed) + } else { + w.UtxoStore.Unlock() + } + + ReplySuccess(reply, msg.Id, result) + // TODO(jrick): If message succeeded in being sent, save the // transaction details with comments. _ = comment - // TODO(jrick): remove previous unspent outputs now spent by the tx. - _ = inputs - - ReplySuccess(reply, msg.Id, result) return true } replyHandlers.Unlock()