mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-14 12:43:03 +02:00
sweepbatcher: auto-increment sweep.ID in StoreMock
This commit is contained in:
parent
09d28b50dd
commit
b7d3bc46f8
1 changed files with 13 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ type StoreMock struct {
|
|||
batches map[int32]dbBatch
|
||||
sweeps map[wire.OutPoint]dbSweep
|
||||
mu sync.Mutex
|
||||
sweepID int32
|
||||
}
|
||||
|
||||
// NewStoreMock instantiates a new mock store.
|
||||
|
|
@ -122,7 +123,18 @@ func (s *StoreMock) UpsertSweep(ctx context.Context, sweep *dbSweep) error {
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
s.sweeps[sweep.Outpoint] = *sweep
|
||||
sweepCopy := *sweep
|
||||
|
||||
if old, exists := s.sweeps[sweep.Outpoint]; exists {
|
||||
// Preserve existing sweep ID.
|
||||
sweepCopy.ID = old.ID
|
||||
} else {
|
||||
// Assign fresh sweep ID.
|
||||
sweepCopy.ID = s.sweepID
|
||||
s.sweepID++
|
||||
}
|
||||
|
||||
s.sweeps[sweep.Outpoint] = sweepCopy
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue