diff options
author | buttercat1791 <mjjurkoic@gmail.com> | 2024-05-27 12:09:41 -0500 |
---|---|---|
committer | buttercat1791 <mjjurkoic@gmail.com> | 2024-05-27 12:09:41 -0500 |
commit | 32bb72b527966c1b7324afcd7fae466fc84b30d6 (patch) | |
tree | b0139829be0ae63b1333a9b857bee70ab2b3b5d1 /src/data | |
parent | 1d6b704c15ee289037447fb566e7583962496650 (diff) |
refactor so no project header imports nostr.hpp
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/event.cpp | 21 | ||||
-rw-r--r-- | src/data/filters.cpp | 12 |
2 files changed, 13 insertions, 20 deletions
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 <sstream> +#include <stdexcept> + #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 <stdexcept> + #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 |