Пример #1
0
        public async Task <CommandHandlingResult> Handle(StartCashoutCommand command, IEventPublisher publisher)
        {
            var asset = await _assetsService.TryGetAssetAsync(command.AssetId);

            if (asset == null)
            {
                throw new InvalidOperationException("Asset not found");
            }

            if (string.IsNullOrWhiteSpace(asset.BlockchainIntegrationLayerId))
            {
                throw new InvalidOperationException("BlockchainIntegrationLayerId of the asset is not configured");
            }

            if (string.IsNullOrWhiteSpace(asset.BlockchainIntegrationLayerAssetId))
            {
                throw new InvalidOperationException("BlockchainIntegrationLayerAssetId of the asset is not configured");
            }

            var blockchainConfiguration = _blockchainConfigurationProvider.GetConfiguration(asset.BlockchainIntegrationLayerId);

            if (blockchainConfiguration.AreCashoutsDisabled)
            {
                _log.Warning(
                    $"Cashouts for {asset.BlockchainIntegrationLayerId} are disabled",
                    context: command);

                await SendToOpsGenieAsync($"Cashouts for {asset.BlockchainIntegrationLayerId} are disabled",
                                          $"Cashouts for {asset.BlockchainIntegrationLayerId} are disabled, operation Id = {command.OperationId}",
                                          command.ToJson());

                return(CommandHandlingResult.Fail(TimeSpan.FromMinutes(10)));
            }

            publisher.PublishEvent(new ValidationStartedEvent
            {
                OperationId       = command.OperationId,
                ClientId          = command.ClientId,
                AssetId           = asset.Id,
                BlockchainType    = asset.BlockchainIntegrationLayerId,
                BlockchainAssetId = asset.BlockchainIntegrationLayerAssetId,
                HotWalletAddress  = blockchainConfiguration.HotWalletAddress,
                ToAddress         = command.ToAddress,
                Amount            = command.Amount
            });

            return(CommandHandlingResult.Ok());
        }
Пример #2
0
        public async Task <CommandHandlingResult> Handle(AcceptCashoutCommand command, IEventPublisher publisher)
        {
            var blockchainConfiguration = _blockchainConfigurationProvider.GetConfiguration(command.BlockchainType);

            var recipientClientId = !_disableDirectCrossClientCashouts
                ? await _walletsClient.TryGetClientIdAsync(command.BlockchainType, command.ToAddress)
                : null;

            if (recipientClientId.HasValue)
            {
                return(StartCrossClientCashaout(command, publisher, recipientClientId.Value));
            }

            if (blockchainConfiguration.SupportCashoutAggregation)
            {
                return(await StartBatchedCashoutAsync(command, publisher, blockchainConfiguration.CashoutsAggregation));
            }

            return(StartRegularCashout(command, publisher));
        }