Update notifyspent requests to take multiple outpoints.

This commit is contained in:
Josh Rickmar 2014-05-06 08:38:23 -05:00
parent 437b4cbdbe
commit 909091984b
2 changed files with 17 additions and 12 deletions

View file

@ -455,9 +455,7 @@ func (a *Account) Track() {
if err != nil {
log.Errorf("Unable to access unspent outputs: %v", err)
}
for _, txout := range unspent {
ReqSpentUtxoNtfn(txout)
}
ReqSpentUtxoNtfns(unspent)
}
// RescanActiveJob creates a RescanJob for all active addresses in the
@ -651,14 +649,18 @@ func (a *Account) ReqNewTxsForAddress(addr btcutil.Address) {
}
}
// ReqSpentUtxoNtfn sends a message to btcd to request updates for when
// ReqSpentUtxoNtfns sends a message to btcd to request updates for when
// a stored UTXO has been spent.
func ReqSpentUtxoNtfn(c *tx.Credit) {
op := c.OutPoint()
log.Debugf("Requesting spent UTXO notifications for Outpoint hash %s index %d",
op.Hash, op.Index)
func ReqSpentUtxoNtfns(credits []*tx.Credit) {
ops := make([]*btcwire.OutPoint, 0, len(credits))
for _, c := range credits {
op := c.OutPoint()
log.Debugf("Requesting spent UTXO notifications for Outpoint " +
"hash %s index %d", op.Hash, op.Index)
ops = append(ops, op)
}
NotifySpent(CurrentServerConn(), op)
NotifySpent(CurrentServerConn(), ops)
}
// TotalReceived iterates through an account's transaction history, returning the

View file

@ -351,9 +351,12 @@ func NotifyReceived(rpc ServerConn, addrs []string) *btcjson.Error {
// NotifySpent requests notifications for when a transaction is processed which
// spends op.
func NotifySpent(rpc ServerConn, outpoint *btcwire.OutPoint) *btcjson.Error {
op := btcws.NewOutPointFromWire(outpoint)
cmd := btcws.NewNotifySpentCmd(<-NewJSONID, op)
func NotifySpent(rpc ServerConn, outpoints []*btcwire.OutPoint) *btcjson.Error {
ops := make([]btcws.OutPoint, 0, len(outpoints))
for _, op := range outpoints {
ops = append(ops, *btcws.NewOutPointFromWire(op))
}
cmd := btcws.NewNotifySpentCmd(<-NewJSONID, ops)
response := <-rpc.SendRequest(NewServerRequest(cmd))
_, jsonErr := response.FinishUnmarshal(nil)
return jsonErr