Skip to content

Commit

Permalink
autopilot: use inline const
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Feb 10, 2025
1 parent cd19e70 commit d367e19
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions autopilot/walletmaintainer/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,24 @@ func (w *walletMaintainer) PerformWalletMaintenance(ctx context.Context, cfg api
}
}

// calculate max outputs
// calculate num outputs
const maxOutputs = 100
amount := contractor.InitialContractFunding.Mul64(10)
maxOutputs := balance.Div(amount).Big().Uint64()
if maxOutputs > 100 {
maxOutputs = 100
numOutputs := balance.Div(amount).Big().Uint64()
if numOutputs > maxOutputs {
numOutputs = maxOutputs
}

// check whether the wallet needs to be redistributed
if maxOutputs < 10 {
// skip maintenance if wallet balance is too low
if numOutputs < 10 {
w.logger.Warnf("wallet maintenance skipped, wallet balance %v is too low to redistribute into meaningful outputs", balance)
return nil
}

// redistribute outputs
ids, err := w.bus.WalletRedistribute(ctx, int(maxOutputs), amount)
ids, err := w.bus.WalletRedistribute(ctx, int(numOutputs), amount)
if err != nil {
return fmt.Errorf("failed to redistribute wallet into %d outputs of amount %v, balance %v, err %v", int(maxOutputs), amount, balance, err)
return fmt.Errorf("failed to redistribute wallet into %d outputs of amount %v, balance %v, err %v", int(numOutputs), amount, balance, err)
}

w.logger.Infof("wallet maintenance succeeded, txns %v", ids)
Expand Down

0 comments on commit d367e19

Please sign in to comment.