From 32bb72b527966c1b7324afcd7fae466fc84b30d6 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Mon, 27 May 2024 12:09:41 -0500 Subject: refactor so no project header imports nostr.hpp --- src/data/event.cpp | 21 +++++++++------------ src/data/filters.cpp | 12 ++++-------- 2 files changed, 13 insertions(+), 20 deletions(-) (limited to 'src/data') diff --git a/src/data/event.cpp b/src/data/event.cpp index 5f611ff..bd37ee7 100644 --- a/src/data/event.cpp +++ b/src/data/event.cpp @@ -1,13 +1,12 @@ +#include +#include + #include "data/data.hpp" using namespace nlohmann; using namespace std; -namespace nostr -{ -namespace data -{ -string Event::serialize() +string nostr::data::Event::serialize() { try { @@ -31,7 +30,7 @@ string Event::serialize() return j.dump(); }; -Event Event::fromString(string jstr) +nostr::data::Event nostr::data::Event::fromString(string jstr) { json j = json::parse(jstr); Event event; @@ -48,7 +47,7 @@ Event Event::fromString(string jstr) return event; }; -Event Event::fromJson(json j) +nostr::data::Event nostr::data::Event::fromJson(json j) { Event event; @@ -69,7 +68,7 @@ Event Event::fromJson(json j) return event; }; -void Event::validate() +void nostr::data::Event::validate() { bool hasPubkey = this->pubkey.length() > 0; if (!hasPubkey) @@ -90,7 +89,7 @@ void Event::validate() } }; -string Event::generateId(string serializedData) const +string nostr::data::Event::generateId(string serializedData) const { unsigned char hash[SHA256_DIGEST_LENGTH]; EVP_Digest(serializedData.c_str(), serializedData.length(), hash, NULL, EVP_sha256(), NULL); @@ -104,7 +103,7 @@ string Event::generateId(string serializedData) const return ss.str(); }; -bool Event::operator==(const Event& other) const +bool nostr::data::Event::operator==(const Event& other) const { if (this->id.empty()) { @@ -117,5 +116,3 @@ bool Event::operator==(const Event& other) const return this->id == other.id; }; -} // namespace data -} // namespace nostr diff --git a/src/data/filters.cpp b/src/data/filters.cpp index 7e1c744..e345c95 100644 --- a/src/data/filters.cpp +++ b/src/data/filters.cpp @@ -1,13 +1,11 @@ +#include + #include "data/data.hpp" using namespace nlohmann; using namespace std; -namespace nostr -{ -namespace data -{ -string Filters::serialize(string& subscriptionId) +string nostr::data::Filters::serialize(string& subscriptionId) { try { @@ -40,7 +38,7 @@ string Filters::serialize(string& subscriptionId) return jarr.dump(); }; -void Filters::validate() +void nostr::data::Filters::validate() { bool hasLimit = this->limit > 0; if (!hasLimit) @@ -66,5 +64,3 @@ void Filters::validate() throw invalid_argument("Filters::validate: At least one filter must be set."); } }; -} // namespace data -} // namespace nostr -- cgit