Husnain
commited on
Commit
•
744e0f5
1
Parent(s):
6cad06d
Update proof_worker.py
Browse files- networks/proof_worker.py +22 -9
networks/proof_worker.py
CHANGED
@@ -1,12 +1,19 @@
|
|
1 |
import base64
|
|
|
2 |
import json
|
3 |
import random
|
|
|
4 |
from datetime import datetime, timedelta, timezone
|
|
|
5 |
from constants.headers import OPENAI_GET_HEADERS
|
6 |
|
|
|
7 |
class ProofWorker:
|
8 |
-
def __init__(self):
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
def get_parse_time(self):
|
12 |
now = datetime.now()
|
@@ -35,14 +42,20 @@ class ProofWorker:
|
|
35 |
config[3] = i
|
36 |
json_str = json.dumps(config)
|
37 |
base = base64.b64encode(json_str.encode()).decode()
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
-
worker = ProofWorker()
|
44 |
-
config = worker.get_config()
|
45 |
-
print("Config:", config)
|
46 |
seed, difficulty = "0.42665582693491433", "05cdf2"
|
|
|
47 |
proof_token = worker.calc_proof_token(seed, difficulty)
|
48 |
-
print(f"
|
|
|
|
1 |
import base64
|
2 |
+
from hashlib import sha3_512
|
3 |
import json
|
4 |
import random
|
5 |
+
|
6 |
from datetime import datetime, timedelta, timezone
|
7 |
+
|
8 |
from constants.headers import OPENAI_GET_HEADERS
|
9 |
|
10 |
+
|
11 |
class ProofWorker:
|
12 |
+
def __init__(self, difficulty=None, required=False, seed=None):
|
13 |
+
self.difficulty = difficulty
|
14 |
+
self.required = required
|
15 |
+
self.seed = seed
|
16 |
+
self.proof_token_prefix = "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D"
|
17 |
|
18 |
def get_parse_time(self):
|
19 |
now = datetime.now()
|
|
|
42 |
config[3] = i
|
43 |
json_str = json.dumps(config)
|
44 |
base = base64.b64encode(json_str.encode()).decode()
|
45 |
+
hasher = sha3_512()
|
46 |
+
hasher.update((seed + base).encode())
|
47 |
+
hash = hasher.digest().hex()
|
48 |
+
if hash[:diff_len] <= difficulty:
|
49 |
+
return "gAAAAAB" + base
|
50 |
+
self.proof_token = (
|
51 |
+
self.proof_token_prefix + base64.b64encode(seed.encode()).decode()
|
52 |
+
)
|
53 |
+
return self.proof_token
|
54 |
+
|
55 |
|
56 |
if __name__ == "__main__":
|
|
|
|
|
|
|
57 |
seed, difficulty = "0.42665582693491433", "05cdf2"
|
58 |
+
worker = ProofWorker()
|
59 |
proof_token = worker.calc_proof_token(seed, difficulty)
|
60 |
+
print(f"proof_token: {proof_token}")
|
61 |
+
# python -m networks.proof_worker
|