diff --git a/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs b/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs index 912b833..a7eee60 100644 --- a/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs +++ b/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs @@ -40,12 +40,12 @@ public IActionResult GetContracts([MinLength(2)][MaxLength(100)] string contract [HttpGet] [Route("contracts/logs")] - public IActionResult GetContracts([Range(0, long.MaxValue)] long startBlock,[Range(0, long.MaxValue)] long endBlock, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 1000)] int limit = 1000) + public async Task GetContractLogsAsync([Range(0, long.MaxValue)] long startBlock,[Range(0, long.MaxValue)] long endBlock, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 1000)] int limit = 1000) { if (endBlock < startBlock) return BadRequest(); - return OkPaging(cirrusMongoData.ListBLocksLogs(startBlock,endBlock, offset, limit)); + return OkPaging(await cirrusMongoData.ListContractLogsAsync(startBlock,endBlock, offset, limit)); } [HttpGet] diff --git a/src/Blockcore.Indexer.Cirrus/Storage/ICirrusStorage.cs b/src/Blockcore.Indexer.Cirrus/Storage/ICirrusStorage.cs index 12be1de..2ac8238 100644 --- a/src/Blockcore.Indexer.Cirrus/Storage/ICirrusStorage.cs +++ b/src/Blockcore.Indexer.Cirrus/Storage/ICirrusStorage.cs @@ -14,7 +14,7 @@ public interface ICirrusStorage QueryContractCode ContractCode(string address); QueryResult GroupedContracts(); QueryResult ListContracts(string contractType, int? offset, int limit); - QueryResult ListBLocksLogs(long startBlock, long endBlock, int? offset, int limit); + Task> ListContractLogsAsync(long startBlock, long endBlock, int? offset, int limit); Task GetDaoContractByAddressAsync(string contractAddress); Task GetStandardTokenContractByAddressAsync(string contractAddress); diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs index 287251c..16ab73a 100644 --- a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs @@ -114,17 +114,17 @@ public QueryResult ListContracts(string contractType, int? of }; } - public QueryResult ListBLocksLogs(long startBlock, long endBlock, int? offset, int limit) + public async Task> ListContractLogsAsync(long startBlock, long endBlock, int? offset, int limit) { - var total = mongoDb.CirrusContractTable + var query = mongoDb.CirrusContractTable .AsQueryable() - .Count(_ => _.BlockIndex >= startBlock && _.BlockIndex <= endBlock); + .Where(_ => _.BlockIndex >= startBlock && _.BlockIndex <= endBlock && _.Logs.Any()); - var contracts = mongoDb.CirrusContractTable.AsQueryable() - .Where(_ => _.BlockIndex >= startBlock && _.BlockIndex <= endBlock) - .Skip((offset ?? 0) * limit) - .Take(limit) - .ToList(); + var total = await query.CountAsync(); + + var contracts = await query.Skip(offset ?? 0) + .Take(limit) + .ToListAsync(); var response = contracts.Select(receipt => new QueryBlockSmartContractsLogs @@ -133,17 +133,20 @@ public QueryResult ListBLocksLogs(long startBlock, From = receipt.FromAddress, To = receipt.ToAddress, BlockNumber = receipt.BlockIndex, + BlockHash = receipt.BlockHash, TransactionHash = receipt.TransactionId, Success = receipt.Success, Error = receipt.Error, PostState = receipt.PostState, GasUsed = receipt.GasUsed, - BlockHash = receipt.BlockHash, - Logs = receipt.Logs.Select(l => new Blockcore.Indexer.Cirrus.Models.QueryBlockSmartContractsLogs.LogResponse + Logs = receipt.Logs.Select(l => new QueryBlockSmartContractsLogs.LogResponse { - Address = l.Address,Data = l.Data,Log = new QueryBlockSmartContractsLogs.LogData + Address = l.Address, + Data = l.Data, + Log = new QueryBlockSmartContractsLogs.LogData { - Data = l.Log.Data,Event = l.Log.Event + Data = l.Log.Data, + Event = l.Log.Event }, Topics = l.Topics }).ToArray()