From b0bca660a3aea47a5b957097fc74b6ce9e3df795 Mon Sep 17 00:00:00 2001 From: Dmitry Mirgaleev <35151170+dmirgaleev@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:21:09 +0300 Subject: [PATCH] Optimize filters, update ws docs. (#154) --- Tzkt.Api/Parameters/Binders/Int32Binder.cs | 21 ++- Tzkt.Api/Swagger/WsSubscriptions.md | 134 ++++++++++++++++++ .../Proto1/Diagnostics/Diagnostics.cs | 2 +- 3 files changed, 151 insertions(+), 6 deletions(-) diff --git a/Tzkt.Api/Parameters/Binders/Int32Binder.cs b/Tzkt.Api/Parameters/Binders/Int32Binder.cs index ad1df54e6..52333e879 100644 --- a/Tzkt.Api/Parameters/Binders/Int32Binder.cs +++ b/Tzkt.Api/Parameters/Binders/Int32Binder.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Tzkt.Api { @@ -45,6 +41,21 @@ public Task BindModelAsync(ModelBindingContext bindingContext) bindingContext.Result = ModelBindingResult.Success(null); return Task.CompletedTask; } + + if (ge != null && ge == le) + { + bindingContext.Result = ModelBindingResult.Success(new Int32Parameter + { + Eq = ge, + Ne = ne, + Gt = gt, + Lt = lt, + In = @in, + Ni = ni + }); + + return Task.CompletedTask; + } bindingContext.Result = ModelBindingResult.Success(new Int32Parameter { diff --git a/Tzkt.Api/Swagger/WsSubscriptions.md b/Tzkt.Api/Swagger/WsSubscriptions.md index a652906f5..5d706fcad 100644 --- a/Tzkt.Api/Swagger/WsSubscriptions.md +++ b/Tzkt.Api/Swagger/WsSubscriptions.md @@ -440,8 +440,142 @@ connection.on("transfers", (msg) => { console.log(msg); }); await connection.invoke("SubscribeToTokenTransfers", { account: 'tz123...' }); ```` +--- + +## SubscribeToTicketBalances + +Sends ticket balances when they are updated + +### Method + +`SubscribeToTicketBalances` + +### Channel + +`ticket_balances` + +### Parameters + +This method accepts the following parameters: + +````js +{ + account: '', // address of the account that holds tickets + ticketer: '', // address of the ticketer +} +```` + +You can set various combinations of these fields to configure what you want to subscribe to. For example: + +````js +// subscribe to all ticket balance updates +{ +} + +// subscribe to balance updates of all tickets within the ticketer +{ + ticketer: 'KT1...' +} + +// subscribe to ticket balance updates for the account +{ + account: 'tz1...' +} + +// subscribe to balance updates of all tickets within the ticketer for the account +{ + account: 'tz1...', + ticketer: 'KT1...' +} +```` + +> **Note:** you can invoke this method multiple times with different parameters to register multiple subscriptions. + +### Data model + +Same as in [/tickets/balances](#operation/Tickets_GetTicketBalances). + +### State + +State contains level (`int`) of the last processed block. + +### Example + +````js +connection.on("ticket_balances", (msg) => { console.log(msg); }); +// subscribe to all ticket balances of the 'tz123...' account +await connection.invoke("SubscribeToTicketBalances", { account: 'tz123...' }); +```` + --- +## SubscribeToTicketTransfers + +Sends ticket transfers + +### Method + +`SubscribeToTicketTransfers` + +### Channel + +`ticket_transfers` + +### Parameters + +This method accepts the following parameters: + +````js +{ + account: '', // address of the account that sends/receives tickets + ticketer: '', // address of the ticketer +} +```` + +You can set various combinations of these fields to configure what you want to subscribe to. For example: + +````js +// subscribe to all transfers +{ +} + +// subscribe to transfers of all tickets within the ticketer +{ + ticketer: 'KT1...' +} + +// subscribe to transfers from/to the account +{ + account: 'tz1...' +} + +// subscribe to transfers of all tickets within the ticketer from/to the account +{ + account: 'tz1...', + ticketer: 'KT1...' +} +```` + +> **Note:** you can invoke this method multiple times with different parameters to register multiple subscriptions. + +### Data model + +Same as in [/tickets/transfers](#operation/Tickets_GetTicketTransfers). + +### State + +State contains level (`int`) of the last processed block. + +### Example + +````js +connection.on("ticket_transfers", (msg) => { console.log(msg); }); +// subscribe to all transfers of the 'tz123...' account +await connection.invoke("SubscribeToTicketTransfers", { account: 'tz123...' }); +```` + +--- + ## SubscribeToEvents Sends contract events diff --git a/Tzkt.Sync/Protocols/Handlers/Proto1/Diagnostics/Diagnostics.cs b/Tzkt.Sync/Protocols/Handlers/Proto1/Diagnostics/Diagnostics.cs index 87c487a82..3f09b060c 100644 --- a/Tzkt.Sync/Protocols/Handlers/Proto1/Diagnostics/Diagnostics.cs +++ b/Tzkt.Sync/Protocols/Handlers/Proto1/Diagnostics/Diagnostics.cs @@ -59,7 +59,7 @@ protected virtual async Task RunDiagnostics(int level, int ops = -1) { var entries = Db.ChangeTracker.Entries(); - if (ops != -1 && ops != entries.Count(x => x.Entity is BaseOperation && x.State == EntityState.Added)) + if (ops != -1 && ops != entries.Count(x => x.Entity is BaseOperation or ContractEvent && x.State == EntityState.Added)) throw new Exception($"Diagnostics failed: wrong operations count"); var state = Cache.AppState.Get();