Example #1
0
        private async Task Handle(BlockchainOperationsExecutor.Contract.Events.OperationExecutionCompletedEvent evt, ICommandSender sender)
        {
            var aggregate = await _cashoutRepository.TryGetAsync(evt.OperationId);

            if (aggregate == null)
            {
                // This is not a cashout operation
                return;
            }

            var operationFinishMoment = DateTime.UtcNow;

            if (aggregate.OnOperationCompleted(evt.TransactionHash, evt.TransactionAmount, evt.Fee, operationFinishMoment))
            {
                if (!aggregate.TransactionAmount.HasValue)
                {
                    throw new InvalidOperationException("Transaction amount should be not null here");
                }

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

                sender.SendCommand
                (
                    new NotifyCashoutCompletedCommand
                {
                    Amount            = aggregate.Amount,
                    TransactionAmount = aggregate.TransactionAmount.Value,
                    TransactionFee    = aggregate.Fee.Value,
                    AssetId           = aggregate.AssetId,
                    ClientId          = aggregate.ClientId,
                    ToAddress         = aggregate.ToAddress,
                    OperationId       = aggregate.OperationId,
                    TransactionHash   = aggregate.TransactionHash,
                    StartMoment       = aggregate.StartMoment,
                    FinishMoment      = operationFinishMoment
                },
                    CqrsModule.Self
                );

                _chaosKitty.Meow(evt.OperationId);

                await _cashoutRepository.SaveAsync(aggregate);
            }
        }
        public async Task Handle(BlockchainOperationsExecutor.Contract.Events.OperationExecutionCompletedEvent evt)
        {
            await _deduplicationRepository.TryRemoveAsync(evt.OperationId);

            _chaosKitty.Meow(evt.OperationId);
        }