diff --git a/cmdmgr.go b/cmdmgr.go index e8a8db5..c349210 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -456,7 +456,7 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) { pairs := map[string]uint64{ toaddr58: uint64(amt), } - rawtx, _, err := w.txToPairs(pairs, uint64(fee), int(minconf)) + rawtx, inputs, err := w.txToPairs(pairs, uint64(fee), int(minconf)) if err != nil { e := InternalError e.Message = err.Error() @@ -487,6 +487,7 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) { _, _ = comment, commentto // TODO(jrick): remove previous unspent outputs now spent by the tx. + _ = inputs ReplySuccess(reply, msg.Id, result) return true @@ -579,7 +580,7 @@ func SendMany(reply chan []byte, msg *btcjson.Message) { TxFee.Lock() fee := TxFee.i TxFee.Unlock() - rawtx, _, err := w.txToPairs(pairs, uint64(fee), int(minconf)) + rawtx, inputs, err := w.txToPairs(pairs, uint64(fee), int(minconf)) if err != nil { e := InternalError e.Message = err.Error() @@ -610,6 +611,7 @@ func SendMany(reply chan []byte, msg *btcjson.Message) { _ = comment // TODO(jrick): remove previous unspent outputs now spent by the tx. + _ = inputs ReplySuccess(reply, msg.Id, result) return true diff --git a/tx/tx.go b/tx/tx.go index a7564cd..312d8c0 100644 --- a/tx/tx.go +++ b/tx/tx.go @@ -180,6 +180,38 @@ func (u *UtxoStore) Rollback(height int64, hash *btcwire.ShaHash) (modified bool return } +// Remove removes all utxos from toRemove from a UtxoStore. The order +// of utxos in the resulting UtxoStore is unspecified. +func (u *UtxoStore) Remove(toRemove []*Utxo) (modified bool) { + s := *u + + m := make(map[*Utxo]bool) + for _, utxo := range s { + m[utxo] = true + } + + for _, candidate := range toRemove { + if _, ok := m[candidate]; ok { + modified = true + } + delete(m, candidate) + } + + if !modified { + return + } + + s = make([]*Utxo, len(m)) + i := 0 + for utxo := range m { + s[i] = utxo + i++ + } + + *u = s + return +} + // ReadFrom satisifies the io.ReaderFrom interface. A Utxo is read // from r with the format: //