public async Task <IEnumerable <AddressHistoryModel> > GetAsync(AddressHistoryQuery addressHistoryQuery) { var filterBuilder = Builders <AddressHistoryEntity> .Filter; var filter = filterBuilder.Empty; if (!string.IsNullOrEmpty(addressHistoryQuery.FromAddress)) { filter &= filterBuilder.Eq(x => x.From, addressHistoryQuery.FromAddress); } if (!string.IsNullOrEmpty(addressHistoryQuery.ToAddress)) { var filterTo = filterBuilder.Eq(x => x.To, addressHistoryQuery.ToAddress); filter = addressHistoryQuery.FromAddress == addressHistoryQuery.ToAddress ? filter | filterTo : filter & filterTo; } if (addressHistoryQuery.StartBlock.HasValue) { var unixTime = addressHistoryQuery.StartBlock.Value; filter &= filterBuilder.Gte(x => x.BlockNumber, unixTime); } if (addressHistoryQuery.StopBlock.HasValue) { var unixTime = addressHistoryQuery.StopBlock.Value; filter &= filterBuilder.Lte(x => x.BlockNumber, unixTime); } var sort = Builders <AddressHistoryEntity> .Sort.Combine ( Builders <AddressHistoryEntity> .Sort.Descending(x => x.BlockNumber), Builders <AddressHistoryEntity> .Sort.Ascending(x => x.TransactionIndex), Builders <AddressHistoryEntity> .Sort.Ascending(x => x.MessageIndex) ); var search = _collection.Find(filter); search = search.Sort(sort); addressHistoryQuery.Start = addressHistoryQuery.Start ?? 0; addressHistoryQuery.Count = addressHistoryQuery.Count.HasValue && addressHistoryQuery.Count != 0 ? addressHistoryQuery.Count : (int)await search.CountAsync(); search = search.Skip(addressHistoryQuery.Start).Limit(addressHistoryQuery.Count); return((await search.ToListAsync()) .Select(_mapper.Map <AddressHistoryModel>)); }
public async Task <IActionResult> GetForAddress(GetAddressInternalMessageHistoryRequest request) { var address = request.Address.ToLowerInvariant(); var transactionQuery = new AddressHistoryQuery { FromAddress = address, ToAddress = address, StartBlock = request.StartBlock, StopBlock = request.StopBlock, Start = request.Start, Count = request.Count }; var messages = (await _addressHistoryService.GetAsync(transactionQuery)).ToList(); return(ProcessResponse(messages)); }
public async Task <IEnumerable <AddressHistoryModel> > GetAsync(AddressHistoryQuery addressHistoryQuery) { IEnumerable <AddressHistoryModel> history = await _addressHistoryRepository.GetAsync(addressHistoryQuery); return(history); }