public async Task ProcessAsync(int batchSize)
        {
            int skip = 0;
            var balancesFromDatabase = new List <EnrolledBalance>();

            do
            {
                var received =
                    (await _enrolledBalanceRepository.GetAllForBlockchainAsync(_blockchainId, 0, 100))
                    ?.ToList();

                if (received == null || !received.Any())
                {
                    break;
                }

                balancesFromDatabase.AddRange(received);

                skip += received.Count();

                if (received.Count() < 100)
                {
                    break;
                }
            } while (true);

            var balancesFromApi = new Dictionary <(string AssetId, string Address), WalletBalance>();
            await _blockchainApiClient.EnumerateWalletBalanceBatchesAsync(
                batchSize,
                assetId => GetAssetAccuracy(assetId, batchSize),
                batch =>
            {
                if (batch != null && batch.Any())
                {
                    foreach (var item in batch)
                    {
                        balancesFromApi[(item.AssetId, item.Address.ToLower(CultureInfo.InvariantCulture))] = item;
                    }
Exemple #2
0
        public override async Task <BalanceResponses> GetAllBalancesForBlockchain(GetAllBalancesForBlockchainRequest request, ServerCallContext context)
        {
            var balances =
                await _enrolledBalanceRepository.GetAllForBlockchainAsync(request.BlockchainId, request.Skip, request.Take);

            var response = new BalanceResponses();

            if (balances != null && balances.Any())
            {
                response.Balances.AddRange(balances.Select(x => new BalanceResponse()
                {
                    Block     = x.Block,
                    Balance   = x.Balance.ToString(),
                    WalletKey = new WalletKey()
                    {
                        BlockchainAssetId = x.Key.BlockchainAssetId,
                        BlockchainId      = x.Key.BlockchainId,
                        WalletAddress     = x.Key.WalletAddress
                    }
                }));
            }

            return(response);
        }