Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate operationId from controller method name #183

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Blockcore.Indexer.Cirrus/Client/Types/LogResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace Blockcore.Indexer.Cirrus.Client.Types;

public class LogResponse
{
public string Address { get; set; }
public string[] Topics { get; set; }
public string Data { get; set; }

public LogData Log { get; set; }
}

public class LogData
{
public string Event { get; set; }

public IDictionary<string, object> Data { get; set; }
}
18 changes: 0 additions & 18 deletions src/Blockcore.Indexer.Cirrus/Client/Types/ReceiptResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections.Generic;

namespace Blockcore.Indexer.Cirrus.Client.Types
{
public class ReceiptResponse
Expand All @@ -20,22 +18,6 @@ public class ReceiptResponse

}

public class LogResponse
{
public string Address { get; set; }
public string[] Topics { get; set; }
public string Data { get; set; }

public LogData Log { get; set; }
}

public class LogData
{
public string Event { get; set; }

public IDictionary<string, object> Data { get; set; }
}

//public class LocalExecutionResponse
//{
// public IReadOnlyList<TransferResponse> InternalTransfers { get; set; }
Expand Down
51 changes: 41 additions & 10 deletions src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Blockcore.Indexer.Cirrus.Models;
using Blockcore.Indexer.Cirrus.Storage;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;
using Blockcore.Indexer.Core.Operations;
using Blockcore.Indexer.Core.Paging;
using Blockcore.Indexer.Core.Storage.Types;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Blockcore.Indexer.Cirrus.Controllers
Expand All @@ -26,21 +29,28 @@ public CirrusQueryController(IPagingHelper paging, ICirrusStorage cirrusMongoDat

[HttpGet]
[Route("contract/list")]
[ProducesResponseType(typeof(QueryResult<QueryContractGroup>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetGroupedContracts()
{
return OkPaging(cirrusMongoData.GroupedContracts());
}

[HttpGet]
[Route("contract/list/{contractType}")]
public IActionResult GetContracts([MinLength(2)][MaxLength(100)] string contractType, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
[ProducesResponseType(typeof(QueryResult<QueryContractList>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetContractsOfType([MinLength(2)][MaxLength(100)] string contractType, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return OkPaging(cirrusMongoData.ListContracts(contractType, offset, limit));
}

[HttpGet]
[Route("contracts/logs")]
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)
[ProducesResponseType(typeof(QueryResult<QueryBlockSmartContractsLogs>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetContractLogs([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();
Expand All @@ -50,56 +60,69 @@ public async Task<IActionResult> GetContractLogsAsync([Range(0, long.MaxValue)]

[HttpGet]
[Route("collectables/{ownerAddress}")]
public IActionResult GetAddressAssets([MinLength(30)][MaxLength(100)] string ownerAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
[ProducesResponseType(typeof(QueryResult<QueryAddressAsset>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetNonFungibleTokensOwnedByAddress([MinLength(30)][MaxLength(100)] string ownerAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return OkPaging(cirrusMongoData.GetNonFungibleTokensForAddressAsync(ownerAddress,offset,limit).Result);
}

[HttpGet]
[Route("tokens/{ownerAddress}")]
public IActionResult GettokensForAddress([MinLength(30)][MaxLength(100)] string ownerAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
[ProducesResponseType(typeof(QueryResult<QueryStandardToken>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetStandardTokensOwnedByAddress([MinLength(30)][MaxLength(100)] string ownerAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return OkPaging(cirrusMongoData.GetStandardTokensForAddressAsync(ownerAddress,offset,limit).Result);
}

[HttpGet]
[Route("contract/{address}")]
public IActionResult GetAddressContract([MinLength(30)][MaxLength(100)] string address)
[ProducesResponseType(typeof(QueryContractCreate), StatusCodes.Status200OK)]
public IActionResult GetSmartContractCreateTransaction([MinLength(30)][MaxLength(100)] string address)
{
return Ok(cirrusMongoData.ContractCreate(address));
}

[HttpGet]
[Route("contract/{address}/transactions")]
public IActionResult GetAddressCall([MinLength(30)][MaxLength(100)] string address, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
[ProducesResponseType(typeof(QueryResult<QueryContractCall>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetSmartContractCallTransactions([MinLength(30)][MaxLength(100)] string address, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return OkPaging(cirrusMongoData.ContractCall(address, null, offset, limit));
}

[HttpGet]
[Route("contract/{address}/transactions/{filterAddress}")]
public IActionResult GetAddressCallFilter([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
[ProducesResponseType(typeof(QueryResult<QueryContractCall>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetSmartContractCallTransactionsBySender([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress, [Range(0, long.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10)
{
return OkPaging(cirrusMongoData.ContractCall(address, filterAddress, offset, limit));
}

[HttpGet]
[Route("contract/transaction/{transactionid}")]
public IActionResult GetTransactionContract([MinLength(30)][MaxLength(100)] string transactionid)
[ProducesResponseType(typeof(QueryContractTransaction), StatusCodes.Status200OK)]
public IActionResult GetSmartContractTransactionById([MinLength(30)][MaxLength(100)] string transactionid)
{
return Ok(cirrusMongoData.ContractTransaction(transactionid));
}

[HttpGet]
[Route("contract/code/{address}")]
public IActionResult GetContractCode([MinLength(30)][MaxLength(100)] string address)
[ProducesResponseType(typeof(QueryContractCode), StatusCodes.Status200OK)]
public IActionResult GetSmartContractCodeByAddress([MinLength(30)][MaxLength(100)] string address)
{
return Ok(cirrusMongoData.ContractCode(address));
}

[HttpGet]
[Route("contract/dao/{address}")]
[SlowRequestsFilteerAttribute]
[ProducesResponseType(typeof(QueryDAOContract), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetDaoContractByAddress([MinLength(30)][MaxLength(100)] string address)
{
var contract = await cirrusMongoData.GetDaoContractByAddressAsync(address);
Expand All @@ -115,6 +138,8 @@ public async Task<IActionResult> GetDaoContractByAddress([MinLength(30)][MaxLeng
[HttpGet]
[Route("contract/standardtoken/{address}")]
[SlowRequestsFilteerAttribute]
[ProducesResponseType(typeof(QueryStandardTokenContract), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30)][MaxLength(100)] string address)
{
var contract = await cirrusMongoData.GetStandardTokenContractByAddressAsync(address);
Expand All @@ -130,7 +155,9 @@ public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30
[HttpGet]
[Route("contract/standardtoken/{address}/{filterAddress}")]
[SlowRequestsFilteerAttribute]
public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress)
[ProducesResponseType(typeof(QueryStandardToken), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetStandardTokenContractByAddressFiltered([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress)
{
var contract = await cirrusMongoData.GetStandardTokenByIdAsync(address, filterAddress);

Expand All @@ -145,6 +172,8 @@ public async Task<IActionResult> GetStandardTokenContractByAddress([MinLength(30
[HttpGet]
[Route("contract/nonfungibletoken/{address}")]
[SlowRequestsFilteerAttribute]
[ProducesResponseType(typeof(QueryNonFungibleTokenContract), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetNonFungibleTokenContractByAddress([MinLength(30)][MaxLength(100)] string address)
{
var contract = await cirrusMongoData.GetNonFungibleTokenContractByAddressAsync(address);
Expand All @@ -160,6 +189,8 @@ public async Task<IActionResult> GetNonFungibleTokenContractByAddress([MinLength
[HttpGet]
[Route("contract/nonfungibletoken/{address}/tokens/{id}")]
[SlowRequestsFilteerAttribute]
[ProducesResponseType(typeof(NonFungibleTokenTable), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetNonFungibleTokenById([MinLength(30)][MaxLength(100)] string address,
[MinLength(1)][MaxLength(100)] string id)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using Blockcore.Indexer.Cirrus.Client.Types;

namespace Blockcore.Indexer.Cirrus.Models;

Expand Down Expand Up @@ -27,20 +27,4 @@ public class QueryBlockSmartContractsLogs
// public ulong ContractBalance { get; set; }

public LogResponse[] Logs { get; set; }

public class LogResponse
{
public string Address { get; set; }
public string[] Topics { get; set; }
public string Data { get; set; }

public LogData Log { get; set; }
}

public class LogData
{
public string Event { get; set; }

public IDictionary<string, object> Data { get; set; }
}
}
5 changes: 3 additions & 2 deletions src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blockcore.Indexer.Cirrus.Client.Types;
using Blockcore.Indexer.Cirrus.Models;
using Blockcore.Indexer.Cirrus.Storage.Mongo.Types;
using Blockcore.Indexer.Core.Client;
Expand Down Expand Up @@ -139,11 +140,11 @@ public async Task<QueryResult<QueryBlockSmartContractsLogs>> ListContractLogsAsy
Error = receipt.Error,
PostState = receipt.PostState,
GasUsed = receipt.GasUsed,
Logs = receipt.Logs.Select(l => new QueryBlockSmartContractsLogs.LogResponse
Logs = receipt.Logs.Select(l => new LogResponse
{
Address = l.Address,
Data = l.Data,
Log = new QueryBlockSmartContractsLogs.LogData
Log = new LogData
{
Data = l.Log.Data,
Event = l.Log.Event
Expand Down
5 changes: 4 additions & 1 deletion src/Blockcore.Indexer.Core/Controllers/CommandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Blockcore.Indexer.Core.Binding;
using Blockcore.Indexer.Core.Handlers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Blockcore.Indexer.Core.Controllers
Expand All @@ -24,7 +25,9 @@ public CommandController(CommandHandler commandHandler)
}

[HttpPost("send")]
public async Task<IActionResult> Send([FromBody][ModelBinder(BinderType = typeof(RawStringModelBinder))] string data)
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
public async Task<IActionResult> SendTransaction([FromBody][ModelBinder(BinderType = typeof(RawStringModelBinder))] string data)
{
if (string.IsNullOrEmpty(data))
{
Expand Down
3 changes: 2 additions & 1 deletion src/Blockcore.Indexer.Core/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

using Blockcore.Indexer.Core.Client;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -10,7 +11,7 @@ namespace Blockcore.Indexer.Core.Controllers
public class ErrorController : ControllerBase
{
[Route("/error")]
public IActionResult Error([FromServices] IWebHostEnvironment webHostEnvironment)
public IActionResult GetError([FromServices] IWebHostEnvironment webHostEnvironment)
{
IExceptionHandlerFeature context = HttpContext.Features.Get<IExceptionHandlerFeature>();
bool devMode = webHostEnvironment.EnvironmentName == "Development";
Expand Down
11 changes: 10 additions & 1 deletion src/Blockcore.Indexer.Core/Controllers/InsightController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using Blockcore.Indexer.Core.Paging;
using Blockcore.Indexer.Core.Settings;
using Blockcore.Indexer.Core.Storage;
using Blockcore.Indexer.Core.Storage.Mongo.Types;
using Blockcore.Indexer.Core.Storage.Types;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -46,6 +48,7 @@ public InsightController(IPagingHelper paging, IStorage storage, IMemoryCache ca
/// </summary>
/// <returns></returns>
[HttpGet("supply")]
[ProducesResponseType(typeof(Supply), StatusCodes.Status200OK)]
public ActionResult<Supply> GetSupply()
{
if (!cache.TryGetValue(CacheKeys.Supply, out Supply supply))
Expand All @@ -67,6 +70,7 @@ public ActionResult<Supply> GetSupply()
/// </summary>
/// <returns></returns>
[HttpGet("supply/circulating")]
[ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)]
public ActionResult<decimal> GetCirculatingSupply()
{
return Ok(CalculateCirculatingSupply() / unit);
Expand All @@ -77,6 +81,7 @@ public ActionResult<decimal> GetCirculatingSupply()
/// </summary>
/// <returns></returns>
[HttpGet("supply/total")]
[ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)]
public ActionResult<decimal> GetTotalSupply()
{
return Ok(storage.TotalBalance());
Expand All @@ -87,6 +92,7 @@ public ActionResult<decimal> GetTotalSupply()
/// </summary>
/// <returns></returns>
[HttpGet("rewards")]
[ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)]
public ActionResult<decimal> GetRewards()
{
long tip = storage.GetLatestBlock().BlockIndex;
Expand All @@ -107,7 +113,8 @@ public ActionResult<decimal> GetRewards()
/// </summary>
/// <returns></returns>
[HttpGet("wallets")]
public IActionResult GetWallets()
[ProducesResponseType(typeof(List<Wallet>), StatusCodes.Status200OK)]
public IActionResult GetKnownWallets()
{
if (!cache.TryGetValue(CacheKeys.Wallets, out List<Wallet> funds))
{
Expand All @@ -126,6 +133,8 @@ public IActionResult GetWallets()
/// Returns richlist entries based on the offset and limit. The entries are sorted from from lowest to highest balance.
/// </summary>
[HttpGet("richlist")]
[ProducesResponseType(typeof(QueryResult<RichlistTable>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetRichlist([Range(0, int.MaxValue)] int offset = 0, [Range(1, 100)] int limit = 100)
{
return OkPaging(storage.Richlist(offset, limit));
Expand Down
Loading