aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--include/nostr.hpp2
-rw-r--r--src/event.cpp3
-rw-r--r--src/filters.cpp8
-rw-r--r--src/nostr_service.cpp25
-rw-r--r--test/nostr_service_test.cpp2
6 files changed, 28 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ed34df..ce940bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,7 @@ include(FetchContent)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
diff --git a/include/nostr.hpp b/include/nostr.hpp
index dab4d71..a59bd33 100644
--- a/include/nostr.hpp
+++ b/include/nostr.hpp
@@ -114,7 +114,7 @@ struct Filters
* @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 subscriptionId);
+ std::string serialize(std::string& subscriptionId);
private:
/**
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)
diff --git a/test/nostr_service_test.cpp b/test/nostr_service_test.cpp
index d23f1bb..e80406e 100644
--- a/test/nostr_service_test.cpp
+++ b/test/nostr_service_test.cpp
@@ -741,6 +741,7 @@ TEST_F(NostrServiceTest, QueryRelays_ReturnsEvents_UpToEOSE)
vector<shared_ptr<nostr::Event>> signedTestEvents;
for (nostr::Event testEvent : testEvents)
{
+ std::cout << "TEST: Signing event" << std::endl;
auto signedEvent = make_shared<nostr::Event>(testEvent);
signer->sign(signedEvent);
@@ -758,6 +759,7 @@ TEST_F(NostrServiceTest, QueryRelays_ReturnsEvents_UpToEOSE)
string uri,
function<void(const string&)> messageHandler)
{
+ std::cout << "TEST: Sending message: " << message << std::endl;
json messageArr = json::parse(message);
string subscriptionId = messageArr.at(1);