Skip to content

Commit

Permalink
Optimize filters, update ws docs. (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmirgaleev authored Oct 23, 2023
1 parent 2b4e1f0 commit b0bca66
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 6 deletions.
21 changes: 16 additions & 5 deletions Tzkt.Api/Parameters/Binders/Int32Binder.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
134 changes: 134 additions & 0 deletions Tzkt.Api/Swagger/WsSubscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b0bca66

Please sign in to comment.