aboutsummaryrefslogtreecommitdiff
path: root/src/event.cpp
blob: 0e4e15981e12f6d1c2ca7e3a7033ba0352d3e430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <string>
#include <vector>
#include <nlohmann/json.hpp>

#include "nostr.hpp"

using nlohmann::json;
using std::string;

namespace nostr 
{
json Event::serialize() const
{
    json j = {
        {"id", this->id},
        {"pubkey", this->pubkey},
        {"created_at", this->created_at},
        {"kind", this->kind},
        {"tags", this->tags},
        {"content", this->content},
        {"sig", this->sig}
    };
    return j.dump();
};

void Event::deserialize(string jsonString)
{
    json j = json::parse(jsonString);
    this->id = j["id"];
    this->pubkey = j["pubkey"];
    this->created_at = j["created_at"];
    this->kind = j["kind"];
    this->tags = j["tags"];
    this->content = j["content"];
    this->sig = j["sig"];
};
} // namespace nostr