Exemplo n.º 1
0
def run(private_key: str,
        state_file_path: str = os.path.join(click.get_app_dir('microraiden'),
                                            'echo_server.db'),
        channel_manager: ChannelManager = None,
        join_thread: bool = True):
    dirname = os.path.dirname(state_file_path)
    if dirname:
        os.makedirs(dirname, exist_ok=True)

    # set up a paywalled proxy
    # arguments are:
    #  - private key to use for receiving funds
    #  - file for storing state information (balance proofs)
    if channel_manager is None:
        web3 = Web3(HTTPProvider(WEB3_PROVIDER_DEFAULT))
        NETWORK_CFG.set_defaults(int(web3.version.network))
        channel_manager = make_channel_manager(
            private_key, NETWORK_CFG.CHANNEL_MANAGER_ADDRESS, state_file_path,
            web3)
    app = PaywalledProxy(channel_manager)

    # Add resource defined by regex and with a fixed price of 1 token.
    app.add_paywalled_resource(StaticPriceResource,
                               "/echofix/<string:param>",
                               price=5)
    # Resource with a price determined by the second parameter.
    app.add_paywalled_resource(DynamicPriceResource, "/echodyn/<int:param>")

    # Start the app. proxy is a WSGI greenlet, so you must join it properly.
    app.run(debug=True)

    if join_thread:
        app.join()
    else:
        return app
Exemplo n.º 2
0
def run(private_key: str,
        state_file_path: str = os.path.join(click.get_app_dir('microraiden'),
                                            'stream.db'),
        channel_manager: ChannelManager = None,
        join_thread: bool = True):
    dirname = os.path.dirname(state_file_path)

    if dirname:
        os.makedirs(dirname, exist_ok=True)

    if channel_manager is None:
        web3 = Web3(HTTPProvider(WEB3_PROVIDER_DEFAULT))
        NETWORK_CFG.set_defaults(int(web3.version.network))
        channel_manager = make_channel_manager(
            private_key, NETWORK_CFG.CHANNEL_MANAGER_ADDRESS, state_file_path,
            web3)

    app = PaywalledProxy(channel_manager)

    app.add_paywalled_resource(StreamResource,
                               "/stream/<string:param>",
                               price=1 * TKN_DECIMALS)

    app.run(host="localhost", port=5000, debug=True)

    if join_thread:
        app.join()
    else:
        return app
Exemplo n.º 3
0
def run(
        private_key: str,
        rpc_provider: str,
        state_file_path: str = os.path.join('./channel.db'),
        channel_manager: ChannelManager = None,
        join_thread: bool = True,
):
    dirname = os.path.dirname(state_file_path)
    if dirname:
        os.makedirs(dirname, exist_ok=True)

    if channel_manager is None:
        web3 = Web3(HTTPProvider(rpc_provider))
        NETWORK_CFG.set_defaults(int(web3.version.network))
        channel_manager = make_channel_manager(
            private_key, NETWORK_CFG.CHANNEL_MANAGER_ADDRESS, state_file_path,
            web3)
    app = PaywalledProxy(channel_manager)

    app.run(host="0.0.0.0", port=5000, debug=True)

    if join_thread:
        app.join()
    else:
        return app
Exemplo n.º 4
0
def run(private_key: str,
        state_file_path: str = './db/echo_server.db',
        channel_manager: ChannelManager = None,
        join_thread: bool = True):
    dirname = os.path.dirname(state_file_path)
    if dirname:
        os.makedirs(dirname, exist_ok=True)

    log.info('(manager %s, token %s)',
             channel_manager.channel_manager_contract.address,
             channel_manager.token_contract.address)

    #config_client = json.load(open('client.json'))
    #config_client['manager'] = channel_manager.channel_manager_contract.address
    #config_client['token'] = channel_manager.token_contract.address
    #json.dump(config_client, open('client.json', 'w'))

    #config_monitor = json.load(open('monitor.json'))
    #config_monitor['manager'] = channel_manager.channel_manager_contract.address
    #config_monitor['token'] = channel_manager.token_contract.address
    #json.dump(config_monitor, open('monitor.json', 'w'))

    #log.info(
    #    'Updated manager address in monitor and client configs.'
    #)

    # set up a paywalled proxy
    # arguments are:
    #  - private key to use for receiving funds
    #  - file for storing state information (balance proofs)

    if channel_manager is None:
        raise Exception('Channel Manager not created!')

    app = PaywalledProxy(channel_manager)

    # Add resource defined by regex and with a fixed price of 1 token.
    app.add_paywalled_resource(StaticPriceResource,
                               "/echofix/<string:param>",
                               price=5)
    # Resource with a price determined by the second parameter.
    app.add_paywalled_resource(DynamicPriceResource, "/echodyn/<int:param>")

    # Start the app. proxy is a WSGI greenlet, so you must join it properly.
    app.run(debug=True, host='0.0.0.0')

    if join_thread:
        app.join()
    else:
        return app