Пример #1
0
    def __init__(
            self,
            token_network: TokenNetwork,
            channel_identifier: typing.ChannelID,
    ):
        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=token_network.address,
            channel_identifier=channel_identifier,
            event_name=EVENT_CHANNEL_OPENED,
        )

        events = token_network.proxy.contract.web3.eth.getLogs(filter_args)
        if not len(events) > 0:
            raise ValueError('Channel is non-existing.')

        event = decode_event(CONTRACT_MANAGER.get_contract_abi(CONTRACT_TOKEN_NETWORK), events[-1])
        participant1 = decode_hex(event['args']['participant1'])
        participant2 = decode_hex(event['args']['participant2'])

        if token_network.node_address not in (participant1, participant2):
            raise ValueError('One participant must be the node address')

        if token_network.node_address == participant2:
            participant1, participant2 = participant2, participant1

        self.channel_identifier = channel_identifier
        self.channel_operations_lock = RLock()
        self.participant1 = participant1
        self.participant2 = participant2
        self.token_network = token_network
Пример #2
0
    def __init__(
        self,
        token_network: TokenNetwork,
        channel_identifier: typing.ChannelID,
    ):
        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=token_network.address,
            channel_identifier=channel_identifier,
            event_name=EVENT_CHANNEL_OPENED,
        )

        events = token_network.proxy.contract.web3.eth.getLogs(filter_args)
        if not len(events) > 0:
            raise ValueError('Channel is non-existing.')

        event = decode_event(
            CONTRACT_MANAGER.get_contract_abi(CONTRACT_TOKEN_NETWORK),
            events[-1])
        participant1 = decode_hex(event['args']['participant1'])
        participant2 = decode_hex(event['args']['participant2'])

        if token_network.node_address not in (participant1, participant2):
            raise ValueError('One participant must be the node address')

        if token_network.node_address == participant2:
            participant1, participant2 = participant2, participant1

        self.channel_identifier = channel_identifier
        self.channel_operations_lock = RLock()
        self.participant1 = participant1
        self.participant2 = participant2
        self.token_network = token_network
Пример #3
0
    def __init__(
        self,
        token_network: TokenNetwork,
        channel_identifier: ChannelID,
        contract_manager: ContractManager,
    ):
        if channel_identifier <= 0 or channel_identifier > UINT256_MAX:
            raise ValueError(
                f"channel_identifier {channel_identifier} is not a uint256")

        # FIXME: Issue #3958
        from_block = GENESIS_BLOCK_NUMBER

        # For this check it is perfectly fine to use a `latest` block number.
        # If the channel happened to be closed, even if the chanel is already
        # closed/settled.
        to_block = "latest"

        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=token_network.address,
            channel_identifier=channel_identifier,
            event_name=ChannelEvent.OPENED,
            contract_manager=contract_manager,
            from_block=from_block,
            to_block=to_block,
        )

        events = token_network.proxy.contract.web3.eth.getLogs(filter_args)
        if not len(events) > 0:
            raise ValueError("Channel is non-existing.")

        event = decode_event(
            contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK),
            events[-1])
        participant1 = Address(decode_hex(event["args"]["participant1"]))
        participant2 = Address(decode_hex(event["args"]["participant2"]))

        if token_network.node_address not in (participant1, participant2):
            raise ValueError("One participant must be the node address")

        if token_network.node_address == participant2:
            participant1, participant2 = participant2, participant1

        self.channel_identifier = channel_identifier
        self.participant1 = participant1
        self.participant2 = participant2
        self.token_network = token_network
        self.client = token_network.client
        self.contract_manager = contract_manager
Пример #4
0
    def settle_timeout(self) -> int:
        """ Returns the channels settle_timeout. """

        # There is no way to get the settle timeout after the channel has been closed as
        # we're saving gas. Therefore get the ChannelOpened event and get the timeout there.
        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=self.token_network.address,
            channel_identifier=self.channel_identifier,
            event_name=ChannelEvent.OPENED,
        )

        events = self.token_network.proxy.contract.web3.eth.getLogs(filter_args)
        assert len(events) > 0, 'No matching ChannelOpen event found.'

        # we want the latest event here, there might have been multiple channels
        event = decode_event(CONTRACT_MANAGER.get_contract_abi(CONTRACT_TOKEN_NETWORK), events[-1])
        return event['args']['settle_timeout']
Пример #5
0
    def settle_timeout(self) -> int:
        """ Returns the channels settle_timeout. """

        # There is no way to get the settle timeout after the channel has been closed as
        # we're saving gas. Therefore get the ChannelOpened event and get the timeout there.
        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=self.token_network.address,
            channel_identifier=self.channel_identifier,
            event_name=EVENT_CHANNEL_OPENED,
        )

        events = self.token_network.proxy.contract.web3.eth.getLogs(filter_args)
        assert len(events) > 0, 'No matching ChannelOpen event found.'

        # we want the latest event here, there might have been multiple channels
        event = decode_event(CONTRACT_MANAGER.get_contract_abi(CONTRACT_TOKEN_NETWORK), events[-1])
        return event['args']['settle_timeout']
Пример #6
0
    def __init__(
        self,
        token_network: TokenNetwork,
        channel_identifier: ChannelID,
        contract_manager: ContractManager,
    ):

        self.contract_manager = contract_manager
        if channel_identifier < 0 or channel_identifier > UINT256_MAX:
            raise ValueError('channel_identifier {} is not a uint256'.format(
                channel_identifier))

        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=token_network.address,
            channel_identifier=channel_identifier,
            event_name=ChannelEvent.OPENED,
            contract_manager=self.contract_manager,
        )

        events = token_network.proxy.contract.web3.eth.getLogs(filter_args)
        if not len(events) > 0:
            raise ValueError('Channel is non-existing.')

        event = decode_event(
            self.contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK),
            events[-1],
        )
        participant1 = Address(decode_hex(event['args']['participant1']))
        participant2 = Address(decode_hex(event['args']['participant2']))

        if token_network.node_address not in (participant1, participant2):
            raise ValueError('One participant must be the node address')

        if token_network.node_address == participant2:
            participant1, participant2 = participant2, participant1

        self.channel_identifier = channel_identifier
        self.participant1 = participant1
        self.participant2 = participant2
        self.token_network = token_network
        self.client = self.token_network.client
Пример #7
0
    def close_block_number(self) -> typing.Optional[int]:
        """ Returns the channel's closed block number. """

        # The closed block number is not in the smart contract storage to save
        # gas. Therefore get the ChannelClosed event is needed here.
        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=self.token_network.address,
            channel_identifier=self.channel_identifier,
            event_name=ChannelEvent.CLOSED,
        )

        events = self.token_network.proxy.contract.web3.eth.getLogs(
            filter_args)
        if not events:
            return None

        assert len(events) == 1
        event = decode_event(
            CONTRACT_MANAGER.get_contract_abi(CONTRACT_TOKEN_NETWORK),
            events[0])
        return event['blockNumber']
Пример #8
0
    def close_block_number(self) -> Optional[int]:
        """ Returns the channel's closed block number. """

        # The closed block number is not in the smart contract storage to save
        # gas. Therefore get the ChannelClosed event is needed here.
        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=self.token_network.address,
            channel_identifier=self.channel_identifier,
            event_name=ChannelEvent.CLOSED,
            contract_manager=self.contract_manager,
        )

        events = self.token_network.proxy.contract.web3.eth.getLogs(filter_args)
        if not events:
            return None

        assert len(events) == 1
        event = decode_event(
            self.contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK),
            events[0],
        )
        return event['blockNumber']
Пример #9
0
    def __init__(
            self,
            token_network: TokenNetwork,
            channel_identifier: ChannelID,
            contract_manager: ContractManager,
    ):

        self.contract_manager = contract_manager
        if channel_identifier < 0 or channel_identifier > UINT256_MAX:
            raise ValueError('channel_identifier {} is not a uint256'.format(channel_identifier))

        filter_args = get_filter_args_for_specific_event_from_channel(
            token_network_address=token_network.address,
            channel_identifier=channel_identifier,
            event_name=ChannelEvent.OPENED,
            contract_manager=self.contract_manager,
        )

        events = token_network.proxy.contract.web3.eth.getLogs(filter_args)
        if not len(events) > 0:
            raise ValueError('Channel is non-existing.')

        event = decode_event(
            self.contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK),
            events[-1],
        )
        participant1 = decode_hex(event['args']['participant1'])
        participant2 = decode_hex(event['args']['participant2'])

        if token_network.node_address not in (participant1, participant2):
            raise ValueError('One participant must be the node address')

        if token_network.node_address == participant2:
            participant1, participant2 = participant2, participant1

        self.channel_identifier = channel_identifier
        self.participant1 = participant1
        self.participant2 = participant2
        self.token_network = token_network