From e37b4146b93f2312a3ea55d1c134851cf24c9720 Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 7 Feb 2025 20:16:25 +0000 Subject: [PATCH] nip-45: only accept one filter per count command. --- 45.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/45.md b/45.md index 219368e4..15d9c27f 100644 --- a/45.md +++ b/45.md @@ -10,21 +10,21 @@ Relays may support the verb `COUNT`, which provides a mechanism for obtaining ev ## Motivation -Some queries a client may want to execute against connected relays are prohibitively expensive, for example, in order to retrieve follower counts for a given pubkey, a client must query all kind-3 events referring to a given pubkey only to count them. The result may be cached, either by a client or by a separate indexing server as an alternative, but both options erode the decentralization of the network by creating a second-layer protocol on top of Nostr. +Some queries a client may want to execute against connected relays are prohibitively expensive, for example, in order to retrieve follower counts for a given pubkey, a client must query all kind-3 events referring to a given pubkey only to count them. The result may be cached, either by a client or by a separate indexing server as an alternative, but both options erode the decentralization of the network by creating a second-layer protocol on top of the Nostr. -## Filters and return values +## Filter and return values -This NIP defines the verb `COUNT`, which accepts a subscription id and filters as specified in [NIP 01](01.md) for the verb `REQ`. Multiple filters are OR'd together and aggregated into a single count result. +This NIP defines the verb `COUNT`, which accepts a subscription id and a filter as specified in [NIP 01](01.md) for the verb `REQ`. -``` -["COUNT", , ...] +```json +["COUNT", "", ] ``` -Counts are returned using a `COUNT` response in the form `{"count": }`. Relays may use probabilistic counts to reduce compute requirements. +Counts are returned using a `COUNT` response in the form `{"count": }`. Relays MAY use probabilistic counts to reduce compute requirements. In case a relay uses probabilistic counts, it MAY indicate it in the response with `approximate` key i.e. `{"count": , "approximate": }`. -``` -["COUNT", , {"count": }] +```json +["COUNT", "", {"count": }] ``` Whenever the relay decides to refuse to fulfill the `COUNT` request, it MUST return a `CLOSED` message. @@ -33,28 +33,28 @@ Whenever the relay decides to refuse to fulfill the `COUNT` request, it MUST ret ### Followers count -``` -["COUNT", , {"kinds": [3], "#p": []}] -["COUNT", , {"count": 238}] +```json +["COUNT", "", {"kinds": [3], "#p": [""]}] +["COUNT", "", {"count": 238}] ``` ### Count posts and reactions -``` -["COUNT", , {"kinds": [1, 7], "authors": []}] -["COUNT", , {"count": 5}] +```json +["COUNT", "", {"kinds": [1, 7], "authors": [""]}] +["COUNT", "", {"count": 5}] ``` ### Count posts approximately -``` -["COUNT", , {"kinds": [1]}] -["COUNT", , {"count": 93412452, "approximate": true}] +```json +["COUNT", "", {"kinds": [1]}] +["COUNT", "", {"count": 93412452, "approximate": true}] ``` ### Relay refuses to count -``` -["COUNT", , {"kinds": [4], "authors": [], "#p": []}] -["CLOSED", , "auth-required: cannot count other people's DMs"] +```json +["COUNT", "", {"kinds": [4], "authors": [""], "#p": [""]}] +["CLOSED", "", "auth-required: cannot count other people's DMs"] ```