Пример #1
0
    def __init__(self,
                 private_key: str = None,
                 key_password_path: str = None,
                 channel_manager_address: str = None,
                 web3: Web3 = None) -> None:
        is_hex_key = is_hex(private_key) and len(
            remove_0x_prefix(private_key)) == 64
        is_path = os.path.exists(private_key)
        assert is_hex_key or is_path, 'Private key must either be a hex key or a file path.'

        # Load private key from file if none is specified on command line.
        if is_path:
            private_key = get_private_key(private_key, key_password_path)
            assert private_key is not None, 'Could not load private key from file.'

        self.channels = []  # type: List[Channel]

        # Create web3 context if none is provided, either by using the proxies' context or creating
        # a new one.
        if not web3:
            web3 = Web3(HTTPProvider(WEB3_PROVIDER_DEFAULT))

        channel_manager_address = to_checksum_address(
            channel_manager_address or NETWORK_CFG.CHANNEL_MANAGER_ADDRESS)

        self.context = Context(private_key, web3, channel_manager_address)

        self.sync_channels()
Пример #2
0
    def __init__(self,
                 private_key: str = None,
                 key_path: str = None,
                 key_password_path: str = None,
                 channel_manager_address: str = CHANNEL_MANAGER_ADDRESS,
                 web3: Web3 = None) -> None:
        assert private_key or key_path
        assert not private_key or isinstance(private_key, str)

        # Load private key from file if none is specified on command line.
        if not private_key:
            private_key = get_private_key(key_path, key_password_path)
            assert private_key is not None

        self.channels = []  # type: List[Channel]

        # Create web3 context if none is provided, either by using the proxies' context or creating
        # a new one.
        if not web3:
            web3 = Web3(RPCProvider())

        self.context = Context(private_key, web3, channel_manager_address)

        self.sync_channels()