public async Task <PaginatedList <Transaction> > GetHistoryAsync(string continuation)
        {
            var operationExecutions = await GetOperationExecutionsAsync();

            var continuationToken = continuation != null
                ? JsonConvert.DeserializeObject <TableContinuationToken>(continuation)
                : null;

            var query = new TableQuery <CashoutBatchEntity>
            {
                TakeCount = 1000
            };
            var response = await _cashoutBatchesTable.ExecuteQuerySegmentedAsync(query, continuationToken);

            var transactions = response.Results
                               .Where(cashoutsBatch => cashoutsBatch.State == CashoutsBatchState.Finished)
                               .SelectMany(cashoutsBatch =>
            {
                var blockchain = _blockchainsProvider.GetByBilIdOrDefault(cashoutsBatch.BlockchainType);

                if (blockchain == null)
                {
                    return(Enumerable.Empty <Transaction>());
                }

                if (!operationExecutions.TryGetValue(cashoutsBatch.BatchId, out var operationExecution))
                {
                    _log.Warning($"Operation execution for cashouts batch {cashoutsBatch.BatchId} not found, skipping");

                    return(Enumerable.Empty <Transaction>());
                }

                if (operationExecution.Result != OperationExecutionResult.Completed &&
                    operationExecution.Result != OperationExecutionResult.Success)
                {
                    return(Enumerable.Empty <Transaction>());
                }

                if (string.IsNullOrWhiteSpace(operationExecution.TransactionHash))
                {
                    _log.Warning($"Transaction hash for cashouts batch {cashoutsBatch.BatchId} is empty, skipping");

                    return(Enumerable.Empty <Transaction>());
                }

                var cashouts = JsonConvert.DeserializeObject <BatchedCashout[]>(cashoutsBatch.Cashouts);

                return(cashouts.Select(cashout => new Transaction
                                       (
                                           blockchain.CryptoCurrency,
                                           operationExecution.TransactionHash,
                                           cashout.ClientId,
                                           cashout.DestinationAddress,
                                           TransactionType.Withdrawal
                                       )));
            })
                               .ToArray();

            return(PaginatedList.From(response.ContinuationToken, transactions));
        }
Esempio n. 2
0
        public async Task <PaginatedList <DepositWallet> > GetWalletsAsync(string continuation)
        {
            var continuationToken = continuation != null
                ? JsonConvert.DeserializeObject <TableContinuationToken>(continuation)
                : null;

            var query = new TableQuery <BlockchainWalletEntity>
            {
                TakeCount = 1000
            };
            var response = await _table.ExecuteQuerySegmentedAsync(query, continuationToken);

            var transactions = response.Results
                               .Select(wallet =>
            {
                var blockchain = _blockchainsProvider.GetByBilIdOrDefault(wallet.IntegrationLayerId);

                if (blockchain == null)
                {
                    return(null);
                }

                return(new DepositWallet
                       (
                           wallet.ClientId,
                           wallet.Address,
                           blockchain.CryptoCurrency
                       ));
            })
                               .Where(x => x != null)
                               .ToArray();

            return(PaginatedList.From(response.ContinuationToken, transactions));
        }
        public async Task <PaginatedList <DepositWallet> > GetWalletsAsync(string continuation)
        {
            if (_collection == null)
            {
                throw new InvalidOperationException("MongoStorage not configured");
            }

            var continuationToken = continuation != null
                ? JsonConvert.DeserializeObject <MongoContinuationToken>(continuation)
                : new MongoContinuationToken
            {
                Skip = 0
            };

            var entities = await _collection.AsQueryable()
                           .Skip(continuationToken.Skip)
                           .Take(1000)
                           .ToListAsync();

            var wallets = entities
                          .Select(wallet =>
            {
                var blockchain = _blockchainsProvider.GetByBilIdOrDefault(wallet.BlockchainType);

                if (blockchain == null)
                {
                    return(null);
                }

                return(new DepositWallet(wallet.ClientId, wallet.Address, blockchain.CryptoCurrency));
            })
                          .Where(wallet => wallet != null)
                          .ToArray();

            var resultContinuationToken = entities.Count < 1000
                ? null
                : new MongoContinuationToken
            {
                Skip = continuationToken.Skip + entities.Count
            };

            return(PaginatedList.From(resultContinuationToken, wallets));
        }
        public async Task <PaginatedList <Transaction> > GetHistoryAsync(string continuation)
        {
            var continuationToken = continuation != null
                ? JsonConvert.DeserializeObject <TableContinuationToken>(continuation)
                : null;

            var query = new TableQuery <CashoutEntity>
            {
                TakeCount = 1000
            };
            var response = await _table.ExecuteQuerySegmentedAsync(query, continuationToken);

            var transactions = response.Results
                               .Where(cashout => cashout.Result == CashoutResult.Success && !string.IsNullOrWhiteSpace(cashout.TransactionHash))
                               .Select(cashout =>
            {
                var blockchain = _blockchainsProvider.GetByBilIdOrDefault(cashout.BlockchainType);

                if (blockchain == null)
                {
                    return(null);
                }

                return(new Transaction
                       (
                           blockchain.CryptoCurrency,
                           cashout.TransactionHash,
                           cashout.ClientId,
                           cashout.ToAddress,
                           TransactionType.Withdrawal
                       ));
            })
                               .Where(x => x != null)
                               .ToArray();

            return(PaginatedList.From(response.ContinuationToken, transactions));
        }