Beispiel #1
0
        public async Task <IEnumerable <Erc20BalanceModel> > GetAsync(Erc20BalanceQuery query)
        {
            var filterBuilder = Builders <Erc20BalanceEntity> .Filter;
            var filter        = filterBuilder.Empty;

            if (query.BlockNumber.HasValue)
            {
                filter &= filterBuilder.Eq(x => x.BlockNumber, query.BlockNumber.Value);
            }

            if (!string.IsNullOrEmpty(query.AssetHolder))
            {
                filter &= filterBuilder.Eq(x => x.AssetHolderAddress, query.AssetHolder);
            }

            if (query.Contracts != null && query.Contracts.Any())
            {
                filter &= filterBuilder.In(x => x.ContractAddress, query.Contracts.ToList());
            }

            return((await _balanceCollection.Find(filter)
                    .SortByDescending(x => x.BlockNumber)
                    .ThenBy(x => x.ContractAddress)
                    .ThenBy(x => x.AssetHolderAddress)
                    .Skip(query.Start)
                    .Limit(query.Count)
                    .ToListAsync())
                   .Select(_mapper.Map <Erc20BalanceModel>));
        }
Beispiel #2
0
        public async Task <IActionResult> GetForAddress([FromRoute] string address, [FromBody] IEnumerable <string> contracts)
        {
            var query = new Erc20BalanceQuery
            {
                AssetHolder = address.ToLowerInvariant(),
                Contracts   = contracts?.Select(x => x.ToLowerInvariant()).Distinct()
            };

            return(await GetAsync(query));
        }
Beispiel #3
0
        public async Task <IActionResult> Get([FromBody] GetErc20BalanceRequest request, [FromQuery] int?start, [FromQuery] int?count)
        {
            var query = new Erc20BalanceQuery
            {
                AssetHolder = request.AssetHolder?.ToLowerInvariant(),
                BlockNumber = request.BlockNumber,
                Contracts   = request.Contracts?.Select(x => x.ToLowerInvariant()).Distinct(),
                Count       = count,
                Start       = start
            };

            return(await GetAsync(query));
        }
Beispiel #4
0
        private async Task <IActionResult> GetAsync(Erc20BalanceQuery query)
        {
            var balances = (await _balanceService.GetAsync(query))
                           .Select(x => new Erc20BalanceResponse
            {
                AssetHolderAddress = x.AssetHolderAddress,
                Balance            = x.Balance.ToString(),
                BlockNumber        = x.BlockNumber,
                ContractAddress    = x.ContractAddress
            })
                           .ToList();

            return(new JsonResult(balances));
        }
Beispiel #5
0
 public async Task <IEnumerable <Erc20BalanceModel> > GetAsync(Erc20BalanceQuery query)
 {
     return(await _balanceRepository.GetAsync(query));
 }