Example #1
0
def get_blockstack_client_session( new_blockstack_client_session_opts=None ):
    """
    Get or instantiate our storage API session.
    """
    global blockstack_client_session
    global blockstack_client_session_opts

    # do we have storage?
    if blockstack_client is None:
        return None

    opts = None
    if new_blockstack_client_session_opts is not None:
        opts = new_blockstack_client_session_opts
    else:
        opts = blockstack_client.get_config()

    if opts is None:
        return None

    blockstack_client_session = blockstack_client.session( conf=opts )
    if blockstack_client_session is not None:

        if new_blockstack_client_session_opts is not None:
            blockstack_client_session_opts = new_blockstack_client_session_opts

    return blockstack_client_session
def get_blockstack_client_session( new_blockstack_client_session_opts=None ):
    """
    Get or instantiate our storage API session.
    """
    global blockstack_client_session
    global blockstack_client_session_opts

    # do we have storage?
    if blockstack_client is None:
        return None

    opts = None
    if new_blockstack_client_session_opts is not None:
        opts = new_blockstack_client_session_opts
    else:
        opts = blockstack_client.get_config()

    if opts is None:
        return None

    blockstack_client_session = blockstack_client.session( conf=opts )
    if blockstack_client_session is not None:

        if new_blockstack_client_session_opts is not None:
            blockstack_client_session_opts = new_blockstack_client_session_opts

    return blockstack_client_session
Example #3
0
def main(argv):
    """
    Proceed to resolve names forever.
    argv:
        * -p/--password <tor controller password>
        * -P/--port <tor controller port>
        * -H/--blockstack-hostport <blockstack host:port>
    """

    opts_list, prog_args = getopt.getopt(
        sys.argv[1:], 'p:P:H:', ['password='******'port=', 'blockstack-node='])

    password = None
    port = TOR_CONTROL_PORT
    blockstack_hostport = None

    for (argname, argval) in opts_list:
        if argname == '-p' or argname == '--password':
            password = argval

        if argname == '-P' or argname == '--port':
            port = int(argval)

        if argname == '-H' or argname == '--blockstack-node':
            blockstack_hostport = argval

    if blockstack_hostport:
        blockstack_host, blockstack_port = blockstack_client.utils.url_to_host_port(
            blockstack_hostport)
        if blockstack_host is None or blockstack_port is None:
            print >> sys.stderr, "Invalid argument: {}".format(
                blockstack_hostport)
            sys.exit(1)

    blockstack_client.session(server_host=blockstack_host,
                              server_port=blockstack_port,
                              set_global=True)
    controller = connect_tor(password=password, port=port)
    atexit.register(atexit_shutdown, controller)

    while True:
        try:
            time.sleep(1.0)
        except KeyboardInterrupt:
            break
def make_proxy():
    """
    Create a blockstack client API proxy
    """
    global utxo_opts

    client_path = os.environ.get("BLOCKSTACK_CLIENT_CONFIG", None)
    assert client_path is not None

    client_config = blockstack_client.get_config(client_path)
    proxy = blockstack_client.session(conf=client_config)

    proxy.config_path = client_path

    # add in some UTXO goodness
    proxy.get_unspents = get_unspents
    proxy.broadcast_transaction = broadcast_transaction

    return proxy