示例#1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",
                        default="localhost",
                        type=str,
                        help="Cluster IP")

    parser.add_argument("--bootstrapip",
                        default="54.70.162.141",
                        type=str,
                        help="Bootstrap Cluster IP")

    parser.add_argument("-i",
                        "--interval",
                        default=10,
                        type=int,
                        help="Query interval in second")

    args = parser.parse_args()

    private_endpoint = "http://{}:38391".format(args.ip)
    private_client = jsonrpcclient.HTTPClient(private_endpoint)

    public_endpoint = "http://{}:38391".format(args.bootstrapip)
    public_client = jsonrpcclient.HTTPClient(public_endpoint)

    query_height(private_client, public_client, args)
def get_work_rpc(shard: Optional[int],
                 host: str = "localhost",
                 jrpc_port: int = 38391,
                 timeout=3) -> MiningWork:
    json_rpc_url = "http://{}:{}".format(host, jrpc_port)
    cli = jsonrpcclient.HTTPClient(json_rpc_url)
    header_hash, height, diff = cli.send(
        jsonrpcclient.Request("getWork",
                              hex(shard) if shard is not None else None),
        timeout=timeout,
    )
    return MiningWork(bytes.fromhex(header_hash[2:]), int(height, 16),
                      int(diff, 16))
def submit_work_rpc(
    shard: Optional[int],
    res: MiningResult,
    host: str = "localhost",
    jrpc_port: int = 38391,
    timeout=3,
) -> bool:
    json_rpc_url = "http://{}:{}".format(host, jrpc_port)
    cli = jsonrpcclient.HTTPClient(json_rpc_url)
    success = cli.send(
        jsonrpcclient.Request(
            "submitWork",
            hex(shard) if shard is not None else None,
            "0x" + res.header_hash.hex(),
            hex(res.nonce),
            "0x" + res.mixhash.hex(),
        ),
        timeout=timeout,
    )
    return success
from decimal import Decimal
import smtplib
from quarkchain.cluster.cluster_config import ClusterConfig
from quarkchain.cluster.master import MasterServer
from quarkchain.cluster.cluster import Cluster
import jsonrpcclient
import logging
import time
from datetime import datetime
import smtplib
import os
import tempfile

TIMEOUT = 10
PRIVATE_ENDPOINT = "http://{}:38491".format("localhost")
PRIVATE_CLIENT = jsonrpcclient.HTTPClient(PRIVATE_ENDPOINT)


def now():
    return datetime.now().strftime("%Y-%m-%d %H:%M:%S")


class HealthCheckCluster(Cluster):
    async def run(self):
        await self.run_master()
        await asyncio.sleep(20)
        check_routing_table(10)
        await self.shutdown()


def check_routing_table(timeout=TIMEOUT):
示例#5
0
def get_jsonrpc_cli(jrpc_url):
    return jsonrpcclient.HTTPClient(jrpc_url)