Last active
May 8, 2019 00:19
-
-
Save mitche50/fe617860491e552139cd84ff2f9a23e5 to your computer and use it in GitHub Desktop.
Send a nano transaction and monitor the work every 3 seconds to see if there has been automated rework done - Beta Node Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Before running, make sure to update the path for the log file and your source / destination accounts and wallet. | |
""" | |
import time | |
import logging | |
import requests | |
import json | |
# Set Log File | |
logging.basicConfig(handlers=[logging.FileHandler('/path/to/rework.log', 'a', 'utf-8')], | |
level=logging.INFO) | |
source = "" | |
destination = "" | |
amount = 10 | |
wallet = "" | |
# Get the frontier for the source account | |
data = { | |
"action": "account_info", | |
"account": source | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
frontier = rx["frontier"] | |
# Generate work at base difficulty | |
data = { | |
"action": "work_generate", | |
"hash": frontier, | |
"difficulty": "ffffffc000000000" | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
work = rx["work"] | |
# Send the transaction | |
data = { | |
"action": "send", | |
"wallet": wallet, | |
"source": source, | |
"destination": destination, | |
"amount": amount | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
send_hash = rx["block"] | |
# First block_info call - log original work and previous hash for work validate | |
data = { | |
"action": "block_info", | |
"hash": send_hash, | |
"json_block": "true" | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
original_work = rx["contents"]["work"] | |
previous = rx["contents"]["previous"] | |
# Retrieve the multiplier | |
data = { | |
'action': 'work_validate', | |
'work': original_work, | |
'hash': previous | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
original_difficulty = rx["multiplier"] | |
root = previous+previous | |
print("Original difficulty for block {} = {} - {}".format(send_hash, original_work, original_difficulty)) | |
logging.info("Original difficulty for block {} = {} - {}".format(send_hash, original_work, original_difficulty)) | |
while True: | |
# Wait 3 seconds between polling the node for new work information | |
time.sleep(3) | |
data = { | |
"action": "block_info", | |
"hash": send_hash, | |
"json_block": "true" | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
confirmed = rx["confirmed"] | |
final_work = rx["contents"]["work"] | |
if confirmed == "true": | |
print("Transaction confirmed.") | |
logging.info("Transaction confirmed.") | |
print("Final work: {}".format(final_work)) | |
logging.info("Final work: {}".format(final_work)) | |
break | |
data = { | |
"action": "confirmation_info", | |
"root": root, | |
"contents":"true", | |
"json_block": "true" | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
blocks = rx['blocks'] | |
new_work = blocks[send_hash]["contents"]["work"] | |
# If the work values are different, check what the new multiplier is. | |
if new_work != original_work: | |
data = { | |
'action': 'work_validate', | |
'work': new_work, | |
'hash': previous | |
} | |
response = requests.post("http://[::1]:55000", json.dumps(data)) | |
rx = response.json() | |
new_difficulty = rx["multiplier"] | |
print("New difficulty for block {} = {} - {}".format(send_hash, new_work, new_difficulty)) | |
logging.info("New difficulty for block {} = {} - {}".format(send_hash, new_work, new_difficulty)) | |
original_work = new_work | |
else: | |
print("No change in work") | |
logging.info("No change in work") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment