Skip to content

Commit b9db0bc

Browse files
Address review: named sweeper init, dedupe signingWallets
- newSweeper uses named struct fields so inserting a field can't silently misassign the positional values. - Extract primaryThenFallbacks so the sweeper and adminService share the primary-then-fallbacks ordering instead of duplicating it.
1 parent ded6d98 commit b9db0bc

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

internal/core/application/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func NewAdminService(
9191
// signingWallets returns the wallets to try when signing a sweep, in order: the
9292
// primary wallet first, then any configured fallbacks.
9393
func (a *adminService) signingWallets() []ports.WalletService {
94-
return append([]ports.WalletService{a.walletSvc}, a.walletFallbacks...)
94+
return primaryThenFallbacks(a.walletSvc, a.walletFallbacks)
9595
}
9696

9797
func (a *adminService) Wallet() ports.WalletService {

internal/core/application/sweeper.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,28 @@ func newSweeper(
5252
scheduler ports.SchedulerService,
5353
) *sweeper {
5454
return &sweeper{
55-
wallet, walletFallbacks, repoManager, builder, scheduler,
56-
&sync.Mutex{}, make(map[string]struct{}), nil,
55+
wallet: wallet,
56+
walletFallbacks: walletFallbacks,
57+
repoManager: repoManager,
58+
builder: builder,
59+
scheduler: scheduler,
60+
locker: &sync.Mutex{},
61+
scheduledTasks: make(map[string]struct{}),
5762
}
5863
}
5964

6065
// signingWallets returns the wallets to try when signing a sweep, in order: the
6166
// primary wallet first, then any configured fallbacks.
6267
func (s *sweeper) signingWallets() []ports.WalletService {
63-
return append([]ports.WalletService{s.wallet}, s.walletFallbacks...)
68+
return primaryThenFallbacks(s.wallet, s.walletFallbacks)
69+
}
70+
71+
// primaryThenFallbacks returns the primary wallet followed by the fallbacks — the
72+
// order in which sweep signing is attempted.
73+
func primaryThenFallbacks(
74+
primary ports.WalletService, fallbacks []ports.WalletService,
75+
) []ports.WalletService {
76+
return append([]ports.WalletService{primary}, fallbacks...)
6477
}
6578

6679
// buildAndSignSweepTx builds the sweep transaction once (its destination and fees

0 commit comments

Comments
 (0)