Husnain commited on
Commit
8e9ecf2
1 Parent(s): 1e96a75
Files changed (1) hide show
  1. networks/proof_worker.py +5 -41
networks/proof_worker.py CHANGED
@@ -1,20 +1,10 @@
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, user_name, difficulty=None, required=False, seed=None):
13
- self.user_name = user_name
14
- self.difficulty = difficulty
15
- self.required = required
16
- self.seed = seed
17
- self.proof_token_prefix = "gAAAAABwQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D"
18
 
19
  def get_parse_time(self):
20
  now = datetime.now()
@@ -36,33 +26,7 @@ class ProofWorker:
36
  OPENAI_GET_HEADERS["User-Agent"],
37
  ]
38
 
39
- def calc_proof_token(self, seed: str, difficulty: str):
40
- try:
41
- config = self.get_config()
42
- diff_len = len(difficulty) // 2
43
- for i in range(100000):
44
- config[3] = i
45
- json_str = json.dumps(config)
46
- base = base64.b64encode(json_str.encode()).decode()
47
- hasher = sha3_512()
48
- hasher.update((seed + base).encode())
49
- hash_val = hasher.digest().hex()
50
- if hash_val[:diff_len] <= difficulty:
51
- return "gAAAAAB" + base
52
- self.proof_token = (
53
- self.proof_token_prefix + base64.b64encode(seed.encode()).decode()
54
- )
55
- return self.proof_token
56
- except Exception as e:
57
- return str(e)
58
-
59
-
60
  if __name__ == "__main__":
61
- user_name = "Niansuh"
62
- seed, difficulty = "0.42665582693491433", "05cdf2"
63
- worker = ProofWorker(user_name)
64
- proof_token = worker.calc_proof_token(seed, difficulty)
65
- decoded_proof_token = base64.b64decode(proof_token.encode()).decode()
66
- print(f"proof_token: {proof_token}")
67
- print(f"decoded_proof_token: {decoded_proof_token}")
68
- # python -m networks.proof_worker
 
 
 
 
1
  import random
 
2
  from datetime import datetime, timedelta, timezone
 
3
  from constants.headers import OPENAI_GET_HEADERS
4
 
 
5
  class ProofWorker:
6
+ def __init__(self):
7
+ pass
 
 
 
 
8
 
9
  def get_parse_time(self):
10
  now = datetime.now()
 
26
  OPENAI_GET_HEADERS["User-Agent"],
27
  ]
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  if __name__ == "__main__":
30
+ worker = ProofWorker()
31
+ config = worker.get_config()
32
+ print("Config:", config)