From 111b9914c601730a3697a3b7ff8a60fd2c15a38a Mon Sep 17 00:00:00 2001 From: Michael Jurkoic Date: Sat, 23 Mar 2024 11:38:29 -0500 Subject: Get smarter with pointers so tests pass --- include/nostr.hpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'include/nostr.hpp') diff --git a/include/nostr.hpp b/include/nostr.hpp index 2b04862..2f37c51 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -42,7 +42,7 @@ struct Event * @returns A stringified JSON object representing the event. * @throws `std::invalid_argument` if the event object is invalid. */ - std::string serialize(std::shared_ptr signer); + std::string serialize(); /** * @brief Deserializes the event from a JSON string. @@ -105,14 +105,15 @@ private: class NostrService { -// TODO: Setup signer in the constructor. public: NostrService( std::shared_ptr appender, - std::shared_ptr client); + std::shared_ptr client, + std::shared_ptr signer); NostrService( std::shared_ptr appender, std::shared_ptr client, + std::shared_ptr signer, RelayList relays); ~NostrService(); @@ -149,7 +150,7 @@ public: * to which relays the event was published successfully, and to which relays the event failed * to publish. */ - std::tuple publishEvent(Event event); + std::tuple publishEvent(std::shared_ptr event); /** * @brief Queries all open relay connections for events matching the given set of filters. @@ -229,8 +230,8 @@ private: std::unordered_map> _subscriptions; ///< A map from subscription IDs to the events returned by the relays for each subscription. std::unordered_map> _events; - ///< A map from the subscription IDs to the latest read event for each subscription. - std::unordered_map::iterator> _eventIterators; + ///< A map from the subscription IDs to the ID of the latest read event for each subscription. + std::unordered_map _lastRead; /** * @brief Determines which of the given relays are currently connected. @@ -302,6 +303,11 @@ private: class ISigner { public: - virtual std::string generateSignature(std::shared_ptr event) = 0; + /** + * @brief Signs the given Nostr event. + * @param event The event to sign. + * @remark The event's `sig` field will be updated in-place with the signature. + */ + virtual void sign(std::shared_ptr event) = 0; }; } // namespace nostr -- cgit