From 1d05ad4a2fac8f25084ba37d95dca37554e87813 Mon Sep 17 00:00:00 2001 From: drmathias Date: Thu, 15 Dec 2022 13:02:23 +0000 Subject: [PATCH 1/2] Generate operationId from controller method name --- .../Controllers/CirrusQueryController.cs | 20 +++++++++---------- .../Controllers/CommandController.cs | 2 +- .../Controllers/ErrorController.cs | 3 ++- .../Controllers/InsightController.cs | 2 +- .../Controllers/QueryController.cs | 2 +- .../Controllers/StatsController.cs | 12 +++++------ src/Blockcore.Indexer.Core/Startup.cs | 14 +++++++++++-- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs b/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs index 912b8333..5d99de74 100644 --- a/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs +++ b/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs @@ -33,14 +33,14 @@ public IActionResult GetGroupedContracts() [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) + 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 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 IActionResult GetContractsLogs([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(); @@ -50,49 +50,49 @@ public IActionResult GetContracts([Range(0, long.MaxValue)] long startBlock,[Ran [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) + 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) + 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) + 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) + 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) + 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) + 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) + public IActionResult GetSmartContractCodeByAddress([MinLength(30)][MaxLength(100)] string address) { return Ok(cirrusMongoData.ContractCode(address)); } @@ -130,7 +130,7 @@ public async Task GetStandardTokenContractByAddress([MinLength(30 [HttpGet] [Route("contract/standardtoken/{address}/{filterAddress}")] [SlowRequestsFilteerAttribute] - public async Task GetStandardTokenContractByAddress([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress) + public async Task GetStandardTokenContractByAddressFiltered([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress) { var contract = await cirrusMongoData.GetStandardTokenByIdAsync(address, filterAddress); diff --git a/src/Blockcore.Indexer.Core/Controllers/CommandController.cs b/src/Blockcore.Indexer.Core/Controllers/CommandController.cs index 43261e40..1c7068bd 100644 --- a/src/Blockcore.Indexer.Core/Controllers/CommandController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/CommandController.cs @@ -24,7 +24,7 @@ public CommandController(CommandHandler commandHandler) } [HttpPost("send")] - public async Task Send([FromBody][ModelBinder(BinderType = typeof(RawStringModelBinder))] string data) + public async Task SendTransaction([FromBody][ModelBinder(BinderType = typeof(RawStringModelBinder))] string data) { if (string.IsNullOrEmpty(data)) { diff --git a/src/Blockcore.Indexer.Core/Controllers/ErrorController.cs b/src/Blockcore.Indexer.Core/Controllers/ErrorController.cs index df371082..d9ba5ba4 100644 --- a/src/Blockcore.Indexer.Core/Controllers/ErrorController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/ErrorController.cs @@ -1,3 +1,4 @@ + using Blockcore.Indexer.Core.Client; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Hosting; @@ -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(); bool devMode = webHostEnvironment.EnvironmentName == "Development"; diff --git a/src/Blockcore.Indexer.Core/Controllers/InsightController.cs b/src/Blockcore.Indexer.Core/Controllers/InsightController.cs index d72bd3b9..528a1ed6 100644 --- a/src/Blockcore.Indexer.Core/Controllers/InsightController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/InsightController.cs @@ -107,7 +107,7 @@ public ActionResult GetRewards() /// /// [HttpGet("wallets")] - public IActionResult GetWallets() + public IActionResult GetKnownWallets() { if (!cache.TryGetValue(CacheKeys.Wallets, out List funds)) { diff --git a/src/Blockcore.Indexer.Core/Controllers/QueryController.cs b/src/Blockcore.Indexer.Core/Controllers/QueryController.cs index 5efcce09..ce275f49 100644 --- a/src/Blockcore.Indexer.Core/Controllers/QueryController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/QueryController.cs @@ -35,7 +35,7 @@ public QueryController(IPagingHelper paging, IStorage storage) /// [HttpGet] [Route("address/{address}")] - public IActionResult GetAddress([MinLength(4)][MaxLength(100)] string address) + public IActionResult GetAddressBalance([MinLength(4)][MaxLength(100)] string address) { return Ok(storage.AddressBalance(address)); } diff --git a/src/Blockcore.Indexer.Core/Controllers/StatsController.cs b/src/Blockcore.Indexer.Core/Controllers/StatsController.cs index 00c24e9c..a170c7b9 100644 --- a/src/Blockcore.Indexer.Core/Controllers/StatsController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/StatsController.cs @@ -31,21 +31,21 @@ public StatsController(StatsHandler statsHandler, IStorage storage) [HttpGet] [Route("heartbeat")] - public IActionResult Heartbeat() + public IActionResult GetHeartbeat() { return Ok("Heartbeat"); } [HttpGet] [Route("connections")] - public async Task Connections() + public async Task GetConnections() { StatsConnection ret = await statsHandler.StatsConnection(); return Ok(ret); } [HttpGet()] - public async Task Get() + public async Task GetStats() { Statistics ret = await statsHandler.Statistics(); return Ok(ret); @@ -57,7 +57,7 @@ public async Task Get() /// [HttpGet] [Route("info")] - public async Task Info() + public async Task GetInfo() { CoinInfo ret = await statsHandler.CoinInformation(); return Ok(ret); @@ -69,7 +69,7 @@ public async Task Info() /// [HttpGet] [Route("peers")] - public async Task Peers() + public async Task GetCurrentPeers() { System.Collections.Generic.List ret = await statsHandler.Peers(); return Ok(ret); @@ -81,7 +81,7 @@ public async Task Peers() /// [HttpGet] [Route("peers/{date}")] - public IActionResult Peers(DateTime date) + public IActionResult GetPeersFromDate(DateTime date) { List list = storage.GetPeerFromDate(date); return Ok(list); diff --git a/src/Blockcore.Indexer.Core/Startup.cs b/src/Blockcore.Indexer.Core/Startup.cs index f8e7f3f7..7bb7ca1e 100644 --- a/src/Blockcore.Indexer.Core/Startup.cs +++ b/src/Blockcore.Indexer.Core/Startup.cs @@ -15,8 +15,6 @@ using Blockcore.Indexer.Core.Storage.Mongo; using Blockcore.Indexer.Core.Sync; using Blockcore.Indexer.Core.Sync.SyncTasks; -using Blockcore.Utilities; -using ConcurrentCollections; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.ApplicationModels; @@ -27,6 +25,7 @@ using Microsoft.OpenApi.Models; using MongoDB.Driver; using Newtonsoft.Json; +using Swashbuckle.AspNetCore.SwaggerGen; namespace Blockcore.Indexer.Core { @@ -111,6 +110,17 @@ public static void AddIndexerServices(IServiceCollection services, IConfiguratio { string assemblyVersion = typeof(Startup).Assembly.GetName().Version.ToString(); + options.CustomOperationIds(e => + { + if (!e.TryGetMethodInfo(out MethodInfo methodInfo)) return null; + // convert method name to camelCase + return string.Create(methodInfo.Name.Length, methodInfo.Name, (chars, methodName) => + { + methodName.AsSpan().CopyTo(chars); + chars[0] = char.ToLower(methodName[0]); + }); + }); + options.SwaggerDoc("indexer", new OpenApiInfo { From 7bfecb47d338243c50e5f47ea42bc026960c806c Mon Sep 17 00:00:00 2001 From: drmathias Date: Thu, 22 Dec 2022 10:38:31 +0000 Subject: [PATCH 2/2] Generate OpenAPI type schemas --- .../Client/Types/LogResponse.cs | 19 ++++++++++ .../Client/Types/ReceiptResponse.cs | 18 ---------- .../Controllers/CirrusQueryController.cs | 31 ++++++++++++++++ .../Models/QueryBlockSmartContractsLogs.cs | 18 +--------- .../Storage/Mongo/CirrusMongoData.cs | 5 +-- .../Controllers/CommandController.cs | 3 ++ .../Controllers/InsightController.cs | 9 +++++ .../Controllers/QueryController.cs | 35 +++++++++++++++++++ .../Controllers/StatsController.cs | 7 ++++ 9 files changed, 108 insertions(+), 37 deletions(-) create mode 100644 src/Blockcore.Indexer.Cirrus/Client/Types/LogResponse.cs diff --git a/src/Blockcore.Indexer.Cirrus/Client/Types/LogResponse.cs b/src/Blockcore.Indexer.Cirrus/Client/Types/LogResponse.cs new file mode 100644 index 00000000..3426e684 --- /dev/null +++ b/src/Blockcore.Indexer.Cirrus/Client/Types/LogResponse.cs @@ -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 Data { get; set; } +} diff --git a/src/Blockcore.Indexer.Cirrus/Client/Types/ReceiptResponse.cs b/src/Blockcore.Indexer.Cirrus/Client/Types/ReceiptResponse.cs index a325d99a..302c9158 100644 --- a/src/Blockcore.Indexer.Cirrus/Client/Types/ReceiptResponse.cs +++ b/src/Blockcore.Indexer.Cirrus/Client/Types/ReceiptResponse.cs @@ -1,5 +1,3 @@ -using System.Collections.Generic; - namespace Blockcore.Indexer.Cirrus.Client.Types { public class ReceiptResponse @@ -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 Data { get; set; } - } - //public class LocalExecutionResponse //{ // public IReadOnlyList InternalTransfers { get; set; } diff --git a/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs b/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs index 0203fb08..26ade80f 100644 --- a/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs +++ b/src/Blockcore.Indexer.Cirrus/Controllers/CirrusQueryController.cs @@ -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 @@ -26,6 +29,8 @@ public CirrusQueryController(IPagingHelper paging, ICirrusStorage cirrusMongoDat [HttpGet] [Route("contract/list")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetGroupedContracts() { return OkPaging(cirrusMongoData.GroupedContracts()); @@ -33,6 +38,8 @@ public IActionResult GetGroupedContracts() [HttpGet] [Route("contract/list/{contractType}")] + [ProducesResponseType(typeof(QueryResult), 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)); @@ -40,6 +47,9 @@ public IActionResult GetContractsOfType([MinLength(2)][MaxLength(100)] string co [HttpGet] [Route("contracts/logs")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task 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) @@ -50,6 +60,8 @@ public async Task GetContractLogs([Range(0, long.MaxValue)] long [HttpGet] [Route("collectables/{ownerAddress}")] + [ProducesResponseType(typeof(QueryResult), 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); @@ -57,6 +69,8 @@ public IActionResult GetNonFungibleTokensOwnedByAddress([MinLength(30)][MaxLengt [HttpGet] [Route("tokens/{ownerAddress}")] + [ProducesResponseType(typeof(QueryResult), 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); @@ -64,6 +78,7 @@ public IActionResult GetStandardTokensOwnedByAddress([MinLength(30)][MaxLength(1 [HttpGet] [Route("contract/{address}")] + [ProducesResponseType(typeof(QueryContractCreate), StatusCodes.Status200OK)] public IActionResult GetSmartContractCreateTransaction([MinLength(30)][MaxLength(100)] string address) { return Ok(cirrusMongoData.ContractCreate(address)); @@ -71,6 +86,8 @@ public IActionResult GetSmartContractCreateTransaction([MinLength(30)][MaxLength [HttpGet] [Route("contract/{address}/transactions")] + [ProducesResponseType(typeof(QueryResult), 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)); @@ -78,6 +95,8 @@ public IActionResult GetSmartContractCallTransactions([MinLength(30)][MaxLength( [HttpGet] [Route("contract/{address}/transactions/{filterAddress}")] + [ProducesResponseType(typeof(QueryResult), 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)); @@ -85,6 +104,7 @@ public IActionResult GetSmartContractCallTransactionsBySender([MinLength(30)][Ma [HttpGet] [Route("contract/transaction/{transactionid}")] + [ProducesResponseType(typeof(QueryContractTransaction), StatusCodes.Status200OK)] public IActionResult GetSmartContractTransactionById([MinLength(30)][MaxLength(100)] string transactionid) { return Ok(cirrusMongoData.ContractTransaction(transactionid)); @@ -92,6 +112,7 @@ public IActionResult GetSmartContractTransactionById([MinLength(30)][MaxLength(1 [HttpGet] [Route("contract/code/{address}")] + [ProducesResponseType(typeof(QueryContractCode), StatusCodes.Status200OK)] public IActionResult GetSmartContractCodeByAddress([MinLength(30)][MaxLength(100)] string address) { return Ok(cirrusMongoData.ContractCode(address)); @@ -100,6 +121,8 @@ public IActionResult GetSmartContractCodeByAddress([MinLength(30)][MaxLength(100 [HttpGet] [Route("contract/dao/{address}")] [SlowRequestsFilteerAttribute] + [ProducesResponseType(typeof(QueryDAOContract), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetDaoContractByAddress([MinLength(30)][MaxLength(100)] string address) { var contract = await cirrusMongoData.GetDaoContractByAddressAsync(address); @@ -115,6 +138,8 @@ public async Task GetDaoContractByAddress([MinLength(30)][MaxLeng [HttpGet] [Route("contract/standardtoken/{address}")] [SlowRequestsFilteerAttribute] + [ProducesResponseType(typeof(QueryStandardTokenContract), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetStandardTokenContractByAddress([MinLength(30)][MaxLength(100)] string address) { var contract = await cirrusMongoData.GetStandardTokenContractByAddressAsync(address); @@ -130,6 +155,8 @@ public async Task GetStandardTokenContractByAddress([MinLength(30 [HttpGet] [Route("contract/standardtoken/{address}/{filterAddress}")] [SlowRequestsFilteerAttribute] + [ProducesResponseType(typeof(QueryStandardToken), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetStandardTokenContractByAddressFiltered([MinLength(30)][MaxLength(100)] string address, [MinLength(30)][MaxLength(100)] string filterAddress) { var contract = await cirrusMongoData.GetStandardTokenByIdAsync(address, filterAddress); @@ -145,6 +172,8 @@ public async Task GetStandardTokenContractByAddressFiltered([MinL [HttpGet] [Route("contract/nonfungibletoken/{address}")] [SlowRequestsFilteerAttribute] + [ProducesResponseType(typeof(QueryNonFungibleTokenContract), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetNonFungibleTokenContractByAddress([MinLength(30)][MaxLength(100)] string address) { var contract = await cirrusMongoData.GetNonFungibleTokenContractByAddressAsync(address); @@ -160,6 +189,8 @@ public async Task GetNonFungibleTokenContractByAddress([MinLength [HttpGet] [Route("contract/nonfungibletoken/{address}/tokens/{id}")] [SlowRequestsFilteerAttribute] + [ProducesResponseType(typeof(NonFungibleTokenTable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetNonFungibleTokenById([MinLength(30)][MaxLength(100)] string address, [MinLength(1)][MaxLength(100)] string id) { diff --git a/src/Blockcore.Indexer.Cirrus/Models/QueryBlockSmartContractsLogs.cs b/src/Blockcore.Indexer.Cirrus/Models/QueryBlockSmartContractsLogs.cs index 90d540bb..6d88b08c 100644 --- a/src/Blockcore.Indexer.Cirrus/Models/QueryBlockSmartContractsLogs.cs +++ b/src/Blockcore.Indexer.Cirrus/Models/QueryBlockSmartContractsLogs.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using Blockcore.Indexer.Cirrus.Client.Types; namespace Blockcore.Indexer.Cirrus.Models; @@ -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 Data { get; set; } - } } diff --git a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs index 16ab73a9..a6bd8047 100644 --- a/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs +++ b/src/Blockcore.Indexer.Cirrus/Storage/Mongo/CirrusMongoData.cs @@ -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; @@ -139,11 +140,11 @@ public async Task> 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 diff --git a/src/Blockcore.Indexer.Core/Controllers/CommandController.cs b/src/Blockcore.Indexer.Core/Controllers/CommandController.cs index 1c7068bd..12fda082 100644 --- a/src/Blockcore.Indexer.Core/Controllers/CommandController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/CommandController.cs @@ -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 @@ -24,6 +25,8 @@ public CommandController(CommandHandler commandHandler) } [HttpPost("send")] + [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] public async Task SendTransaction([FromBody][ModelBinder(BinderType = typeof(RawStringModelBinder))] string data) { if (string.IsNullOrEmpty(data)) diff --git a/src/Blockcore.Indexer.Core/Controllers/InsightController.cs b/src/Blockcore.Indexer.Core/Controllers/InsightController.cs index 528a1ed6..88a1f2a2 100644 --- a/src/Blockcore.Indexer.Core/Controllers/InsightController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/InsightController.cs @@ -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; @@ -46,6 +48,7 @@ public InsightController(IPagingHelper paging, IStorage storage, IMemoryCache ca /// /// [HttpGet("supply")] + [ProducesResponseType(typeof(Supply), StatusCodes.Status200OK)] public ActionResult GetSupply() { if (!cache.TryGetValue(CacheKeys.Supply, out Supply supply)) @@ -67,6 +70,7 @@ public ActionResult GetSupply() /// /// [HttpGet("supply/circulating")] + [ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)] public ActionResult GetCirculatingSupply() { return Ok(CalculateCirculatingSupply() / unit); @@ -77,6 +81,7 @@ public ActionResult GetCirculatingSupply() /// /// [HttpGet("supply/total")] + [ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)] public ActionResult GetTotalSupply() { return Ok(storage.TotalBalance()); @@ -87,6 +92,7 @@ public ActionResult GetTotalSupply() /// /// [HttpGet("rewards")] + [ProducesResponseType(typeof(decimal), StatusCodes.Status200OK)] public ActionResult GetRewards() { long tip = storage.GetLatestBlock().BlockIndex; @@ -107,6 +113,7 @@ public ActionResult GetRewards() /// /// [HttpGet("wallets")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public IActionResult GetKnownWallets() { if (!cache.TryGetValue(CacheKeys.Wallets, out List funds)) @@ -126,6 +133,8 @@ public IActionResult GetKnownWallets() /// Returns richlist entries based on the offset and limit. The entries are sorted from from lowest to highest balance. /// [HttpGet("richlist")] + [ProducesResponseType(typeof(QueryResult), 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)); diff --git a/src/Blockcore.Indexer.Core/Controllers/QueryController.cs b/src/Blockcore.Indexer.Core/Controllers/QueryController.cs index ce275f49..81449bd6 100644 --- a/src/Blockcore.Indexer.Core/Controllers/QueryController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/QueryController.cs @@ -2,9 +2,12 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Threading.Tasks; +using Blockcore.Indexer.Core.Models; using Blockcore.Indexer.Core.Paging; 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; namespace Blockcore.Indexer.Core.Controllers @@ -35,6 +38,7 @@ public QueryController(IPagingHelper paging, IStorage storage) /// [HttpGet] [Route("address/{address}")] + [ProducesResponseType(typeof(QueryAddress), StatusCodes.Status200OK)] public IActionResult GetAddressBalance([MinLength(4)][MaxLength(100)] string address) { return Ok(storage.AddressBalance(address)); @@ -47,6 +51,7 @@ public IActionResult GetAddressBalance([MinLength(4)][MaxLength(100)] string add /// [HttpPost] [Route("addresses/balance")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public IActionResult GetAddressesBalance(IList addresses) { return Ok(storage.QuickBalancesLookupForAddressesWithHistoryCheckAsync(addresses).Result); @@ -61,6 +66,8 @@ public IActionResult GetAddressesBalance(IList addresses) /// [HttpGet] [Route("address/{address}/transactions")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetAddressTransactions([MinLength(4)][MaxLength(100)] string address, [Range(0, int.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10) { return OkPaging(storage.AddressHistory(address, offset, limit)); @@ -76,6 +83,8 @@ public IActionResult GetAddressTransactions([MinLength(4)][MaxLength(100)] strin /// [HttpGet] [Route("address/{address}/transactions/unspent")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetAddressTransactionsUnspent([MinLength(30)][MaxLength(100)] string address, long confirmations = 0, [Range(0, int.MaxValue)] int offset = 0, [Range(1, 50)] int limit = 10) { QueryResult result = await storage.GetUnspentTransactionsByAddressAsync(address, confirmations, offset, limit); @@ -91,6 +100,8 @@ public async Task GetAddressTransactionsUnspent([MinLength(30)][M /// [HttpGet] [Route("mempool/transactions")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetMempoolTransactions([Range(0, int.MaxValue)] int offset = 0, [Range(1, 50)] int limit = 10) { return OkPaging(storage.GetMemoryTransactionsSlim(offset, limit)); @@ -102,6 +113,8 @@ public IActionResult GetMempoolTransactions([Range(0, int.MaxValue)] int offset /// [HttpGet] [Route("mempool/transactions/count")] + [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetMempoolTransactionsCount() { return OkItem(storage.GetMemoryTransactionsCount()); @@ -114,6 +127,8 @@ public IActionResult GetMempoolTransactionsCount() /// [HttpGet] [Route("transaction/{transactionId}")] + [ProducesResponseType(typeof(QueryTransaction), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetTransaction(string transactionId) { return OkItem(storage.GetTransaction(transactionId)); @@ -126,6 +141,8 @@ public IActionResult GetTransaction(string transactionId) /// [HttpGet] [Route("transaction/{transactionId}/hex")] + [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetTransactionHex(string transactionId) { return OkItem(storage.GetRawTransaction(transactionId)); @@ -139,6 +156,8 @@ public IActionResult GetTransactionHex(string transactionId) /// Number of blocks to return. Maximum 50. [HttpGet] [Route("block")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetBlocks([Range(0, int.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10) { return OkPaging(storage.Blocks(offset, limit)); @@ -152,6 +171,8 @@ public IActionResult GetBlocks([Range(0, int.MaxValue)] int? offset = 0, [Range( /// [HttpGet] [Route("block/{hash}/transactions")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetBlockByHashTransactions(string hash, [Range(0, int.MaxValue)] int offset = 0, [Range(1, 50)] int limit = 10) { return OkPaging(storage.TransactionsByBlock(hash, offset, limit)); @@ -164,6 +185,8 @@ public IActionResult GetBlockByHashTransactions(string hash, [Range(0, int.MaxVa /// [HttpGet] [Route("block/{hash}")] + [ProducesResponseType(typeof(SyncBlockInfo), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetBlockByHash(string hash) { return OkItem(storage.BlockByHash(hash)); @@ -176,6 +199,8 @@ public IActionResult GetBlockByHash(string hash) /// [HttpGet] [Route("block/{hash}/hex")] + [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetBlockHex(string hash) { return OkItem(storage.GetRawBlock(hash)); @@ -188,6 +213,8 @@ public IActionResult GetBlockHex(string hash) /// Number of blocks to return. Maximum 50. [HttpGet] [Route("block/orphan")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetOrphanBlocks([Range(0, int.MaxValue)] int? offset = 0, [Range(1, 50)] int limit = 10) { return OkPaging(storage.OrphanBlocks(offset, limit)); @@ -200,6 +227,8 @@ public IActionResult GetOrphanBlocks([Range(0, int.MaxValue)] int? offset = 0, [ /// [HttpGet] [Route("block/orphan/{hash}")] + [ProducesResponseType(typeof(ReorgBlockTable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetOrphanBlockByHash(string hash) { return OkItem(storage.OrphanBlockByHash(hash)); @@ -212,6 +241,8 @@ public IActionResult GetOrphanBlockByHash(string hash) /// [HttpGet] [Route("block/index/{index}")] + [ProducesResponseType(typeof(SyncBlockInfo), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetBlockByIndex([Range(0, long.MaxValue)] long index) { return OkItem(storage.BlockByIndex(index)); @@ -225,6 +256,8 @@ public IActionResult GetBlockByIndex([Range(0, long.MaxValue)] long index) /// [HttpGet] [Route("block/index/{index}/transactions")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetBlockByIndexTransactions([Range(0, long.MaxValue)] long index, [Range(0, int.MaxValue)] int offset = 0, [Range(1, 50)] int limit = 10) { return OkPaging(storage.TransactionsByBlock(index, offset, limit)); @@ -236,6 +269,8 @@ public IActionResult GetBlockByIndexTransactions([Range(0, long.MaxValue)] long /// [HttpGet] [Route("block/latest")] + [ProducesResponseType(typeof(SyncBlockInfo), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public IActionResult GetLatestBlock() { return OkItem(storage.GetLatestBlock()); diff --git a/src/Blockcore.Indexer.Core/Controllers/StatsController.cs b/src/Blockcore.Indexer.Core/Controllers/StatsController.cs index a170c7b9..5db278dd 100644 --- a/src/Blockcore.Indexer.Core/Controllers/StatsController.cs +++ b/src/Blockcore.Indexer.Core/Controllers/StatsController.cs @@ -5,6 +5,7 @@ using Blockcore.Indexer.Core.Models; using Blockcore.Indexer.Core.Storage; using Blockcore.Indexer.Core.Storage.Mongo; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Blockcore.Indexer.Core.Controllers @@ -31,6 +32,7 @@ public StatsController(StatsHandler statsHandler, IStorage storage) [HttpGet] [Route("heartbeat")] + [ProducesResponseType(typeof(string), StatusCodes.Status200OK)] public IActionResult GetHeartbeat() { return Ok("Heartbeat"); @@ -38,6 +40,7 @@ public IActionResult GetHeartbeat() [HttpGet] [Route("connections")] + [ProducesResponseType(typeof(StatsConnection), StatusCodes.Status200OK)] public async Task GetConnections() { StatsConnection ret = await statsHandler.StatsConnection(); @@ -45,6 +48,7 @@ public async Task GetConnections() } [HttpGet()] + [ProducesResponseType(typeof(Statistics), StatusCodes.Status200OK)] public async Task GetStats() { Statistics ret = await statsHandler.Statistics(); @@ -57,6 +61,7 @@ public async Task GetStats() /// [HttpGet] [Route("info")] + [ProducesResponseType(typeof(CoinInfo), StatusCodes.Status200OK)] public async Task GetInfo() { CoinInfo ret = await statsHandler.CoinInformation(); @@ -69,6 +74,7 @@ public async Task GetInfo() /// [HttpGet] [Route("peers")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public async Task GetCurrentPeers() { System.Collections.Generic.List ret = await statsHandler.Peers(); @@ -81,6 +87,7 @@ public async Task GetCurrentPeers() /// [HttpGet] [Route("peers/{date}")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public IActionResult GetPeersFromDate(DateTime date) { List list = storage.GetPeerFromDate(date);