Created
January 27, 2022 21:12
-
-
Save humbdrag/0bb2d63b6a644797b53e9edc971fe805 to your computer and use it in GitHub Desktop.
Make submission of the mined block pyminer
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
submission_str = create_submission_str(block_template) | |
# Define parameters for the RPC. | |
parameters = { | |
"host": "127.0.0.1", | |
"port": "8332", | |
"rpcuser": "Your Username", | |
"rpcpass": "Your Password", | |
"rpcurl": "http://127.0.0.1:8332" | |
} | |
# Construct the RPC request data. | |
rpc_id = random.getrandbits(32) | |
data = json.dumps({ | |
"id": rpc_id, | |
"method": "submitblock", | |
"params": [submission_str] | |
}).encode() | |
auth = base64.b64encode(bytes( | |
parameters["rpcuser"] + ":" + parameters["rpcpass"], | |
"utf8" | |
)) | |
request = urllib.request.Request( | |
parameters["rpcurl"], | |
data, | |
{"Authorization": b"Basic " + auth} | |
) | |
# Send the RPC and parse response. | |
with urllib.request.urlopen(request) as f: | |
response = json.loads(f.read()) | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment