// CompleteWithdrawal completes the specified withdrawal in a fully separate database transaction
// (do not pass a transaction as context)
// It removes the pending withdrawal, sends the transaction to the network and creates a matching completed withdrawal
CompleteWithdrawal completes the specified withdrawal in a fully separate database transaction
(do not pass a transaction as context)
It removes the pending withdrawal, sends the transaction to the network and creates a matching completed withdrawal
// CompleteWithdrawal completes the specified withdrawal in a fully separate database transaction // ( do not pass a transaction as context ) // It removes the pending withdrawal sends the transaction to the network and creates a matching completed withdrawal
func (w *WithdrawalHandler) CompleteWithdrawal(ctxCtx context.Context, pending *types.PendingWithdrawal) error {
	timing := w.statsClient.NewTiming()
	defer timing.Send("complete_withdrawal")
	ctx, err := BeginTransaction(ctxCtx)
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	defer ctx.Rollback() 
	err = pending.Delete(ctx)
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	done := make(chan struct{})
	var blockHash rpc.BlockHash
	w.collectorAccountQueue <- func(collectorAccount *wallet.Account, _, _ rpc.Client) {
		blockHash, err = collectorAccount.Send(pending.RewardsAddress, pending.Amount.BigInt())
		done <- struct{}{}
	}
	<-done
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	withdrawal := &types.Withdrawal{
		TxHash:         blockHash.String(),
		RewardsAddress: pending.RewardsAddress,
		Amount:         pending.Amount,
		StartedAt:      pending.StartedAt,
		CompletedAt:    time.Now(),
	}
	err = withdrawal.Insert(ctx)
	if err != nil {
		return stacktrace.Propagate(err, "")
	}
	return stacktrace.Propagate(ctx.Commit(), "")
}
func ( w * WithdrawalHandler ) CompleteWithdrawal ( ctxCtx context . Context , pending * types . PendingWithdrawal ) error { timing := w . statsClient . NewTiming ( ) defer timing . Send ( " " ) ctx , err := BeginTransaction ( ctxCtx ) if err != nil { return stacktrace . Propagate ( err , " " ) } defer ctx . Rollback ( ) err = pending . Delete ( ctx ) if err != nil { return stacktrace . Propagate ( err , " " ) } done := make ( chan struct { } ) var blockHash rpc . BlockHash w . collectorAccountQueue <- func ( collectorAccount * wallet . Account , _ , _ rpc . Client ) { blockHash , err = collectorAccount . Send ( pending . RewardsAddress , pending . Amount . BigInt ( ) ) done <- struct { } { } } <- done if err != nil { return stacktrace . Propagate ( err , " " ) } withdrawal := & types . Withdrawal { TxHash : blockHash . String ( ) , RewardsAddress : pending . RewardsAddress , Amount : pending . Amount , StartedAt : pending . StartedAt , CompletedAt : time . Now ( ) , } err = withdrawal . Insert ( ctx ) if err != nil { return stacktrace . Propagate ( err , " " ) } return stacktrace . Propagate ( ctx . Commit ( ) , " " ) }
CompleteWithdrawal completes the specified withdrawal in a fully separate database transaction
(do not pass a transaction as context)
It removes the pending withdrawal, sends the transaction to the network and creates a matching completed withdrawal
CompleteWithdrawal completes the specified withdrawal in a fully separate database transaction ( do not pass a transaction as context ) It removes the pending withdrawal sends the transaction to the network and creates a matching completed withdrawal
// if things go wrong, the delete of the pending_withdrawal is rolled back // this call will error if the pending withdrawal no longer exists (avoids double spends)