aboutsummaryrefslogtreecommitdiff
path: root/src/event.cpp
blob: 75f2ee88b9a62ef25a3894ac93d91c80b09a56f7 (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
38
#pragma once

#include <string>
#include <vector>
#include <nlohmann/json.hpp>

#include "nostr.hpp"

using std::string;

namespace nostr 
{
    nlohmann::json Event::serialize() const
    {
        nlohmann::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)
    {
        nlohmann::json j = nlohmann::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"];
    };
}