Skip to content

Commit 59f67de

Browse files
authored
Merge pull request #919 from starius/conf-chan
sweepbatcher: notify caller about confirmations
2 parents 80828c2 + c70257a commit 59f67de

File tree

7 files changed

+685
-184
lines changed

7 files changed

+685
-184
lines changed

sweepbatcher/store.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ type dbBatch struct {
213213
// ID is the unique identifier of the batch.
214214
ID int32
215215

216-
// State is the current state of the batch.
217-
State string
216+
// Confirmed is set when the batch is fully confirmed.
217+
Confirmed bool
218218

219219
// BatchTxid is the txid of the batch transaction.
220220
BatchTxid chainhash.Hash
@@ -255,11 +255,8 @@ type dbSweep struct {
255255
// convertBatchRow converts a batch row from db to a sweepbatcher.Batch struct.
256256
func convertBatchRow(row sqlc.SweepBatch) *dbBatch {
257257
batch := dbBatch{
258-
ID: row.ID,
259-
}
260-
261-
if row.Confirmed {
262-
batch.State = batchOpen
258+
ID: row.ID,
259+
Confirmed: row.Confirmed,
263260
}
264261

265262
if row.BatchTxID.Valid {
@@ -288,7 +285,7 @@ func convertBatchRow(row sqlc.SweepBatch) *dbBatch {
288285
// it into the database.
289286
func batchToInsertArgs(batch dbBatch) sqlc.InsertBatchParams {
290287
args := sqlc.InsertBatchParams{
291-
Confirmed: false,
288+
Confirmed: batch.Confirmed,
292289
BatchTxID: sql.NullString{
293290
Valid: true,
294291
String: batch.BatchTxid.String(),
@@ -305,10 +302,6 @@ func batchToInsertArgs(batch dbBatch) sqlc.InsertBatchParams {
305302
MaxTimeoutDistance: batch.MaxTimeoutDistance,
306303
}
307304

308-
if batch.State == batchConfirmed {
309-
args.Confirmed = true
310-
}
311-
312305
return args
313306
}
314307

@@ -317,7 +310,7 @@ func batchToInsertArgs(batch dbBatch) sqlc.InsertBatchParams {
317310
func batchToUpdateArgs(batch dbBatch) sqlc.UpdateBatchParams {
318311
args := sqlc.UpdateBatchParams{
319312
ID: batch.ID,
320-
Confirmed: false,
313+
Confirmed: batch.Confirmed,
321314
BatchTxID: sql.NullString{
322315
Valid: true,
323316
String: batch.BatchTxid.String(),
@@ -333,10 +326,6 @@ func batchToUpdateArgs(batch dbBatch) sqlc.UpdateBatchParams {
333326
},
334327
}
335328

336-
if batch.State == batchConfirmed {
337-
args.Confirmed = true
338-
}
339-
340329
return args
341330
}
342331

sweepbatcher/store_mock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (s *StoreMock) FetchUnconfirmedSweepBatches(ctx context.Context) (
3636

3737
result := []*dbBatch{}
3838
for _, batch := range s.batches {
39-
if batch.State != "confirmed" {
39+
if !batch.Confirmed {
4040
result = append(result, &batch)
4141
}
4242
}
@@ -91,7 +91,7 @@ func (s *StoreMock) ConfirmBatch(ctx context.Context, id int32) error {
9191
return errors.New("batch not found")
9292
}
9393

94-
batch.State = "confirmed"
94+
batch.Confirmed = true
9595
s.batches[batch.ID] = batch
9696

9797
return nil
@@ -201,7 +201,7 @@ func (s *StoreMock) TotalSweptAmount(ctx context.Context, batchID int32) (
201201
return 0, errors.New("batch not found")
202202
}
203203

204-
if batch.State != batchConfirmed && batch.State != batchClosed {
204+
if !batch.Confirmed {
205205
return 0, nil
206206
}
207207

@@ -212,5 +212,5 @@ func (s *StoreMock) TotalSweptAmount(ctx context.Context, batchID int32) (
212212
}
213213
}
214214

215-
return 0, nil
215+
return total, nil
216216
}

0 commit comments

Comments
 (0)