private async Task Handle(CashinEnrolledToMatchingEngineEvent evt, ICommandSender sender)
        {
            var aggregate = await _cashoutRepository.GetAsync(evt.CashoutOperationId);

            var matchingEngineEnrollementMoment = DateTime.UtcNow;

            if (aggregate.OnEnrolledToMatchingEngine(matchingEngineEnrollementMoment))
            {
                if (!aggregate.MatchingEngineEnrollementMoment.HasValue)
                {
                    throw new InvalidOperationException("ME enrollement moment should be not null here");
                }

                sender.SendCommand
                (
                    new NotifyCrossClientCashoutCompletedCommand
                {
                    OperationId       = aggregate.OperationId,
                    ClientId          = aggregate.ClientId,
                    CashinOperationId = aggregate.CashinOperationId,
                    RecipientClientId = aggregate.RecipientClientId,
                    AssetId           = aggregate.AssetId,
                    Amount            = aggregate.Amount,
                    StartMoment       = aggregate.StartMoment,
                    FinishMoment      = aggregate.MatchingEngineEnrollementMoment.Value
                },
                    BlockchainCashoutProcessorBoundedContext.Name
                );

                _chaosKitty.Meow(evt.CashoutOperationId);

                await _cashoutRepository.SaveAsync(aggregate);
            }
        }
        public async Task Handle(CashinEnrolledToMatchingEngineEvent evt)
        {
            var aggregate = await _crossClientCashoutRepository.GetAsync(evt.CashoutOperationId);

            await _deduplicationRepository.TryRemoveAsync(aggregate.CashinOperationId);

            _chaosKitty.Meow(evt.CashoutOperationId);
        }
示例#3
0
        private async Task Handle(CashinEnrolledToMatchingEngineEvent evt, ICommandSender sender)
        {
            var aggregate = await _cashinRepository.GetAsync(evt.OperationId);

            var transitionResult = aggregate.OnEnrolledToMatchingEngine(clientId: evt.ClientId);

            if (transitionResult.ShouldSaveAggregate())
            {
                await _cashinRepository.SaveAsync(aggregate);
            }

            if (transitionResult.ShouldSendCommands())
            {
                if (!aggregate.BalanceBlock.HasValue)
                {
                    throw new InvalidOperationException("Balance block should be not null here");
                }

                if (!aggregate.EnrolledBalanceAmount.HasValue)
                {
                    throw new InvalidOperationException("Enrolled balance amount should be not null here");
                }

                if (!aggregate.OperationAmount.HasValue)
                {
                    throw new InvalidOperationException("Operation amount should be not null here");
                }

                if (!aggregate.IsDustCashin.HasValue)
                {
                    throw new InvalidOperationException("IsDustCashin should be not null here");
                }

                sender.SendCommand
                (
                    new SetEnrolledBalanceCommand
                {
                    BalanceBlock          = aggregate.BalanceBlock.Value,
                    BlockchainAssetId     = aggregate.BlockchainAssetId,
                    BlockchainType        = aggregate.BlockchainType,
                    DepositWalletAddress  = aggregate.DepositWalletAddress,
                    EnrolledBalanceAmount = aggregate.EnrolledBalanceAmount.Value,
                    OperationAmount       = aggregate.OperationAmount.Value,
                    OperationId           = aggregate.OperationId
                },
                    Self
                );

                _chaosKitty.Meow(aggregate.OperationId);
            }
        }