aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Michael Jurkoic <mjjurkoic@gmail.com>2024-04-30 00:20:05 -0500
committerLibravatar Michael Jurkoic <mjjurkoic@gmail.com>2024-04-30 00:20:05 -0500
commit1417e31b8d9c181b4c35ff4f50d65125d958689b (patch)
tree8c60f5ce027e55cb5ee19501ed00d0901a740a43 /src
parentb05e6adca19038f2d4efdd41df030a890344ef5a (diff)
Ensure first queryRelay unit test passes
Diffstat (limited to 'src')
-rw-r--r--src/event.cpp3
-rw-r--r--src/filters.cpp8
-rw-r--r--src/nostr_service.cpp25
3 files changed, 24 insertions, 12 deletions
diff --git a/src/event.cpp b/src/event.cpp
index 5c98028..703efae 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -24,8 +24,7 @@ string Event::serialize()
{"kind", this->kind},
{"tags", this->tags},
{"content", this->content},
- {"sig", this->sig}
- };
+ {"sig", this->sig}};
j["id"] = this->generateId(j.dump());
diff --git a/src/filters.cpp b/src/filters.cpp
index cfbc5bf..40596eb 100644
--- a/src/filters.cpp
+++ b/src/filters.cpp
@@ -3,10 +3,9 @@
using namespace nlohmann;
using namespace std;
-
namespace nostr
{
-string Filters::serialize(string subscriptionId)
+string Filters::serialize(string& subscriptionId)
{
try
{
@@ -23,9 +22,8 @@ string Filters::serialize(string subscriptionId)
{"kinds", this->kinds},
{"since", this->since},
{"until", this->until},
- {"limit", this->limit}
- };
-
+ {"limit", this->limit}};
+
for (auto& tag : this->tags)
{
stringstream ss;
diff --git a/src/nostr_service.cpp b/src/nostr_service.cpp
index f8565cc..a1adbbb 100644
--- a/src/nostr_service.cpp
+++ b/src/nostr_service.cpp
@@ -3,7 +3,6 @@
using namespace nlohmann;
using namespace std;
-using namespace UUIDv4;
namespace nostr
{
@@ -189,7 +188,23 @@ vector<shared_ptr<Event>> NostrService::queryRelays(shared_ptr<Filters> filters)
vector<shared_ptr<Event>> events;
string subscriptionId = this->generateSubscriptionId();
- string request = filters->serialize(subscriptionId);
+ string request;
+
+ try
+ {
+ request = filters->serialize(subscriptionId);
+ }
+ catch (const invalid_argument& e)
+ {
+ PLOG_ERROR << "Failed to serialize filters - invalid object: " << e.what();
+ throw e;
+ }
+ catch (const json::exception& je)
+ {
+ PLOG_ERROR << "Failed to serialize filters - JSON exception: " << je.what();
+ throw je;
+ }
+
vector<future<tuple<string, bool>>> requestFutures;
// Send the same query to each relay. As events trickle in from each relay, they will be added
@@ -487,9 +502,9 @@ void NostrService::disconnect(string relay)
string NostrService::generateSubscriptionId()
{
- UUIDGenerator<std::mt19937_64> uuidGenerator;
- UUID uuid = uuidGenerator.getUUID();
- return uuid.bytes();
+ UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
+ UUIDv4::UUID uuid = uuidGenerator.getUUID();
+ return uuid.str();
};
string NostrService::generateCloseRequest(string subscriptionId)