|
|
@ -3,6 +3,7 @@ package sweepbatcher
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
|
@ -46,6 +47,9 @@ type BaseDB interface {
|
|
|
|
InsertBatch(ctx context.Context, arg sqlc.InsertBatchParams) (
|
|
|
|
InsertBatch(ctx context.Context, arg sqlc.InsertBatchParams) (
|
|
|
|
int32, error)
|
|
|
|
int32, error)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DropBatch drops a batch from the database.
|
|
|
|
|
|
|
|
DropBatch(ctx context.Context, id int32) error
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateBatch updates a batch in the database.
|
|
|
|
// UpdateBatch updates a batch in the database.
|
|
|
|
UpdateBatch(ctx context.Context, arg sqlc.UpdateBatchParams) error
|
|
|
|
UpdateBatch(ctx context.Context, arg sqlc.UpdateBatchParams) error
|
|
|
|
|
|
|
|
|
|
|
@ -108,6 +112,24 @@ func (s *SQLStore) InsertSweepBatch(ctx context.Context, batch *dbBatch) (int32,
|
|
|
|
return s.baseDb.InsertBatch(ctx, batchToInsertArgs(*batch))
|
|
|
|
return s.baseDb.InsertBatch(ctx, batchToInsertArgs(*batch))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DropBatch drops a batch from the database. Note that we only use this call
|
|
|
|
|
|
|
|
// for batches that have no sweeps and so we'd not be able to resume.
|
|
|
|
|
|
|
|
func (s *SQLStore) DropBatch(ctx context.Context, id int32) error {
|
|
|
|
|
|
|
|
readOpts := loopdb.NewSqlReadOpts()
|
|
|
|
|
|
|
|
return s.baseDb.ExecTx(ctx, readOpts, func(tx *sqlc.Queries) error {
|
|
|
|
|
|
|
|
dbSweeps, err := tx.GetBatchSweeps(ctx, id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(dbSweeps) != 0 {
|
|
|
|
|
|
|
|
return fmt.Errorf("cannot drop a non-empty batch")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tx.DropBatch(ctx, id)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UpdateSweepBatch updates a batch in the database.
|
|
|
|
// UpdateSweepBatch updates a batch in the database.
|
|
|
|
func (s *SQLStore) UpdateSweepBatch(ctx context.Context, batch *dbBatch) error {
|
|
|
|
func (s *SQLStore) UpdateSweepBatch(ctx context.Context, batch *dbBatch) error {
|
|
|
|
return s.baseDb.UpdateBatch(ctx, batchToUpdateArgs(*batch))
|
|
|
|
return s.baseDb.UpdateBatch(ctx, batchToUpdateArgs(*batch))
|
|
|
|