Skip to content

Commit 7a7ea05

Browse files
committed
sweepbatcher/Store: do not provide LoopOut field
This data is not used by Batcher since commit "sweepbatcher: load swap from loopdb, not own store". Now sweepbatcher.Store depends only on tables sweeps and sweep_batches and does not depend on swaps, loopout_swaps and htlc_keys, making it easier to reuse.
1 parent 4be69e1 commit 7a7ea05

File tree

4 files changed

+14
-152
lines changed

4 files changed

+14
-152
lines changed

loopdb/sqlc/batch.sql.go

Lines changed: 6 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/queries/batch.sql

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,13 @@ AND
9191

9292
-- name: GetBatchSweeps :many
9393
SELECT
94-
sweeps.*,
95-
swaps.*,
96-
loopout_swaps.*,
97-
htlc_keys.*
94+
*
9895
FROM
9996
sweeps
100-
JOIN
101-
swaps ON sweeps.swap_hash = swaps.swap_hash
102-
JOIN
103-
loopout_swaps ON sweeps.swap_hash = loopout_swaps.swap_hash
104-
JOIN
105-
htlc_keys ON sweeps.swap_hash = htlc_keys.swap_hash
10697
WHERE
107-
sweeps.batch_id = $1
98+
batch_id = $1
10899
ORDER BY
109-
sweeps.id ASC;
100+
id ASC;
110101

111102
-- name: GetSweepStatus :one
112103
SELECT

sweepbatcher/store.go

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type BaseDB interface {
2121

2222
// GetBatchSweeps fetches all the sweeps that are part a batch.
2323
GetBatchSweeps(ctx context.Context, batchID int32) (
24-
[]sqlc.GetBatchSweepsRow, error)
24+
[]sqlc.Sweep, error)
2525

2626
// GetBatchSweptAmount returns the total amount of sats swept by a
2727
// (confirmed) batch.
@@ -34,10 +34,6 @@ type BaseDB interface {
3434
GetParentBatch(ctx context.Context, swapHash []byte) (sqlc.SweepBatch,
3535
error)
3636

37-
// GetSwapUpdates fetches all the updates for a swap.
38-
GetSwapUpdates(ctx context.Context, swapHash []byte) (
39-
[]sqlc.SwapUpdate, error)
40-
4137
// GetUnconfirmedBatches fetches all the batches from the
4238
// database that are not in a confirmed state.
4339
GetUnconfirmedBatches(ctx context.Context) ([]sqlc.SweepBatch, error)
@@ -154,14 +150,7 @@ func (s *SQLStore) FetchBatchSweeps(ctx context.Context, id int32) (
154150
}
155151

156152
for _, dbSweep := range dbSweeps {
157-
updates, err := s.baseDb.GetSwapUpdates(
158-
ctx, dbSweep.SwapHash,
159-
)
160-
if err != nil {
161-
return err
162-
}
163-
164-
sweep, err := s.convertSweepRow(dbSweep, updates)
153+
sweep, err := s.convertSweepRow(dbSweep)
165154
if err != nil {
166155
return err
167156
}
@@ -260,9 +249,6 @@ type dbSweep struct {
260249

261250
// Completed indicates whether this sweep is completed.
262251
Completed bool
263-
264-
// LoopOut is the loop out that the sweep belongs to.
265-
LoopOut *loopdb.LoopOut
266252
}
267253

268254
// convertBatchRow converts a batch row from db to a sweepbatcher.Batch struct.
@@ -354,9 +340,7 @@ func batchToUpdateArgs(batch dbBatch) sqlc.UpdateBatchParams {
354340
}
355341

356342
// convertSweepRow converts a sweep row from db to a sweep struct.
357-
func (s *SQLStore) convertSweepRow(row sqlc.GetBatchSweepsRow,
358-
updates []sqlc.SwapUpdate) (dbSweep, error) {
359-
343+
func (s *SQLStore) convertSweepRow(row sqlc.Sweep) (dbSweep, error) {
360344
sweep := dbSweep{
361345
ID: row.ID,
362346
BatchID: row.BatchID,
@@ -380,40 +364,7 @@ func (s *SQLStore) convertSweepRow(row sqlc.GetBatchSweepsRow,
380364
Index: uint32(row.OutpointIndex),
381365
}
382366

383-
sweep.LoopOut, err = loopdb.ConvertLoopOutRow(
384-
s.network,
385-
sqlc.GetLoopOutSwapRow{
386-
ID: row.ID,
387-
SwapHash: row.SwapHash,
388-
Preimage: row.Preimage,
389-
InitiationTime: row.InitiationTime,
390-
AmountRequested: row.AmountRequested,
391-
CltvExpiry: row.CltvExpiry,
392-
MaxMinerFee: row.MaxMinerFee,
393-
MaxSwapFee: row.MaxSwapFee,
394-
InitiationHeight: row.InitiationHeight,
395-
ProtocolVersion: row.ProtocolVersion,
396-
Label: row.Label,
397-
DestAddress: row.DestAddress,
398-
SwapInvoice: row.SwapInvoice,
399-
MaxSwapRoutingFee: row.MaxSwapRoutingFee,
400-
SweepConfTarget: row.SweepConfTarget,
401-
HtlcConfirmations: row.HtlcConfirmations,
402-
OutgoingChanSet: row.OutgoingChanSet,
403-
PrepayInvoice: row.PrepayInvoice,
404-
MaxPrepayRoutingFee: row.MaxPrepayRoutingFee,
405-
PublicationDeadline: row.PublicationDeadline,
406-
SingleSweep: row.SingleSweep,
407-
SenderScriptPubkey: row.SenderScriptPubkey,
408-
ReceiverScriptPubkey: row.ReceiverScriptPubkey,
409-
SenderInternalPubkey: row.SenderInternalPubkey,
410-
ReceiverInternalPubkey: row.ReceiverInternalPubkey,
411-
ClientKeyFamily: row.ClientKeyFamily,
412-
ClientKeyIndex: row.ClientKeyIndex,
413-
}, updates,
414-
)
415-
416-
return sweep, err
367+
return sweep, nil
417368
}
418369

419370
// sweepToUpsertArgs converts a Sweep struct to the arguments needed to insert.

0 commit comments

Comments
 (0)