diff --git a/tests/mine.py b/tests/mine.py new file mode 100644 index 0000000..96334ab --- /dev/null +++ b/tests/mine.py @@ -0,0 +1,61 @@ +from random import randint, random +from xxhash import xxh32 + +# Generate fast hash +def sha(text): + text = str(text) + return xxh32(text).hexdigest() + +# Check if hashes match +def check(new_hash, zeros): + if new_hash.startswith('0'*zeros): + return True + else: + return False + +pblock = { + "ph": "5bb98b81", + "nonce": 1, + "ts": "Some transaction data" +} + +# Block +ph = sha(pblock) +block = { + "ph": ph, + "nonce": 1, + "ts": "Some transaction data" +} + + +from time import time +start_time = time() + +zeros = 6 +MAX_NONCE = 10**10 +NONCES = list(range(MAX_NONCE)) +print(NONCES) + + +exit() +#for i in range(MAX_NONCE): +while True: + text = block["ph"] + str(block["nonce"]) + block["ts"] + + if check(sha(text), zeros): + print("NONCE: ", block["nonce"]) + print("Hash: ", sha(text)) + break + # Gen new NONCE + #block["nonce"] = i + block["nonce"] = randint(1, MAX_NONCE) + +print("--- %s seconds ---" % (time() - start_time)) + +''' +from time import time +start_time = time() +print("--- %s seconds ---" % (time() - start_time)) +''' + +#17.42