-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenesis.py
69 lines (58 loc) · 1.51 KB
/
genesis.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import time
import random
import uuid
import base58
import hashlib
from nacl.encoding import HexEncoder
from nacl.signing import SigningKey
from src.models import Ask, Vote
from pymongo import MongoClient
cli = MongoClient('localhost', 27017)
db = cli.yat
txs = db.tx
asks = db.asks
votes = db.votes
def tob2b(t):
h = hashlib.blake2b()
h.update(t)
return base58.b58encode(h.digest())
sk = 'DQsYfHpJ9WAGai9JJ1eDntkx4CpeCAbhPi2MrPDiwYs5'
sk_bytes = base58.b58decode(sk.encode())
pk = 'B3qUs7s5C5G4n7V5x2XE4JMWzPMvVXWRzkxfp76zgs6t'
amount = 1000000000000
uniq = str(uuid.uuid4())
m = pk + str(amount) + str(uniq)
signing_key = SigningKey(sk_bytes)
message_bytes = bytes(m.encode("utf-8"))
signed = base58.b58encode(signing_key.sign(message_bytes))
hash_ask = tob2b(signed)
a = Ask(addr = pk,
amount = amount,
uniq = uniq,
title = '',
cover = '',
desc = '',
sign = signed,
prev_hash = '',
hash = hash_ask,
time = int(round(time.time() * 1000)))
r = asks.insert_one(dict(a))
if r.inserted_id: print(r.inserted_id)
uniq = str(uuid.uuid4())
like = True
m = pk + str(hash_ask) + str(like) + str(uniq)
message_bytes = bytes(m.encode("utf-8"))
signed = base58.b58encode(signing_key.sign(message_bytes))
hash_vote = tob2b(signed)
v = Vote(addr = pk,
id = hash_ask,
like = like,
uniq = uniq,
sign = signed,
prev_hash = '',
hash = hash_vote,
time = int(round(time.time() * 1000)))
r = votes.insert_one(dict(v))
if r.inserted_id: print(r.inserted_id)
print(a)
print(v)