Skip to content

Commit

Permalink
Add filtering by parameter in the /transactions/count API endpoin…
Browse files Browse the repository at this point in the history
…t and some docs improvements
  • Loading branch information
Groxan committed Aug 3, 2022
1 parent 2216a7c commit dd08240
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
12 changes: 9 additions & 3 deletions Tzkt.Api/Controllers/OperationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,8 @@ public async Task<ActionResult<int>> GetOriginationsCount(
/// <param name="hasInternals">Filters transactions by presence of internal operations.</param>
/// <param name="entrypoint">Filters transactions by entrypoint called on the target contract.</param>
/// <param name="parameter">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=...`.</param>
/// 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=...`.</param>
/// <param name="status">Filters transactions by operation status (`applied`, `failed`, `backtracked`, `skipped`).</param>
/// <param name="select">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.</param>
/// <param name="sort">Sorts transactions by specified field. Supported fields: `id` (default), `level`, `gasUsed`, `storageUsed`, `bakerFee`, `storageFee`, `allocationFee`, `amount`.</param>
Expand Down Expand Up @@ -2111,6 +2112,9 @@ public async Task<ActionResult<IEnumerable<TransactionOperation>>> GetTransactio
/// <param name="timestamp">Filters transactions by timestamp.</param>
/// <param name="entrypoint">Filters transactions by entrypoint called on the target contract.</param>
/// <param name="status">Filters transactions by operation status (`applied`, `failed`, `backtracked`, `skipped`).</param>
/// <param name="parameter">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=...`.</param>
/// <returns></returns>
[HttpGet("transactions/count")]
public async Task<ActionResult<int>> GetTransactionsCount(
Expand All @@ -2123,6 +2127,7 @@ public async Task<ActionResult<int>> GetTransactionsCount(
Int32Parameter level,
DateTimeParameter timestamp,
StringParameter entrypoint,
JsonParameter parameter,
OperationStatusParameter status)
{
if (anyof == null &&
Expand All @@ -2132,17 +2137,18 @@ public async Task<ActionResult<int>> 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);
}
Expand Down
2 changes: 2 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.Transactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public async Task<int> GetTransactionsCount(
Int32Parameter level,
DateTimeParameter timestamp,
StringParameter entrypoint,
JsonParameter parameter,
OperationStatusParameter status)
{
var sql = new SqlBuilder(@"SELECT COUNT(*) FROM ""TransactionOps""")
Expand All @@ -28,6 +29,7 @@ public async Task<int> GetTransactionsCount(
.Filter("Level", level)
.Filter("Timestamp", timestamp)
.Filter("Entrypoint", entrypoint)
.Filter("JsonParameters", parameter)
.Filter("Status", status);

using var db = GetConnection();
Expand Down
11 changes: 5 additions & 6 deletions Tzkt.Api/Swagger/WsSubscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
````

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Websocket/Processors/CyclesProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task<int> 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;
}
Expand Down

0 comments on commit dd08240

Please sign in to comment.