From dd08240f4575de1cadc1819b84db9814c7ee2411 Mon Sep 17 00:00:00 2001 From: 257Byte <257byte@gmail.com> Date: Wed, 3 Aug 2022 14:32:30 +0300 Subject: [PATCH] Add filtering by `parameter` in the `/transactions/count` API endpoint and some docs improvements --- Tzkt.Api/Controllers/OperationsController.cs | 12 +++++++++--- .../Repositories/OperationRepository.Transactions.cs | 2 ++ Tzkt.Api/Swagger/WsSubscriptions.md | 11 +++++------ Tzkt.Api/Websocket/Processors/CyclesProcessor.cs | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Tzkt.Api/Controllers/OperationsController.cs b/Tzkt.Api/Controllers/OperationsController.cs index 9951a8d3d..f751aa73c 100644 --- a/Tzkt.Api/Controllers/OperationsController.cs +++ b/Tzkt.Api/Controllers/OperationsController.cs @@ -1886,7 +1886,8 @@ public async Task> GetOriginationsCount( /// Filters transactions by presence of internal operations. /// Filters transactions by entrypoint called on the target contract. /// Filters transactions by parameter value. Note, this query parameter supports the following format: `?parameter{.path?}{.mode?}=...`, - /// so you can specify a path to a particular field to filter by, for example: `?parameter.token_id=...` or `?parameter.sigs.0.ne=...`. + /// so you can specify a path to a particular field to filter by, for example: `?parameter.token_id=...` or `?parameter.sigs.0.ne=...`. + /// Also, note that `.value` part must be omitted in the path, so, for example, filtering by `parameter.value.foo` must be specified as `?parameter.foo=...`. /// Filters transactions by operation status (`applied`, `failed`, `backtracked`, `skipped`). /// Specify comma-separated list of fields to include into response or leave it undefined to return full object. If you select single field, response will be an array of values in both `.fields` and `.values` modes. /// Sorts transactions by specified field. Supported fields: `id` (default), `level`, `gasUsed`, `storageUsed`, `bakerFee`, `storageFee`, `allocationFee`, `amount`. @@ -2111,6 +2112,9 @@ public async Task>> GetTransactio /// Filters transactions by timestamp. /// Filters transactions by entrypoint called on the target contract. /// Filters transactions by operation status (`applied`, `failed`, `backtracked`, `skipped`). + /// Filters transactions by parameter value. Note, this query parameter supports the following format: `?parameter{.path?}{.mode?}=...`, + /// so you can specify a path to a particular field to filter by, for example: `?parameter.token_id=...` or `?parameter.sigs.0.ne=...`. + /// Also, note that `.value` part must be omitted in the path, so, for example, filtering by `parameter.value.foo` must be specified as `?parameter.foo=...`. /// [HttpGet("transactions/count")] public async Task> GetTransactionsCount( @@ -2123,6 +2127,7 @@ public async Task> GetTransactionsCount( Int32Parameter level, DateTimeParameter timestamp, StringParameter entrypoint, + JsonParameter parameter, OperationStatusParameter status) { if (anyof == null && @@ -2132,17 +2137,18 @@ public async Task> GetTransactionsCount( level == null && timestamp == null && entrypoint == null && + parameter == null && status == null) return Ok(State.Current.TransactionOpsCount); var query = ResponseCacheService.BuildKey(Request.Path.Value, ("anyof", anyof), ("initiator", initiator), ("sender", sender), ("target", target), - ("level", level), ("timestamp", timestamp), ("entrypoint", entrypoint), ("status", status)); + ("level", level), ("timestamp", timestamp), ("entrypoint", entrypoint), ("parameter", parameter), ("status", status)); if (ResponseCache.TryGet(query, out var cached)) return this.Bytes(cached); - var res = await Operations.GetTransactionsCount(anyof, initiator, sender, target, level, timestamp, entrypoint, status); + var res = await Operations.GetTransactionsCount(anyof, initiator, sender, target, level, timestamp, entrypoint, parameter, status); cached = ResponseCache.Set(query, res); return this.Bytes(cached); } diff --git a/Tzkt.Api/Repositories/OperationRepository.Transactions.cs b/Tzkt.Api/Repositories/OperationRepository.Transactions.cs index 0771d39a9..460634631 100644 --- a/Tzkt.Api/Repositories/OperationRepository.Transactions.cs +++ b/Tzkt.Api/Repositories/OperationRepository.Transactions.cs @@ -18,6 +18,7 @@ public async Task GetTransactionsCount( Int32Parameter level, DateTimeParameter timestamp, StringParameter entrypoint, + JsonParameter parameter, OperationStatusParameter status) { var sql = new SqlBuilder(@"SELECT COUNT(*) FROM ""TransactionOps""") @@ -28,6 +29,7 @@ public async Task GetTransactionsCount( .Filter("Level", level) .Filter("Timestamp", timestamp) .Filter("Entrypoint", entrypoint) + .Filter("JsonParameters", parameter) .Filter("Status", status); using var db = GetConnection(); diff --git a/Tzkt.Api/Swagger/WsSubscriptions.md b/Tzkt.Api/Swagger/WsSubscriptions.md index 7545fd1ed..d65cb6a86 100644 --- a/Tzkt.Api/Swagger/WsSubscriptions.md +++ b/Tzkt.Api/Swagger/WsSubscriptions.md @@ -31,9 +31,9 @@ await connection.invoke("SubscribeToHead"); --- -## SubscribeToCycle +## SubscribeToCycles -Sends the blockchain head every time cycle is changed. +Notifies of the start of a new cycle with a specified delay. ### Method @@ -47,9 +47,8 @@ Sends the blockchain head every time cycle is changed. ````js { - delayBlocks: 2, // number of blocks to delay cycle changed notification - // minimum 2, defaults to 2 - // delayBlocks has to be lower than number of blocks in cycle to get notifications + delayBlocks: 2, // number of blocks (2 by default) to delay a new cycle notification + // should be >= 2 (to not worry abour reorgs) and < cycle size } ```` @@ -59,7 +58,7 @@ Same as in [/cycle](#operation/Cycles_GetByIndex) ### State -State contains cycle (`int`) of the last processed cycle. +State contains an index (`int`) of the last processed cycle. ### Example diff --git a/Tzkt.Api/Websocket/Processors/CyclesProcessor.cs b/Tzkt.Api/Websocket/Processors/CyclesProcessor.cs index 82485830e..b1c7d9aa0 100644 --- a/Tzkt.Api/Websocket/Processors/CyclesProcessor.cs +++ b/Tzkt.Api/Websocket/Processors/CyclesProcessor.cs @@ -111,7 +111,7 @@ public async Task Subscribe(IClientProxy client, string connectionId, Cycle Logger.LogDebug("Client {0} subscribed with state {1}", connectionId, StateCache.Current.Cycle); return StateCache.Current.Cycle; } - catch (HubException ex) + catch (HubException) { throw; }