Created
May 30, 2020 00:53
-
-
Save lgray/92d876d2d2d05d4add0f83dbcbf621e5 to your computer and use it in GitHub Desktop.
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
import sys | |
import os | |
import requests | |
import argparse | |
import json | |
from uuid import uuid1 | |
import pprint | |
os.environ['NODE_TLS_REJECT_UNAUTHORIZED'] = '0' | |
parser = argparse.ArgumentParser(description='Talk to blockcollider rpc interface.') | |
parser.add_argument('command', type=str, nargs=1, help="The blockcollider RPC command you want to invoke.") | |
parser.add_argument('params', type=str, nargs='*', help="Parameters to the RPC command, often a miner key.") | |
args = parser.parse_args() | |
rpcHost = os.environ.get('BC_RPC_ADDRESS', 'http://localhost:3000') | |
scookie = os.environ.get('BC_RPC_SCOOKIE', 'testCookie123') | |
url = '{0}/rpc'.format(rpcHost) | |
body = {'jsonrpc': '2.0', | |
'id': uuid1().int, | |
'method': args.command[0], | |
'params': args.params} | |
req = requests.post(url, auth=('', scookie), json=body) | |
rjson = req.json() | |
code = rjson.pop('code', 0) | |
if req.status_code == 401: | |
raise Exception("Failed to authenticate, you likely need to set BC_RPC_SCOOKIE to the correct value!") | |
if code != 0: | |
raise Exception(rjson.pop('message')) | |
pprint.pprint(rjson['result']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment