コード例 #1
0
        public async Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query)
        {
            if (query is null)
            {
                return(PagedResult <DepositDetails> .Empty);
            }

            var deposits = _db.GetAll();

            if (!deposits.Any())
            {
                return(PagedResult <DepositDetails> .Empty);
            }

            var filteredDeposits = deposits.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 filteredDeposits)
                {
                    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));
        }
コード例 #2
0
        public Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query)
        {
            if (query is null)
            {
                return(Task.FromResult(PagedResult <DepositDetails> .Empty));
            }

            var deposits = _db.GetAll();

            if (!deposits.Any())
            {
                return(Task.FromResult(PagedResult <DepositDetails> .Empty));
            }

            var filteredDeposits = deposits.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)
            {
                filteredDeposits = filteredDeposits.Where(d => !d.RefundClaimed &&
                                                          (!(d.EarlyRefundTicket is null) ||
                                                           query.CurrentBlockTimestamp >= d.Deposit.ExpiryTime));
            }

            return(Task.FromResult(filteredDeposits.OrderByDescending(d => d.Timestamp).Paginate(query)));
        }
コード例 #3
0
 public async Task <IReadOnlyList <DataAssetInfo> > GetDataAssetsAsync()
 => await Task.FromResult(_db.GetAll()
                          .Select(d => new DataAssetInfo(d.DataAsset.Id, d.DataAsset.Name, d.DataAsset.Description))
                          .Distinct()
                          .ToList());