From 909091984bf5c74d1de0ca6552cf8ffb70461bda Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 6 May 2014 08:38:23 -0500 Subject: [PATCH] Update notifyspent requests to take multiple outpoints. --- account.go | 20 +++++++++++--------- rpcclient.go | 9 ++++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/account.go b/account.go index d197571..30851f5 100644 --- a/account.go +++ b/account.go @@ -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 diff --git a/rpcclient.go b/rpcclient.go index 1259e80..c28e589 100644 --- a/rpcclient.go +++ b/rpcclient.go @@ -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