Spaces:
Paused
Paused
Husnain
commited on
✨ [Enhance] Add support for user-defined name in ProofWorker class
Browse files- networks/proof_worker.py +13 -9
networks/proof_worker.py
CHANGED
|
@@ -9,7 +9,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
|
|
@@ -35,7 +36,7 @@ class ProofWorker:
|
|
| 35 |
OPENAI_GET_HEADERS["User-Agent"],
|
| 36 |
]
|
| 37 |
|
| 38 |
-
def calc_proof_token(self, seed: str, difficulty: str
|
| 39 |
config = self.get_config()
|
| 40 |
diff_len = len(difficulty) // 2
|
| 41 |
for i in range(100000):
|
|
@@ -44,16 +45,19 @@ class ProofWorker:
|
|
| 44 |
base = base64.b64encode(json_str.encode()).decode()
|
| 45 |
hasher = sha3_512()
|
| 46 |
hasher.update((seed + base).encode())
|
| 47 |
-
|
| 48 |
-
if
|
| 49 |
return "gAAAAAB" + base
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
|
|
|
| 55 |
seed, difficulty = "0.42665582693491433", "05cdf2"
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
proof_token = worker.calc_proof_token(seed, difficulty, user_id)
|
| 59 |
print(f"proof_token: {proof_token}")
|
|
|
|
|
|
| 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
|
|
|
|
| 36 |
OPENAI_GET_HEADERS["User-Agent"],
|
| 37 |
]
|
| 38 |
|
| 39 |
+
def calc_proof_token(self, seed: str, difficulty: str):
|
| 40 |
config = self.get_config()
|
| 41 |
diff_len = len(difficulty) // 2
|
| 42 |
for i in range(100000):
|
|
|
|
| 45 |
base = base64.b64encode(json_str.encode()).decode()
|
| 46 |
hasher = sha3_512()
|
| 47 |
hasher.update((seed + base).encode())
|
| 48 |
+
hash_val = hasher.digest().hex()
|
| 49 |
+
if hash_val[:diff_len] <= difficulty:
|
| 50 |
return "gAAAAAB" + base
|
| 51 |
+
self.proof_token = (
|
| 52 |
+
self.proof_token_prefix + base64.b64encode(seed.encode()).decode()
|
| 53 |
+
)
|
| 54 |
+
return self.proof_token
|
| 55 |
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
| 58 |
+
user_name = "Niansuh"
|
| 59 |
seed, difficulty = "0.42665582693491433", "05cdf2"
|
| 60 |
+
worker = ProofWorker(user_name)
|
| 61 |
+
proof_token = worker.calc_proof_token(seed, difficulty)
|
|
|
|
| 62 |
print(f"proof_token: {proof_token}")
|
| 63 |
+
# python -m networks.proof_worker
|