Add func to remove utxos from a UtxoStore.

This commit is contained in:
Josh Rickmar 2013-10-15 10:05:51 -04:00
parent 154a962173
commit 51cb34e50a
2 changed files with 36 additions and 2 deletions

View file

@ -456,7 +456,7 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) {
pairs := map[string]uint64{ pairs := map[string]uint64{
toaddr58: uint64(amt), 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 { if err != nil {
e := InternalError e := InternalError
e.Message = err.Error() e.Message = err.Error()
@ -487,6 +487,7 @@ func SendFrom(reply chan []byte, msg *btcjson.Message) {
_, _ = comment, commentto _, _ = comment, commentto
// TODO(jrick): remove previous unspent outputs now spent by the tx. // TODO(jrick): remove previous unspent outputs now spent by the tx.
_ = inputs
ReplySuccess(reply, msg.Id, result) ReplySuccess(reply, msg.Id, result)
return true return true
@ -579,7 +580,7 @@ func SendMany(reply chan []byte, msg *btcjson.Message) {
TxFee.Lock() TxFee.Lock()
fee := TxFee.i fee := TxFee.i
TxFee.Unlock() TxFee.Unlock()
rawtx, _, err := w.txToPairs(pairs, uint64(fee), int(minconf)) rawtx, inputs, err := w.txToPairs(pairs, uint64(fee), int(minconf))
if err != nil { if err != nil {
e := InternalError e := InternalError
e.Message = err.Error() e.Message = err.Error()
@ -610,6 +611,7 @@ func SendMany(reply chan []byte, msg *btcjson.Message) {
_ = comment _ = comment
// TODO(jrick): remove previous unspent outputs now spent by the tx. // TODO(jrick): remove previous unspent outputs now spent by the tx.
_ = inputs
ReplySuccess(reply, msg.Id, result) ReplySuccess(reply, msg.Id, result)
return true return true

View file

@ -180,6 +180,38 @@ func (u *UtxoStore) Rollback(height int64, hash *btcwire.ShaHash) (modified bool
return 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 // ReadFrom satisifies the io.ReaderFrom interface. A Utxo is read
// from r with the format: // from r with the format:
// //