// WithdrawBalances initiates withdraws for the specified balances
WithdrawBalances initiates withdraws for the specified balances
// WithdrawBalances initiates withdraws for the specified balances
func (w *WithdrawalHandler) WithdrawBalances(ctxCtx context.Context, balances []*types.RewardBalance) error {
	if len(balances) == 0 {
		return nil
	}
	ctx, err := BeginTransaction(ctxCtx)
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	defer ctx.Rollback()
	now := time.Now()
	pendingWithdrawals := make([]*types.PendingWithdrawal, len(balances))
	userAccounts := make([]string, len(balances))
	for i, balance := range balances {
		pendingWithdrawals[i] = &types.PendingWithdrawal{
			RewardsAddress: balance.RewardsAddress,
			Amount:         balance.Balance,
			StartedAt:      now,
		}
		userAccounts[i] = balance.RewardsAddress
	}
	err = types.ZeroRewardBalanceOfAddresses(ctx, userAccounts)
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	err = types.InsertPendingWithdrawals(ctx, pendingWithdrawals)
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	ctx.DeferToCommit(func() { w.pendingWithdrawalCreated.Notify(pendingWithdrawals) })
	return stacktrace.Propagate(ctx.Commit(), "")
}
func ( w * WithdrawalHandler ) WithdrawBalances ( ctxCtx context . Context , balances [ ] * types . RewardBalance ) error { if len ( balances ) == 0 { return nil } ctx , err := BeginTransaction ( ctxCtx ) if err != nil { return stacktrace . Propagate ( err , " " ) } defer ctx . Rollback ( ) now := time . Now ( ) pendingWithdrawals := make ( [ ] * types . PendingWithdrawal , len ( balances ) ) userAccounts := make ( [ ] string , len ( balances ) ) for i , balance := range balances { pendingWithdrawals [ i ] = & types . PendingWithdrawal { RewardsAddress : balance . RewardsAddress , Amount : balance . Balance , StartedAt : now , } userAccounts [ i ] = balance . RewardsAddress } err = types . ZeroRewardBalanceOfAddresses ( ctx , userAccounts ) if err != nil { return stacktrace . Propagate ( err , " " ) } err = types . InsertPendingWithdrawals ( ctx , pendingWithdrawals ) if err != nil { return stacktrace . Propagate ( err , " " ) } ctx . DeferToCommit ( func ( ) { w . pendingWithdrawalCreated . Notify ( pendingWithdrawals ) } ) return stacktrace . Propagate ( ctx . Commit ( ) , " " ) }
WithdrawBalances initiates withdraws for the specified balances
WithdrawBalances initiates withdraws for the specified balances