From dc5d0fe30cf4d10dc028ece5263aa2b748b5d932 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 14 May 2024 10:44:08 -0300 Subject: [PATCH] sweepbatcher: narrow down interface of swapStore Only one method of loopdb.SwapStore is used (FetchLoopOutSwap). Local interface LoopOutFetcher was defined to reflect this. --- sweepbatcher/sweep_batcher.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sweepbatcher/sweep_batcher.go b/sweepbatcher/sweep_batcher.go index 74fa9d25..0de4c3e1 100644 --- a/sweepbatcher/sweep_batcher.go +++ b/sweepbatcher/sweep_batcher.go @@ -82,6 +82,14 @@ type BatcherStore interface { TotalSweptAmount(ctx context.Context, id int32) (btcutil.Amount, error) } +// LoopOutFetcher is used to load LoopOut swaps from the database. +// It is implemented by loopdb.SwapStore. +type LoopOutFetcher interface { + // FetchLoopOutSwap returns the loop out swap with the given hash. + FetchLoopOutSwap(ctx context.Context, + hash lntypes.Hash) (*loopdb.LoopOut, error) +} + // MuSig2SignSweep is a function that can be used to sign a sweep transaction // cooperatively with the swap server. type MuSig2SignSweep func(ctx context.Context, @@ -183,9 +191,8 @@ type Batcher struct { // batcher and the batches. store BatcherStore - // swapStore includes all the database interactions that are needed for - // interacting with swaps. - swapStore loopdb.SwapStore + // swapStore is used to load LoopOut swaps from the database. + swapStore LoopOutFetcher // wg is a waitgroup that is used to wait for all the goroutines to // exit. @@ -197,7 +204,7 @@ func NewBatcher(wallet lndclient.WalletKitClient, chainNotifier lndclient.ChainNotifierClient, signerClient lndclient.SignerClient, musig2ServerSigner MuSig2SignSweep, verifySchnorrSig VerifySchnorrSig, chainparams *chaincfg.Params, - store BatcherStore, swapStore loopdb.SwapStore) *Batcher { + store BatcherStore, swapStore LoopOutFetcher) *Batcher { return &Batcher{ batches: make(map[int32]*batch),