public async Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query)
        {
            if (query is null)
            {
                return(PagedResult <DepositDetails> .Empty);
            }

            var deposits = Deposits.AsQueryable();

            if (query.OnlyPending || query.OnlyUnconfirmed || query.OnlyNotRejected || query.EligibleToRefund)
            {
                //MongoDB unsupported predicate: (d.Confirmations < d.RequiredConfirmations) - maybe due to uint type?
                var allDeposits = await deposits.ToListAsync();

                var filteredDeposits = allDeposits.AsEnumerable();
                if (query.OnlyPending)
                {
                    filteredDeposits = filteredDeposits.Where(d => !d.Rejected && !d.RefundClaimed &&
                                                              (d.Transaction?.State == TransactionState.Pending ||
                                                               d.ClaimedRefundTransaction?.State ==
                                                               TransactionState.Pending));
                }

                if (query.OnlyUnconfirmed)
                {
                    filteredDeposits = filteredDeposits.Where(d => d.ConfirmationTimestamp == 0 ||
                                                              d.Confirmations < d.RequiredConfirmations);
                }

                if (query.OnlyNotRejected)
                {
                    filteredDeposits = filteredDeposits.Where(d => !d.Rejected);
                }

                if (query.EligibleToRefund)
                {
                    foreach (var deposit in deposits)
                    {
                        uint consumedUnits = await _depositUnitsCalculator.GetConsumedAsync(deposit);

                        deposit.SetConsumedUnits(consumedUnits);
                    }

                    filteredDeposits = filteredDeposits.Where(d => !d.RefundClaimed && (d.ConsumedUnits < d.Deposit.Units) &&
                                                              (!(d.EarlyRefundTicket is null) ||
                                                               query.CurrentBlockTimestamp >= d.Deposit.ExpiryTime
                                                              ));
                }

                return(filteredDeposits.OrderByDescending(d => d.Timestamp).ToArray().Paginate(query));
            }

            return(await deposits.OrderByDescending(d => d.Timestamp).PaginateAsync(query));
        }
        public async Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query)
        {
            if (query is null)
            {
                return(PagedResult <DepositDetails> .Empty);
            }

            var deposits = Deposits.AsQueryable();

            if (query.OnlyUnverified)
            {
                deposits = deposits.Where(d => d.VerificationTimestamp == 0);
            }

            return(await deposits.OrderByDescending(d => d.Timestamp).PaginateAsync(query));
        }
Пример #3
0
        public async Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query)
        {
            if (query is null)
            {
                return(PagedResult <DepositDetails> .Empty);
            }

            var deposits = Deposits.AsQueryable();

            if (query.OnlyUnconfirmed || query.OnlyNotRejected || query.EligibleToRefund)
            {
                //MongoDB unsupported predicate: (d.Confirmations < d.RequiredConfirmations) - maybe due to uint type?
                var allDeposits = await deposits.ToListAsync();

                var filteredDeposits = allDeposits.AsEnumerable();
                if (query.OnlyUnconfirmed)
                {
                    filteredDeposits = filteredDeposits.Where(d => d.ConfirmationTimestamp == 0 ||
                                                              d.Confirmations < d.RequiredConfirmations);
                }

                if (query.OnlyNotRejected)
                {
                    filteredDeposits = filteredDeposits.Where(d => !d.Rejected);
                }

                if (query.EligibleToRefund)
                {
                    filteredDeposits = filteredDeposits.Where(d => !d.RefundClaimed &&
                                                              (!(d.EarlyRefundTicket is null) ||
                                                               query.CurrentBlockTimestamp >= d.Deposit.ExpiryTime
                                                              ));
                }

                return(filteredDeposits.OrderByDescending(d => d.Timestamp).Paginate(query));
            }

            return(await deposits.OrderByDescending(d => d.Timestamp).PaginateAsync(query));
        }
 public async Task <IReadOnlyList <ProviderInfo> > GetProvidersAsync()
 => await Deposits.AsQueryable()
 .Select(d => new ProviderInfo(d.DataHeader.Provider.Name, d.DataHeader.Provider.Address))
 .Distinct()
 .ToListAsync();
 public async Task <IReadOnlyList <DataHeaderInfo> > GetDataHeadersAsync()
 => await Deposits.AsQueryable()
 .Select(d => new DataHeaderInfo(d.DataHeader.Id, d.DataHeader.Name, d.DataHeader.Description))
 .Distinct()
 .ToListAsync();