public async Task <IActionResult> GetFilteredAddresses(AddressesCriteria addressesCriteria) { if (addressesCriteria == null) { addressesCriteria = new AddressesCriteria(); } if (!addressesCriteria.StartAt.HasValue) { addressesCriteria.StartAt = 0; } if (!addressesCriteria.Count.HasValue) { addressesCriteria.Count = MaxPageSize; } var criteria = _mapper.Map <AddressFilterCriteria>(addressesCriteria); var addressResult = await _addressQuery.GetAddressLitesFilteredAsync(criteria, addressesCriteria.StartAt.Value, addressesCriteria.Count.Value, true, MaxAddressesReults); var response = new FilterResponse <FilteredAddress, AddressesCriteria> { Criteria = addressesCriteria, FilterResultCount = addressResult.ResultCount, Data = addressResult.Results.Select(x => _mapper.Map <FilteredAddress>(x)).ToList() }; return(Ok(response)); }
public async Task <IActionResult> GetAddresses(DataTablePostModel <AddressFilterCriteria> model) { var count = model.Length > MaxAddressesPerFilterPage ? MaxAddressesPerFilterPage : model.Length; var data = await _addressQuery.GetAddressLitesFilteredAsync(model.FilterCriteria, model.Start, count, true, MaxAddressesFilterResults); var resultCount = data.ResultCount; var response = new { RecordsFiltered = resultCount, Data = data.Results }; return(Ok(response)); }
protected override async Task ExecuteAsync() { var sw = new Stopwatch(); sw.Start(); Logger.LogInformation("Updating address stats..."); var dormantThreshold = await _blockQuery.GetBlockAsync(DateTime.Now.AddYears(-1)); var addressStats = await _redisCommand.GetAsync <AddressStatDto>(Settings.Redis.AddressStatPubSub) ?? new AddressStatDto(); addressStats.AddressCount = await _addressQuery.GetUniqueAddressCountAsync(); addressStats.CreatedPerHour = await _addressQuery.GetAddressesCreatedLastHourAsync(); addressStats.ZeroBalance = (int)(await _addressQuery.GetCountFilteredAsync(new AddressFilterCriteria { MaxBalance = 0 })); var stakeableAddresses = await _addressQuery.GetAddressLitesFilteredAsync(new AddressFilterCriteria { OrderBy = OrderAddressesBy.HighestBalance, MinBalance = StakeThreshold }, 0, int.MaxValue, false); addressStats.BalanceOverOneThousand = stakeableAddresses.Results.Count; var oldAddresses = await _addressQuery.GetAddressLitesFilteredAsync(new AddressFilterCriteria { OrderBy = OrderAddressesBy.MostRecentlyActive, MinBalance = 0.00000001d, HeightTo = dormantThreshold.Height }, 0, int.MaxValue, false); addressStats.DormantOverOneYear = oldAddresses.Results.Count; var stakingAddresses = await _addressQuery.GetAddressLitesFilteredAsync(new AddressFilterCriteria { IsStaking = true }, 0, int.MaxValue, false); addressStats.StakingCount = stakingAddresses.Results.Count; addressStats.TotalStakedCoins = Math.Round(stakingAddresses.Results.Sum(x => x.Balance), 8); addressStats.AverageBalance = await _addressQuery.GetAverageBalanceAsync(false); var distributionBands = Enum.GetValues(typeof(AddressBalanceDistributionBands)) .Cast <AddressBalanceDistributionBands>() .ToList(); var distributionBalances = new List <double>(); var distributionCounts = new List <int>(); var supplyInfo = await _nexusQuery.GetSupplyRate(); var distributionDtos = new List <AddressDistrubtionBandDto>(); foreach (var distributionBand in distributionBands) { var bandFilter = GetDistrubutionBands(distributionBand); var addCount = (int)(await _addressQuery.GetCountFilteredAsync(bandFilter)); var coinBalance = await _addressQuery.GetBalanceSumFilteredAsync(bandFilter); distributionDtos.Add(new AddressDistrubtionBandDto { DistributionBand = distributionBand, AddressCount = addCount, AddressPercent = (addCount / (double)(addressStats.AddressCount - addressStats.ZeroBalance)) * 100, CoinBalance = coinBalance, CoinPercent = (coinBalance / supplyInfo.MoneySupply) * 100 }); } await _redisCommand.SetAsync(Settings.Redis.AddressDistributionStats, distributionDtos); await _redisCommand.SetAsync(Settings.Redis.AddressStatPubSub, addressStats); await _redisCommand.PublishAsync(Settings.Redis.AddressStatPubSub, addressStats); Logger.LogInformation($"Updated address stats in {sw.Elapsed:g}"); }