Skip to content

Commit 1290ebe

Browse files
committed
sweepbatcher: fix copy-paste in sweep creation
1 parent e8384be commit 1290ebe

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

sweepbatcher/sweep_batcher.go

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -799,29 +799,8 @@ func (b *Batcher) writeToErrChan(ctx context.Context, err error) error {
799799
func (b *Batcher) convertSweep(ctx context.Context, dbSweep *dbSweep) (
800800
*sweep, error) {
801801

802-
s, err := b.sweepStore.FetchSweep(ctx, dbSweep.SwapHash)
803-
if err != nil {
804-
return nil, fmt.Errorf("failed to fetch sweep data for %x: %w",
805-
dbSweep.SwapHash[:6], err)
806-
}
807-
808-
return &sweep{
809-
swapHash: dbSweep.SwapHash,
810-
outpoint: dbSweep.Outpoint,
811-
value: dbSweep.Amount,
812-
confTarget: s.ConfTarget,
813-
timeout: s.Timeout,
814-
initiationHeight: s.InitiationHeight,
815-
htlc: s.HTLC,
816-
preimage: s.Preimage,
817-
swapInvoicePaymentAddr: s.SwapInvoicePaymentAddr,
818-
htlcKeys: s.HTLCKeys,
819-
htlcSuccessEstimator: s.HTLCSuccessEstimator,
820-
protocolVersion: s.ProtocolVersion,
821-
isExternalAddr: s.IsExternalAddr,
822-
destAddr: s.DestAddr,
823-
minFeeRate: s.MinFeeRate,
824-
}, nil
802+
return b.loadSweep(ctx, dbSweep.SwapHash, dbSweep.Outpoint,
803+
dbSweep.Amount)
825804
}
826805

827806
// LoopOutFetcher is used to load LoopOut swaps from the database.
@@ -897,16 +876,25 @@ func NewSweepFetcherFromSwapStore(swapStore LoopOutFetcher,
897876
func (b *Batcher) fetchSweep(ctx context.Context,
898877
sweepReq SweepRequest) (*sweep, error) {
899878

900-
s, err := b.sweepStore.FetchSweep(ctx, sweepReq.SwapHash)
879+
return b.loadSweep(ctx, sweepReq.SwapHash, sweepReq.Outpoint,
880+
sweepReq.Value)
881+
}
882+
883+
// loadSweep loads inputs of sweep from the database and from FeeRateProvider
884+
// if needed and returns an assembled sweep object.
885+
func (b *Batcher) loadSweep(ctx context.Context, swapHash lntypes.Hash,
886+
outpoint wire.OutPoint, value btcutil.Amount) (*sweep, error) {
887+
888+
s, err := b.sweepStore.FetchSweep(ctx, swapHash)
901889
if err != nil {
902890
return nil, fmt.Errorf("failed to fetch sweep data for %x: %w",
903-
sweepReq.SwapHash[:6], err)
891+
swapHash[:6], err)
904892
}
905893

906894
return &sweep{
907-
swapHash: sweepReq.SwapHash,
908-
outpoint: sweepReq.Outpoint,
909-
value: sweepReq.Value,
895+
swapHash: swapHash,
896+
outpoint: outpoint,
897+
value: value,
910898
confTarget: s.ConfTarget,
911899
timeout: s.Timeout,
912900
initiationHeight: s.InitiationHeight,

0 commit comments

Comments
 (0)