mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-28 16:01:29 +00:00
Update unspentOutputs to remove spent unconfirmed outputs
This commit is contained in:
parent
fb7e87b1ef
commit
50da5a9f8c
1 changed files with 25 additions and 14 deletions
|
@ -723,16 +723,12 @@ func (s *Store) markOutputsSpent(spent []Credit, t *TxRecord) (btcutil.Amount, e
|
||||||
op := prev.outPoint()
|
op := prev.outPoint()
|
||||||
switch prev.BlockHeight {
|
switch prev.BlockHeight {
|
||||||
case -1: // unconfirmed
|
case -1: // unconfirmed
|
||||||
op := prev.outPoint()
|
if t.BlockHeight != -1 {
|
||||||
switch prev.BlockHeight {
|
// a confirmed tx cannot spend a previous output from an unconfirmed tx
|
||||||
case -1: // unconfirmed
|
return 0, ErrInconsistentStore
|
||||||
t.s.unconfirmed.spentUnconfirmed[*op] = t.txRecord
|
|
||||||
default:
|
|
||||||
key := prev.outputKey()
|
|
||||||
t.s.unconfirmed.spentBlockOutPointKeys[*op] = key
|
|
||||||
t.s.unconfirmed.spentBlockOutPoints[key] = t.txRecord
|
|
||||||
}
|
}
|
||||||
|
op := prev.outPoint()
|
||||||
|
s.unconfirmed.spentUnconfirmed[*op] = t.txRecord
|
||||||
default:
|
default:
|
||||||
// Update spent info.
|
// Update spent info.
|
||||||
credit := prev.txRecord.credits[prev.OutputIndex]
|
credit := prev.txRecord.credits[prev.OutputIndex]
|
||||||
|
@ -1104,6 +1100,14 @@ func (s *Store) unspentOutputs() ([]Credit, error) {
|
||||||
creditChans[i] <- createdCredit{err: err}
|
creditChans[i] <- createdCredit{err: err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opKey := BlockOutputKey{key, opIndex}
|
||||||
|
_, spent := s.unconfirmed.spentBlockOutPoints[opKey]
|
||||||
|
if spent {
|
||||||
|
close(creditChans[i])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
t := &TxRecord{key, r, s}
|
t := &TxRecord{key, r, s}
|
||||||
c := Credit{t, opIndex}
|
c := Credit{t, opIndex}
|
||||||
creditChans[i] <- createdCredit{credit: c}
|
creditChans[i] <- createdCredit{credit: c}
|
||||||
|
@ -1111,13 +1115,16 @@ func (s *Store) unspentOutputs() ([]Credit, error) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
unspent := make([]Credit, len(s.unspent))
|
unspent := make([]Credit, 0, len(s.unspent))
|
||||||
for i, c := range creditChans {
|
for _, c := range creditChans {
|
||||||
cc := <-c
|
cc, ok := <-c
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if cc.err != nil {
|
if cc.err != nil {
|
||||||
return nil, cc.err
|
return nil, cc.err
|
||||||
}
|
}
|
||||||
unspent[i] = cc.credit
|
unspent = append(unspent, cc.credit)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range s.unconfirmed.txs {
|
for _, r := range s.unconfirmed.txs {
|
||||||
|
@ -1128,9 +1135,13 @@ func (s *Store) unspentOutputs() ([]Credit, error) {
|
||||||
key := BlockTxKey{BlockHeight: -1}
|
key := BlockTxKey{BlockHeight: -1}
|
||||||
txRecord := &TxRecord{key, r, s}
|
txRecord := &TxRecord{key, r, s}
|
||||||
c := Credit{txRecord, uint32(outputIndex)}
|
c := Credit{txRecord, uint32(outputIndex)}
|
||||||
|
op := c.outPoint()
|
||||||
|
_, spent := s.unconfirmed.spentUnconfirmed[*op]
|
||||||
|
if !spent {
|
||||||
unspent = append(unspent, c)
|
unspent = append(unspent, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return unspent, nil
|
return unspent, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue