private void ProcessEvent(WalletRevokeEventEntry eventEntry) { var revoke = (WalletEventEntry)_eventHistoryService.FindById(eventEntry.RevokeWalletEventEntryId); decimal oldBalance; decimal newBalance; string revokedPublicKey; switch (revoke) { case WalletDepositEventEntry deposit: revokedPublicKey = deposit.DepositWalletPublicKey; oldBalance = _knownPublicKeyBalances[revokedPublicKey]; newBalance = oldBalance - 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 executed, the expected real wallet balance was not reduced, // so this event only matters on the TradingService side, where it unlocks the user's balance. // This does not revoke consolidation result! return; } if (withdrawal.Executed == false) { // If the withdrawal wasn't executed yet, then this is where it'll get unlocked for deposit UnlockAfterWithdrawal(withdrawal); } revokedPublicKey = withdrawal.WithdrawalSourcePublicKey; oldBalance = _knownPublicKeyBalances[revokedPublicKey]; newBalance = oldBalance + withdrawal.WithdrawalQty + withdrawal.WithdrawalSingleFee; break; default: throw new Exception("Unsupported wallet revoke event type " + revoke.GetType().Name); } _knownPublicKeyBalances[revokedPublicKey] = newBalance; }
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(); }