private void ProcessEvent(WalletWithdrawalEventEntry eventEntry)
        {
            // We cannot reduce our cached balance, unlocking it for detection as a deposit,
            // until we are sure the withdrawal is valid and it has been executed in a previous service run
            while (eventEntry.Validated == null)
            {
                _logger.LogWarning(
                    $"Withdrawal event {eventEntry.Id} is not validated by Trading Service yet, waiting...");
                Task.Delay(1000).Wait();
                eventEntry = (WalletWithdrawalEventEntry)_eventHistoryService.FindById(eventEntry.Id);
            }

            if (eventEntry.Validated == false)
            {
                return;
            }

            OnWithdrawal(eventEntry);

            if (eventEntry.Executed)
            {
                // We only process the balance unlock for deposit if it isn't being executed in this service run
                UnlockAfterWithdrawal(eventEntry);
            }
        }
Exemplo n.º 2
0
        public void ProcessEvent(WalletRevokeEventEntry eventEntry)
        {
            var relativeBalance = 0m;
            var revoked         = _eventHistoryService.FindById(eventEntry.RevokeWalletEventEntryId);

            switch (revoked)
            {
            case WalletDepositEventEntry deposit:
                relativeBalance = -deposit.DepositQty;
                break;

            case WalletWithdrawalEventEntry withdrawal:
                if (withdrawal.Validated == null)
                {
                    throw new Exception(
                              "Fatal error: revocation of withdrawal event was allowed to start being processed without the Validated flag being set at all, the processing order is probably wrong");
                }

                if (withdrawal.Validated == false)
                {
                    // Not revoking event that was not processed; Validated withdrawals are guaranteed to be done
                    return;
                }

                relativeBalance = withdrawal.WithdrawalQty;
                break;

            default:
                throw new NotImplementedException();
            }

            _userService.ModifyBalance(
                eventEntry.User,
                eventEntry.AccountId,
                eventEntry.CoinSymbol,
                relativeBalance
                ).Wait();
        }