public Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query) { if (query is null) { return(Task.FromResult(PagedResult <DepositDetails> .Empty)); } var depositsBytes = _database.GetAll(); if (depositsBytes.Length == 0) { return(Task.FromResult(PagedResult <DepositDetails> .Empty)); } var deposits = new DepositDetails[depositsBytes.Length]; for (var i = 0; i < depositsBytes.Length; i++) { deposits[i] = Decode(depositsBytes[i]); } var filteredDeposits = deposits.AsEnumerable(); if (query.OnlyUnverified) { filteredDeposits = filteredDeposits.Where(d => d.VerificationTimestamp == 0); } return(Task.FromResult(filteredDeposits.OrderByDescending(d => d.Timestamp).Paginate(query))); }
public async Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query) { if (query is null) { throw new ArgumentNullException(nameof(query)); } var depositsBytes = _database.GetAllValues().ToArray(); if (depositsBytes.Length == 0) { return(PagedResult <DepositDetails> .Empty); } DepositDetails[] deposits = new DepositDetails[depositsBytes.Length]; for (var i = 0; i < depositsBytes.Length; i++) { deposits[i] = Decode(depositsBytes[i]); } IEnumerable <DepositDetails> 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 deposits) { uint consumedUnits = await _depositUnitsCalculator.GetConsumedAsync(deposit); deposit.SetConsumedUnits(consumedUnits); } filteredDeposits = GetEligibleToRefund(filteredDeposits, query.CurrentBlockTimestamp); } return(filteredDeposits.OrderByDescending(d => d.Timestamp).ToArray().Paginate(query)); }
public Task <PagedResult <DepositDetails> > BrowseAsync(GetDeposits query) { if (query is null) { return(Task.FromResult(PagedResult <DepositDetails> .Empty)); } var depositsBytes = _database.GetAll(); if (depositsBytes.Length == 0) { return(Task.FromResult(PagedResult <DepositDetails> .Empty)); } var deposits = new DepositDetails[depositsBytes.Length]; for (var i = 0; i < depositsBytes.Length; i++) { deposits[i] = Decode(depositsBytes[i]); } 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))); }