From 20b0f9c073d52e95b02399d6a243010e36b6c4f1 Mon Sep 17 00:00:00 2001 From: Michael Jurkoic Date: Sun, 17 Mar 2024 14:09:42 -0500 Subject: Serialize relay query filters into a JSON array --- include/nostr.hpp | 5 ++++- src/filters.cpp | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/nostr.hpp b/include/nostr.hpp index fa407ef..8041efe 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -83,10 +83,13 @@ struct Filters /** * @brief Serializes the filters to a JSON object. + * @param subscriptionId A string up to 64 chars in length that is unique per relay connection. * @returns A stringified JSON object representing the filters. * @throws `std::invalid_argument` if the filter object is invalid. + * @remarks The Nostr client is responsible for managing subscription IDs. Responses from the + * relay will be organized by subscription ID. */ - std::string serialize(); + std::string serialize(std::string subscriptionId); private: /** diff --git a/src/filters.cpp b/src/filters.cpp index 0735a19..3179c2f 100644 --- a/src/filters.cpp +++ b/src/filters.cpp @@ -13,7 +13,7 @@ using std::time; namespace nostr { -string Filters::serialize() +string Filters::serialize(string subscriptionId) { try { @@ -42,6 +42,8 @@ string Filters::serialize() j[tagname] = tag.second; } + json jarr = json::array({ "REQ", subscriptionId, j }); + return j.dump(); }; -- cgit