Compare commits
No commits in common. "80befe89a191de5ee40952fc42976fa0b4529b33" and "cd673df9d32574551bd584bb8034a25ff3efe789" have entirely different histories.
80befe89a1
...
cd673df9d3
@ -1,68 +0,0 @@
|
|||||||
from random import randint, random
|
|
||||||
from xxhash import xxh32
|
|
||||||
from time import time
|
|
||||||
|
|
||||||
# Settings
|
|
||||||
global zeros, MAX_NONCE
|
|
||||||
zeros = 6 #DON'T CHANGE!
|
|
||||||
MAX_NONCE = 10**10
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
def mine(block):
|
|
||||||
start_time = time()
|
|
||||||
# New hash
|
|
||||||
text = block["ph"] + str(block["nonce"]) + block["ts"]
|
|
||||||
block["ph"] = sha(text)
|
|
||||||
while True:
|
|
||||||
text = block["ph"] + str(block["nonce"]) + block["ts"]
|
|
||||||
|
|
||||||
if check(sha(text), zeros):
|
|
||||||
print("NONCE: ", block["nonce"])
|
|
||||||
print("Hash: ", sha(text))
|
|
||||||
break
|
|
||||||
block["nonce"] = randint(1, MAX_NONCE)
|
|
||||||
|
|
||||||
print("--- %s seconds ---" % (time() - start_time))
|
|
||||||
return block
|
|
||||||
|
|
||||||
pblock = {
|
|
||||||
"ph": "5bb98b81",
|
|
||||||
"nonce": 1,
|
|
||||||
"ts": "Some transaction data"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Block
|
|
||||||
ph = sha(pblock)
|
|
||||||
block = {
|
|
||||||
"ph": ph,
|
|
||||||
"nonce": 1,
|
|
||||||
"ts": "Some transaction data"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import data
|
|
||||||
#'''
|
|
||||||
while True:
|
|
||||||
block = mine(block)
|
|
||||||
|
|
||||||
# Write blocks
|
|
||||||
blocks = data.mine.read()
|
|
||||||
blocks.append(block)
|
|
||||||
data.mine.write(blocks)
|
|
||||||
#'''
|
|
||||||
|
|
||||||
|
|
||||||
#blocks = data.mine.read()
|
|
||||||
#print(len(blocks))
|
|
Loading…
Reference in New Issue
Block a user