Skip to content

Commit

Permalink
Fixed pagination bug & improvements (#182)
Browse files Browse the repository at this point in the history
* Blockhash property added

* Fixes pagination bug
  • Loading branch information
YakupIpek authored Dec 16, 2022
1 parent ce65206 commit 7f7d75a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IActionResult> 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]
Expand Down
2 changes: 1 addition & 1 deletion src/Blockcore.Indexer.Cirrus/Storage/ICirrusStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ICirrusStorage
QueryContractCode ContractCode(string address);
QueryResult<QueryContractGroup> GroupedContracts();
QueryResult<QueryContractList> ListContracts(string contractType, int? offset, int limit);
QueryResult<QueryBlockSmartContractsLogs> ListBLocksLogs(long startBlock, long endBlock, int? offset, int limit);
Task<QueryResult<QueryBlockSmartContractsLogs>> ListContractLogsAsync(long startBlock, long endBlock, int? offset, int limit);

Task<QueryDAOContract> GetDaoContractByAddressAsync(string contractAddress);
Task<QueryStandardTokenContract> GetStandardTokenContractByAddressAsync(string contractAddress);
Expand Down
27 changes: 15 additions & 12 deletions src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ public QueryResult<QueryContractList> ListContracts(string contractType, int? of
};
}

public QueryResult<QueryBlockSmartContractsLogs> ListBLocksLogs(long startBlock, long endBlock, int? offset, int limit)
public async Task<QueryResult<QueryBlockSmartContractsLogs>> 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
Expand All @@ -133,17 +133,20 @@ public QueryResult<QueryBlockSmartContractsLogs> 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()
Expand Down

0 comments on commit 7f7d75a

Please sign in to comment.