blob: 17008a98271717b09006fdeed556231c18453467 (
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
|
import hashlib
import json
from enum import Enum
from time import time
class EventKind(Enum):
SET_METADATA = 0
TEXT_NOTE = 1
RECOMMEND_SERVER = 2
class Event:
def __init__(self, pubkey, content, tags=None, created_at=None):
self.pubkey = pubkey.lower()
self.created_at = created_at or int(time())
self.kind = 0
self.tags = tags or []
self.content = content
self.sig = 0
self.id = self.get_event_id()
def get_event_id(self):
data = [0, self.pubkey, self.created_at, self.kind, self.tags, self.content]
jd = json.dumps(data).encode("utf-8")
return hashlib.sha256(jd).hexdigest()
|