Beispiel #1
0
        public async Task <IEnumerable <InternalMessageModel> > GetAllByFilterAsync(InternalMessageQuery internalMessageQuery)
        {
            List <InternalMessageModel> result = new List <InternalMessageModel>();
            var filterBuilder = Builders <InternalMessageEntity> .Filter;
            var filter        = Builders <InternalMessageEntity> .Filter.Empty;

            if (!string.IsNullOrEmpty(internalMessageQuery.FromAddress))
            {
                FilterDefinition <InternalMessageEntity> filterFrom = filterBuilder.Eq(x => x.FromAddress, internalMessageQuery.FromAddress);
                filter = filter & filterFrom;
            }

            if (!string.IsNullOrEmpty(internalMessageQuery.ToAddress))
            {
                FilterDefinition <InternalMessageEntity> filterTo = filterBuilder.Eq(x => x.ToAddress, internalMessageQuery.ToAddress);

                filter = internalMessageQuery.FromAddress == internalMessageQuery.ToAddress ? filter | filterTo : filter & filterTo;
            }

            if (internalMessageQuery.StartBlock.HasValue)
            {
                FilterDefinition <InternalMessageEntity> filterStartBlock =
                    filterBuilder.Gte(x => x.BlockNumber, internalMessageQuery.StartBlock.Value);
                filter = filter & filterStartBlock;
            }

            if (internalMessageQuery.StopBlock.HasValue)
            {
                FilterDefinition <InternalMessageEntity> filterEndBlock =
                    filterBuilder.Lte(x => x.BlockNumber, internalMessageQuery.StopBlock.Value);
                filter = filter & filterEndBlock;
            }

            var sort = Builders <InternalMessageEntity> .Sort
                       .Descending(x => x.BlockNumber)
                       .Ascending(x => x.TransactionHash)
                       .Ascending(x => x.MessageIndex);

            MongoDB.Driver.IFindFluent <InternalMessageEntity, InternalMessageEntity> search = _collection.Find(filter);
            search = search.Sort(sort);

            internalMessageQuery.Start = internalMessageQuery.Start.HasValue ? internalMessageQuery.Start : 0;
            internalMessageQuery.Count = internalMessageQuery.Count.HasValue && internalMessageQuery.Count != 0 ? internalMessageQuery.Count : (int)await search.CountAsync();

            search = search.Skip(internalMessageQuery.Start).Limit(internalMessageQuery.Count);
            result = new List <InternalMessageModel>(internalMessageQuery.Count.Value);
            IAsyncCursor <InternalMessageEntity> cursor = await search.ToCursorAsync();

            await cursor.ForEachAsync((internalMessage) =>
            {
                InternalMessageModel internalMessageModel = _mapper.Map <InternalMessageModel>(internalMessage);
                result.Add(internalMessageModel);
            });

            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> GetForAddress(GetAddressInternalMessageHistoryRequest request)
        {
            var address          = request.Address.ToLower();
            var transactionQuery = new InternalMessageQuery
            {
                FromAddress = address,
                ToAddress   = address,
                StartBlock  = request.StartBlock,
                StopBlock   = request.StopBlock,
                Start       = request.Start,
                Count       = request.Count
            };

            var messages = (await _internalMessageService.GetAsync(transactionQuery)).ToList();

            return(ProcessResponse(messages));
        }
Beispiel #3
0
        public async Task <IEnumerable <InternalMessageModel> > GetAsync(InternalMessageQuery internalMessageQuery)
        {
            var messages = await _internalMessageRepository.GetAllByFilterAsync(internalMessageQuery);

            return(messages);
        }