예제 #1
0
def main(
    ctx,
    channel_manager_address,
    ssl_key,
    ssl_cert,
    gas_price,
    state_file,
    private_key,
    private_key_password_file,
    paywall_info,
    rpc_provider,
):
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = privkey_to_addr(private_key)

    constants.paywall_html_dir = paywall_info
    while True:
        try:
            web3 = Web3(
                HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
            NETWORK_CFG.set_defaults(int(web3.version.network))
            channel_manager_address = to_checksum_address(
                channel_manager_address or NETWORK_CFG.CHANNEL_MANAGER_ADDRESS)
            if gas_price is not None:
                NETWORK_CFG.gas_price = gas_price
            if not state_file:
                state_file_name = "%s_%s.db" % (channel_manager_address[:10],
                                                receiver_address[:10])
                app_dir = click.get_app_dir('microraiden')
                if not os.path.exists(app_dir):
                    os.makedirs(app_dir)
                state_file = os.path.join(app_dir, state_file_name)
            app = make_paywalled_proxy(
                private_key,
                state_file,
                contract_address=channel_manager_address,
                web3=web3)
        except StateFileLocked as ex:
            log.warning('Another uRaiden process is already running (%s)!' %
                        str(ex))
        except InsecureStateFile as ex:
            msg = (
                'The permission bits of the state file (%s) are set incorrectly (others can '
                'read or write) or you are not the owner. For reasons of security, '
                'startup is aborted.' % state_file)
            log.fatal(msg)
            raise
        except NetworkIdMismatch as ex:
            log.fatal(str(ex))
            raise
        except requests.exceptions.ConnectionError as ex:
            log.warning("Ethereum node refused connection: %s" % str(ex))
        else:
            break
        sleep(constants.SLEEP_RELOAD)
    ctx.obj = app
예제 #2
0
def start_proxy(receiver_privkey: str) -> PaywalledProxy:
    state_file_name = 'ticker_proxy.db'
    app_dir = click.get_app_dir('microraiden')
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)

    app = make_paywalled_proxy(receiver_privkey, os.path.join(app_dir, state_file_name))
    app.run()
    return app
예제 #3
0
def main(
    ctx,
    channel_manager_address,
    ssl_key,
    ssl_cert,
    gas_price,
    state_file,
    private_key,
    private_key_password_file,
    paywall_info,
    rpc_provider,
):
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = privkey_to_addr(private_key)

    constants.paywall_html_dir = paywall_info
    while True:
        try:
            web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
            NETWORK_CFG.set_defaults(int(web3.version.network))
            channel_manager_address = to_checksum_address(
                channel_manager_address or NETWORK_CFG.CHANNEL_MANAGER_ADDRESS
            )
            if gas_price is not None:
                NETWORK_CFG.gas_price = gas_price
            if not state_file:
                state_file_name = "%s_%s.db" % (
                    channel_manager_address[:10],
                    receiver_address[:10]
                )
                app_dir = click.get_app_dir('microraiden')
                if not os.path.exists(app_dir):
                    os.makedirs(app_dir)
                state_file = os.path.join(app_dir, state_file_name)
            app = make_paywalled_proxy(private_key, state_file,
                                       contract_address=channel_manager_address,
                                       web3=web3)
        except StateFileLocked as ex:
            log.warning('Another uRaiden process is already running (%s)!' % str(ex))
        except InsecureStateFile as ex:
            msg = ('The permission bits of the state file (%s) are set incorrectly (others can '
                   'read or write) or you are not the owner. For reasons of security, '
                   'startup is aborted.' % state_file)
            log.fatal(msg)
            raise
        except NetworkIdMismatch as ex:
            log.fatal(str(ex))
            raise
        except requests.exceptions.ConnectionError as ex:
            log.warning("Ethereum node refused connection: %s" % str(ex))
        else:
            break
        sleep(constants.SLEEP_RELOAD)
    ctx.obj = app
예제 #4
0
def start_proxy(receiver_privkey: str) -> PaywalledProxy:
    state_file_name = 'ticker_proxy.db'
    app_dir = click.get_app_dir('microraiden')
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)

    app = make_paywalled_proxy(receiver_privkey, os.path.join(app_dir, state_file_name))
    app.run()
    return app
예제 #5
0
def main(
    ctx,
    channel_manager_address,
    ssl_key,
    ssl_cert,
    state_file,
    private_key,
    paywall_info,
    rpc_provider,
):
    if private_key is None:
        log.fatal("No private key provided")
        sys.exit(1)
    if utils.check_permission_safety(private_key) is False:
        log.fatal("Private key file %s must be readable only by its owner." %
                  (private_key))
        sys.exit(1)
    with open(private_key) as keyfile:
        private_key = keyfile.readline()[:-1]
    if not is_hex(private_key) or len(decode_hex(private_key)) != 32:
        log.fatal("Private key must be specified as 32 hex encoded bytes")
        sys.exit(1)

    receiver_address = privkey_to_addr(private_key)
    channel_manager_address = channel_manager_address or config.CHANNEL_MANAGER_ADDRESS

    if not state_file:
        state_file_name = "%s_%s.json" % (channel_manager_address[:10],
                                          receiver_address[:10])
        app_dir = click.get_app_dir('microraiden')
        if not os.path.exists(app_dir):
            os.makedirs(app_dir)
        state_file = os.path.join(app_dir, state_file_name)

    config.paywall_html_dir = paywall_info
    web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
    try:
        app = make_paywalled_proxy(private_key, state_file, web3=web3)
    except StateFileLocked as ex:
        log.fatal('Another uRaiden process is already running (%s)!' % str(ex))
        sys.exit(1)
    except InsecureStateFile as ex:
        msg = (
            'The permission bits of the state file (%s) are set incorrectly (others can '
            'read or write) or you are not the owner. For reasons of security, '
            'startup is aborted.' % state_file)
        log.fatal(msg)
        sys.exit(1)
    except NetworkIdMismatch as ex:
        log.fatal(str(ex))
        sys.exit(1)
    except requests.exceptions.ConnectionError as ex:
        log.fatal("Ethereum node refused connection: %s" % str(ex))
        sys.exit(1)
    ctx.obj = app
예제 #6
0
def start_proxy(receiver_privkey: str) -> PaywalledProxy:
    state_file_name = '{}_{}.json'.format(CHANNEL_MANAGER_ADDRESS,
                                          privkey_to_addr(receiver_privkey))
    app_dir = click.get_app_dir('microraiden')
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)

    app = make_paywalled_proxy(receiver_privkey,
                               os.path.join(app_dir, state_file_name))
    app.run()
    return app
예제 #7
0
def main(
    ctx,
    channel_manager_address,
    ssl_key,
    ssl_cert,
    state_file,
    private_key,
    private_key_password_file,
    paywall_info,
    rpc_provider,
):
    private_key = utils.get_private_key(private_key, private_key_password_file)
    if private_key is None:
        sys.exit(1)

    receiver_address = privkey_to_addr(private_key)
    channel_manager_address = channel_manager_address or config.CHANNEL_MANAGER_ADDRESS

    if not state_file:
        state_file_name = "%s_%s.db" % (channel_manager_address[:10],
                                        receiver_address[:10])
        app_dir = click.get_app_dir('microraiden')
        if not os.path.exists(app_dir):
            os.makedirs(app_dir)
        state_file = os.path.join(app_dir, state_file_name)

    config.paywall_html_dir = paywall_info
    web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={'timeout': 60}))
    try:
        app = make_paywalled_proxy(private_key,
                                   state_file,
                                   contract_address=channel_manager_address,
                                   web3=web3)
    except StateFileLocked as ex:
        log.fatal('Another uRaiden process is already running (%s)!' % str(ex))
        sys.exit(1)
    except InsecureStateFile as ex:
        msg = (
            'The permission bits of the state file (%s) are set incorrectly (others can '
            'read or write) or you are not the owner. For reasons of security, '
            'startup is aborted.' % state_file)
        log.fatal(msg)
        sys.exit(1)
    except NetworkIdMismatch as ex:
        log.fatal(str(ex))
        sys.exit(1)
    except requests.exceptions.ConnectionError as ex:
        log.fatal("Ethereum node refused connection: %s" % str(ex))
        sys.exit(1)
    ctx.obj = app
예제 #8
0
def start_proxy(receiver_privkey: str) -> PaywalledProxy:
    state_file_name = '{}_{}.json'.format(CHANNEL_MANAGER_ADDRESS,
                                          privkey_to_addr(receiver_privkey))
    app_dir = click.get_app_dir('microraiden')
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)

    app = make_paywalled_proxy(receiver_privkey,
                               os.path.join(app_dir, state_file_name))
    app.add_content(
        PaywalledProxyUrl("[A-Z]{6}", 1 * TKN_DECIMALS,
                          'http://api.bitfinex.com/v1/pubticker/',
                          [r'[A-Z]{6}']))
    app.run()
    return app
예제 #9
0
def run(join_thread: bool = True):
    dirname = os.path.dirname(state_file_path)
    if dirname:
        os.makedirs(dirname, exist_ok=True)

    app = make_paywalled_proxy(private_key, state_file_path)

    # log.info(app)
    app.add_paywalled_resource(
        cls=Pic4Cash,
        url=FIX_PRICE_URL + "/<string:param>",
        price=5
    )

    # 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
예제 #10
0
파일: app.py 프로젝트: sot528/microraiden
# create a custom web3 provider - parity/geth runs in another container/on another host

while True:
    try:
        web3 = Web3(
            HTTPProvider(config.WEB3_PROVIDER, request_kwargs={'timeout': 60}))
        network_id = web3.version.network
    except ConnectionError:
        log.critical(
            "Ethereum node isn't responding. Restarting after %d seconds." %
            (config.SLEEP_RELOAD))
        gevent.sleep(config.SLEEP_RELOAD)
    else:
        break

# create flask app
app = Flask(__name__, static_url_path=JSPREFIX_URL, static_folder=JSLIB_DIR)

# create microraiden app
microraiden_app = make_paywalled_proxy(config.PRIVATE_KEY,
                                       config.STATE_FILE,
                                       web3=web3,
                                       flask_app=app)
# add some content
microraiden_app.add_content(
    PaywalledProxyUrl(".*", 1 * TKN_DECIMALS, "http://en.wikipedia.org/",
                      [r"wiki/.*"]))

# only after blockchain is fully synced the app is ready to serve requests
microraiden_app.channel_manager.wait_sync()
예제 #11
0
)
from microraiden.make_helpers import make_paywalled_proxy
from microraiden.config import TKN_DECIMALS

if __name__ == '__main__':
    private_key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    state_file_name = 'echo_server.json'
    app_dir = click.get_app_dir('microraiden')
    if not os.path.exists(app_dir):
        os.makedirs(app_dir)
    state_file_name = os.path.join(app_dir, state_file_name)
    # set up a paywalled proxy
    # arguments are:
    #  - private key to use for receiving funds
    #  - file for storing state information (balance proofs)
    app = make_paywalled_proxy(private_key, state_file_name)

    # Add resource defined by regex and with a fixed price of 1 token
    # We setup the resource to return whatever is supplied as a second argument
    #  in the URL.
    app.add_content(PaywalledContent(
                    "echofix\/[a-zA-Z0-9]+", 1 * TKN_DECIMALS,
                    lambda request: (request.split("/")[1], 200)))
    # Resource with a price determined by the second parameter
    app.add_content(PaywalledContent(
                    "echodyn\/[0-9]+",
                    lambda request: int(request.split("/")[1]) * TKN_DECIMALS,
                    lambda request: (int(request.split("/")[1]), 200)))
    app.add_content(PaywalledProxyUrl(
                    "p\/[0-9]+",
                    1 * TKN_DECIMALS,