Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _create_jsonrpc_params(self, method: RestMethod, params: Optional[NamedTuple]):
# 'vars(namedtuple)' does not working in Python 3.7.4
# noinspection PyProtectedMember
params = params._asdict() if params else None
if params:
params = { k: v for k, v in params.items() if v is not None}
if "from_" in params:
params["from"] = params.pop("from_")
return Request(method.value.name, params) if params else Request(method.value.name)
def checkHeight(private_client, public_client, timeout=TIMEOUT):
result_private = private_client.send(
jsonrpcclient.Request("getRootBlockByHeight"),
timeout=timeout,)
result_public = public_client.send(
jsonrpcclient.Request("getRootBlockByHeight"),
timeout=timeout,)
return {
"height": int(result_private["height"], 16),
"currentHeight": int(result_public["height"], 16),
}
def get_work_rpc(
full_shard_id: Optional[int],
host: str = "localhost",
jrpc_port: int = 38391,
timeout=TIMEOUT,
) -> MiningWork:
jrpc_url = "http://{}:{}".format(host, jrpc_port)
cli = get_jsonrpc_cli(jrpc_url)
header_hash, height, diff = cli.send(
jsonrpcclient.Request(
"getWork", hex(full_shard_id) if full_shard_id is not None else None
),
timeout=timeout,
)
return MiningWork(bytes.fromhex(header_hash[2:]), int(height, 16), int(diff, 16))
def submit_work_rpc(
full_shard_id: Optional[int],
res: MiningResult,
host: str = "localhost",
jrpc_port: int = 38391,
timeout=TIMEOUT,
) -> bool:
jrpc_url = "http://{}:{}".format(host, jrpc_port)
cli = get_jsonrpc_cli(jrpc_url)
success = cli.send(
jsonrpcclient.Request(
"submitWork",
hex(full_shard_id) if full_shard_id is not None else None,
"0x" + res.header_hash.hex(),
hex(res.nonce),
"0x" + res.mixhash.hex(),
),
timeout=timeout,
)
return success
def checkHeight(private_client, public_client, timeout=TIMEOUT):
result_private = private_client.send(
jsonrpcclient.Request("getRootBlockByHeight"),
timeout=timeout,)
result_public = public_client.send(
jsonrpcclient.Request("getRootBlockByHeight"),
timeout=timeout,)
return {
"height": int(result_private["height"], 16),
"currentHeight": int(result_public["height"], 16),
}