Skip to content

Instantly share code, notes, and snippets.

@humbdrag
Created January 27, 2022 21:12
Show Gist options
  • Save humbdrag/0bb2d63b6a644797b53e9edc971fe805 to your computer and use it in GitHub Desktop.
Save humbdrag/0bb2d63b6a644797b53e9edc971fe805 to your computer and use it in GitHub Desktop.
Make submission of the mined block pyminer
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