Пример #1
0
 /// <summary>
 /// Paged by transfer
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public PageList<TransferInfo> QueryTransfers(TransferFilter filter)
 {
     var query = BuildQuery(filter);
     var pageList = new PageList<TransferInfo>();
     var pageIndex = filter.PageIndex <= 0 ? 0 : filter.PageIndex - 1;
     pageList.TotalCount = query.Count();
     pageList.PageIndex = pageIndex + 1;
     pageList.PageSize = filter.PageSize;
     if (filter.PageSize > 0)
     {
         pageList.List.AddRange(query.OrderByDescending(r => r.Time).Skip(pageIndex * filter.PageSize)
             .Take(filter.PageSize).ToList().Select(ToNep5TransferInfo));
     }
     return pageList;
 }
Пример #2
0
        private IQueryable<Nep5TransferEntity> BuildQuery(TransferFilter filter)
        {
            IQueryable<Nep5TransferEntity> query = _sqldb.Nep5Transactions.Where(t => t.TxId != null)
                .Include(t => t.From)
                .Include(t => t.To)
                .Include(t => t.Asset).Where(t => t.Asset.DeleteOrMigrateTxId == null);

            if (filter.FromOrTo.NotEmpty())
            {
                var addresses = filter.FromOrTo.Select(a => a.ToBigEndianHex()).ToList();
                query = query.Where(r => addresses.Contains(r.From.Hash) || addresses.Contains(r.To.Hash));
            }
            if (filter.From.NotEmpty())
            {
                var addresses = filter.From.Select(a => a.ToBigEndianHex()).ToList();
                query = query.Where(r => addresses.Contains(r.From.Hash));
            }
            if (filter.To.NotEmpty())
            {
                var addresses = filter.To.Select(a => a.ToBigEndianHex()).ToList();
                query = query.Where(r => addresses.Contains(r.To.Hash));
            }
            if (filter.StartTime != null)
            {
                query = query.Where(r => r.Time >= filter.StartTime.Value.ToUniversalTime());
            }
            if (filter.EndTime != null)
            {
                query = query.Where(r => r.Time <= filter.EndTime.Value.ToUniversalTime());
            }
            if (filter.Asset != null)
            {
                query = query.Where(r => r.Asset.Hash == filter.Asset.ToBigEndianHex());
            }
            if (filter.BlockHeight != null)
            {
                query = query.Where(r => r.BlockHeight == filter.BlockHeight);
            }
            if (filter.TxIds.NotEmpty())
            {
                var txids = filter.TxIds.Select(t => t.ToBigEndianHex()).Distinct().ToList();
                query = query.Where(r => txids.Contains(r.TxId));
            }

            return query;
        }
Пример #3
0
 /// <summary>
 ///  Paged by Transactions
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public PageList<TransferInfo> QueryNep5Transactions(TransferFilter filter)
 {
     var query = BuildQuery(filter);
     var pageList = new PageList<TransferInfo>();
     var pageIndex = filter.PageIndex <= 0 ? 0 : filter.PageIndex - 1;
     pageList.TotalCount = query.GroupBy(q => q.TxId).Count();
     pageList.PageIndex = pageIndex + 1;
     pageList.PageSize = filter.PageSize;
     if (filter.PageSize > 0)
     {
         var txIds = query.GroupBy(q => new { q.TxId, q.Time }).OrderByDescending(g => g.Key.Time).Select(g => g.Key)
             .Skip(pageIndex * filter.PageSize)
             .Take(filter.PageSize).Select(g => g.TxId).ToList();
         pageList.List.AddRange(query.Where(q => txIds.Contains(q.TxId)).OrderByDescending(r => r.Time).ToList().Select(ToNep5TransferInfo));
     }
     return pageList;
 }