コード例 #1
0
def init(http_client: HTTPClient = None,
         client: Client = None,
         privkey: str = None,
         key_path: str = None,
         key_password_path: str = None,
         channel_manager_address: str = CHANNEL_MANAGER_ADDRESS,
         web3: Web3 = None,
         retry_interval: float = 5,
         initial_deposit: Callable[[int], int] = lambda price: 10 * price,
         topup_deposit: Callable[[int], int] = lambda price: 5 * price):
    """
    TODO: document which of these arguments are actually needed in different use cases.
    """
    global _http_client

    if http_client is None:
        if client is None:
            client = Client(private_key=privkey,
                            key_path=key_path,
                            key_password_path=key_password_path,
                            channel_manager_address=channel_manager_address,
                            web3=web3)
        _http_client = DefaultHTTPClient(client=client,
                                         retry_interval=retry_interval,
                                         initial_deposit=initial_deposit,
                                         topup_deposit=topup_deposit)
    else:
        _http_client = http_client
コード例 #2
0
    def __init__(
            self,
            sender_privkey: str,
            httpclient: DefaultHTTPClient = None
    ):
        self.root = tkinter.Tk()
        ttk.Frame.__init__(self, self.root)
        self.root.title('µRaiden ETH Ticker')
        self.root.protocol('WM_DELETE_WINDOW', self.close)
        self.pack()
        self.pricevar = tkinter.StringVar(value='0.00 USD')
        ttk.Label(self, textvariable=self.pricevar, font=('Helvetica', '72')).pack()

        if httpclient:
            self.httpclient = httpclient
            self.client = httpclient.client
        else:
            self.client = Client(sender_privkey)
            self.httpclient = DefaultHTTPClient(
                self.client,
                'localhost',
                5000,
                initial_deposit=lambda x: 10 * x,
                topup_deposit=lambda x: 5 * x
            )

        self.active_query = False
        self.running = False
コード例 #3
0
def run(key_path, key_password_path, resource):
    # create the client
    with Client(key_path=key_path, key_password_path=key_password_path) as client:
        m2mclient = DefaultHTTPClient(
            client,
            'localhost',
            5000
        )

        # Get the resource. If payment is required, client will attempt to create
        # a channel or will use existing one.
        status, headers, body = m2mclient.run(resource)
        if status == requests.codes.OK:
            if re.match('^text\/', headers['Content-Type']):
                logging.info("got the resource %s type=%s\n%s" % (
                    resource,
                    headers.get('Content-Type', '???'),
                    body))
            else:
                logging.info("got the resource %s type=%s" % (
                    resource,
                    headers.get('Content-Type', '???')))
        else:
            logging.error("error getting the resource. code=%d body=%s" %
                          (status, body.decode().strip()))
コード例 #4
0
def init(privkey: str = None,
         key_path: str = None,
         key_password_path: str = None,
         channel_manager_address: str = CHANNEL_MANAGER_ADDRESS,
         web3: Web3 = None,
         channel_manager_proxy: ChannelContractProxy = None,
         token_proxy: ContractProxy = None,
         contract_metadata: dict = CONTRACT_METADATA,
         retry_interval: float = 5,
         initial_deposit: Callable[[int], int] = lambda price: 10 * price,
         topup_deposit: Callable[[int], int] = lambda price: 5 * price):
    global client
    global http_client
    client = Client(privkey=privkey,
                    key_path=key_path,
                    key_password_path=key_password_path,
                    channel_manager_address=channel_manager_address,
                    web3=web3,
                    channel_manager_proxy=channel_manager_proxy,
                    token_proxy=token_proxy,
                    contract_metadata=contract_metadata)
    http_client = DefaultHTTPClient(client=client,
                                    retry_interval=retry_interval,
                                    initial_deposit=initial_deposit,
                                    topup_deposit=topup_deposit)
コード例 #5
0
ファイル: client.py プロジェクト: tominop/microraiden
def client(sender_privkey: str, client_contract_proxy: ChannelContractProxy,
           client_token_proxy: ContractProxy, datadir: str):
    client = Client(privkey=sender_privkey,
                    channel_manager_proxy=client_contract_proxy,
                    token_proxy=client_token_proxy,
                    datadir=datadir)
    yield client
    client.close()
コード例 #6
0
def openChannel():
    global channel_object
    with Client(config.privkey) as client:
        channel_object = client.get_suitable_channel(
            config.receiver, int(utils.convert_to_utf(request.get_data())))
        if not channel_object:
            return json.dumps(utils.error)
        return json.dumps(utils.ok)
コード例 #7
0
def client(sender_privkey, client_contract_proxy, client_token_proxy, datadir,
           channel_manager_contract_address, token_contract_address):
    client = Client(privkey=sender_privkey,
                    channel_manager_proxy=client_contract_proxy,
                    token_proxy=client_token_proxy,
                    datadir=datadir,
                    channel_manager_address=channel_manager_contract_address,
                    token_address=token_contract_address)
    yield client
    client.close()
コード例 #8
0
def test_filelock(sender_privkey, client_contract_proxy, client_token_proxy,
                  datadir, channel_manager_contract_address,
                  token_contract_address):
    kwargs = {
        'privkey': sender_privkey,
        'channel_manager_proxy': client_contract_proxy,
        'token_proxy': client_token_proxy,
        'datadir': datadir,
        'channel_manager_address': channel_manager_contract_address,
        'token_address': token_contract_address
    }
    client = Client(**kwargs)
    client.close()

    client = Client(**kwargs)
    with pytest.raises(filelock.Timeout):
        Client(**kwargs)
    client.close()

    with Client(**kwargs):
        pass

    with Client(**kwargs):
        with pytest.raises(filelock.Timeout):
            Client(**kwargs)
コード例 #9
0
def client(sender_privkey: str, client_contract_proxy: ChannelContractProxy,
           client_token_proxy: ContractProxy, clean_channels: bool,
           receiver_privkey: str, revert_chain):
    client = Client(privkey=sender_privkey,
                    channel_manager_proxy=client_contract_proxy,
                    token_proxy=client_token_proxy)
    if clean_channels:
        close_all_channels_cooperatively(client, receiver_privkey, balance=0)

    yield client

    if clean_channels:
        close_all_channels_cooperatively(client, receiver_privkey, balance=0)
コード例 #10
0
def client(sender_privkey: str, channel_manager_address: str, web3: Web3,
           clean_channels: bool, receiver_privkey: str, patched_contract,
           revert_chain):
    client = Client(private_key=sender_privkey,
                    channel_manager_address=channel_manager_address,
                    web3=web3)
    if clean_channels:
        close_all_channels_cooperatively(client, receiver_privkey, balance=0)

    yield client

    if clean_channels:
        close_all_channels_cooperatively(client, receiver_privkey, balance=0)
コード例 #11
0
ファイル: test_client.py プロジェクト: theHour/microraiden
def test_client_private_key_path(
        patched_contract,
        monkeypatch: MonkeyPatch,
        sender_privkey: str,
        tmpdir: LocalPath,
        web3: Web3,
        channel_manager_address: str
):
    def check_permission_safety_patched(path: str):
        return True

    monkeypatch.setattr(
        microraiden.utils.private_key,
        'check_permission_safety',
        check_permission_safety_patched
    )

    privkey_file = tmpdir.join('private_key.txt')
    privkey_file.write(sender_privkey)

    with pytest.raises(AssertionError):
        Client(
            private_key='0xthis_is_not_a_private_key',
            channel_manager_address=channel_manager_address,
            web3=web3
        )

    with pytest.raises(AssertionError):
        Client(
            private_key='0xcorrect_length_but_still_not_a_private_key_12345678901234567',
            channel_manager_address=channel_manager_address,
            web3=web3
        )

    with pytest.raises(AssertionError):
        Client(
            private_key='/nonexisting/path',
            channel_manager_address=channel_manager_address,
            web3=web3
        )

    Client(
        private_key=sender_privkey,
        channel_manager_address=channel_manager_address,
        web3=web3
    )

    Client(
        private_key=sender_privkey[2:],
        channel_manager_address=channel_manager_address,
        web3=web3
    )

    Client(
        private_key=str(tmpdir.join('private_key.txt')),
        channel_manager_address=channel_manager_address,
        web3=web3
    )
コード例 #12
0
def run(api_endpoint, api_port, **kwargs):
    exclude_kwargs = {'close_channels'}
    kwargs_client = {
        key: value
        for key, value in kwargs.items() if value and key not in exclude_kwargs
    }
    with Client(**kwargs_client) as client:
        m2mclient = DefaultHTTPClient(client, api_endpoint, api_port)
        resource = m2mclient.run('doggo.jpg')
        log.info('Response: {}'.format(resource))

        if kwargs['close_channels'] is True:
            for channel in client.channels:
                if channel.state == Channel.State.open:
                    channel.close_channel()
コード例 #13
0
ファイル: test1.py プロジェクト: iluxa/microraiden
receiver_key = '0xdd880da44adb44c91005bc7d51d877627ebfc3a45f67ec7f1be926939af79808'
receiver_address = '0x09226F56C5699E2d87700179507cf25FA2F79F6b'

sender_key = '0x1e8b64bcdbaa6cc995e2f325318ba48d58847e0af229670e0fdbd827033c8de0'
sender_address = '0xA7Ac54048B81041dbD527B603175C17473CE2d95'

#cm_address = '0x45fe9a68af651cc5c0fb2c3afc24bb7205eb7e27'
#cm_address = '0xa18bdF0EdEDc0a43C70D00230AbB691b71D9dcC4'
#cm_address = '0x0f83dc382D4B0880b5e06430F49B0d12dD6fE744'
cm_address = '0xB69c353cbA3be3f33910C7c5fFA54C228bde8934'
#fname = "./test1.data"
#fname = "/home/ilya/.config/microraiden/0x45fe9a68_0x09226F56.db"
fname = "/home/ilya/.config/microraiden/0xB69c353c_0x09226F56.db"
cm = make_channel_manager(receiver_key, cm_address, fname, w3)
#client = Client(receiver_key, receiver_key, cm_address, w3);
client = Client(sender_key, sender_key, cm_address, w3)
#ch = open_channel(cm, client, receiver_address)
#ch = client.get_open_channels(receiver_address);
#ch = client.channels;
ch = cm.channels
#ch = client.get_suitable_channel(receiver_address, 1);
#ch = client.get_open_channels(sender_address);
print("ch: ", ch)
block_num = 2006163
id = ('0xA7Ac54048B81041dbD527B603175C17473CE2d95', block_num)
ccc = {
    'sender': '0xA7Ac54048B81041dbD527B603175C17473CE2d95',
    'block': block_num
}
#print("sender: ", ch[id].sender)
print("sender: ", ch[id])