Esempio n. 1
0
def test_client_server():
    init_logging()

    run = asyncio.get_event_loop().run_until_complete

    path = pathlib.Path(tempfile.mkdtemp(), "port")
    server_task = serve_api_on_unix_port(test_api(), path)

    run(client_test(path))
    server_task.cancel()
Esempio n. 2
0
def make_client_server():
    init_logging()
    run = asyncio.get_event_loop().run_until_complete
    path = pathlib.Path(tempfile.mkdtemp(), "port")
    server, aiter = run(start_unix_server_aiter(path))
    rws_aiter = map_aiter(lambda rw: dict(
        reader=rw[0], writer=rw[1], server=server), aiter)
    initial_block_hash = bytes(([0] * 31) + [1])
    ledger = ledger_api.LedgerAPI(initial_block_hash, RAM_DB())
    server_task = asyncio.ensure_future(api_server(rws_aiter, ledger))
    remote = run(proxy_for_unix_connection(path))
    # make sure server_task isn't garbage collected
    remote.server_task = server_task
    return remote
Esempio n. 3
0
def test_client_server():
    init_logging()

    run = asyncio.get_event_loop().run_until_complete

    path = pathlib.Path(tempfile.mkdtemp(), "port")

    server, aiter = run(start_unix_server_aiter(path))

    rws_aiter = map_aiter(
        lambda rw: dict(reader=rw[0], writer=rw[1], server=server), aiter)

    initial_block_hash = bytes(([0] * 31) + [1])
    ledger = ledger_api.LedgerAPI(initial_block_hash, RAM_DB())
    server_task = asyncio.ensure_future(api_server(rws_aiter, ledger))

    run(client_test(path))
    server_task.cancel()
Esempio n. 4
0
def main(args=sys.argv):
    parser = argparse.ArgumentParser(
        description="Chia ledger simulator."
    )
    parser.add_argument("-p", "--port", help="remote port", default=9868)
    parser.set_defaults(func=ledger_command)

    args = parser.parse_args(args=args[1:])

    init_logging()

    run = asyncio.get_event_loop().run_until_complete

    tasks = set()

    tasks.add(asyncio.ensure_future(args.func(args)))

    run(asyncio.wait(tasks))
Esempio n. 5
0
def main(args=sys.argv):
    parser = argparse.ArgumentParser(description="Chia client.")

    parser.add_argument("-p", "--port", help="remote port", default=9868)
    parser.add_argument("host", help="remote host")
    parser.add_argument("function", help="function")
    parser.add_argument("arguments",
                        help="arguments (as json)",
                        type=json.loads)

    args = parser.parse_args(args=args[1:])

    init_logging()

    run = asyncio.get_event_loop().run_until_complete

    reader, writer = run(asyncio.open_connection(args.host, args.port))
    ledger_api = request_response_proxy(reader, writer)

    r = run(getattr(ledger_api, args.function)(**args.arguments))
    print(r)