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.
This commit is contained in:
Josh Rickmar 2013-10-15 10:27:54 -04:00
parent 51cb34e50a
commit 2541ffae76

View file

@ -482,14 +482,34 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) {
return true 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 // TODO(jrick): If message succeeded in being sent, save the
// transaction details with comments. // transaction details with comments.
_, _ = comment, commentto _, _ = comment, commentto
// TODO(jrick): remove previous unspent outputs now spent by the tx.
_ = inputs
ReplySuccess(reply, msg.Id, result)
return true return true
} }
replyHandlers.Unlock() replyHandlers.Unlock()
@ -606,14 +626,34 @@ func SendMany(reply chan []byte, msg *btcjson.Message) {
return true 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 // TODO(jrick): If message succeeded in being sent, save the
// transaction details with comments. // transaction details with comments.
_ = comment _ = comment
// TODO(jrick): remove previous unspent outputs now spent by the tx.
_ = inputs
ReplySuccess(reply, msg.Id, result)
return true return true
} }
replyHandlers.Unlock() replyHandlers.Unlock()