Example #1
0
    def get_channel(
        self,
        registry_address: typing.PaymentNetworkID,
        token_address: typing.TokenAddress,
        partner_address: typing.Address,
    ) -> NettingChannelState:
        if not is_binary_address(token_address):
            raise InvalidAddress(
                'Expected binary address format for token in get_channel')

        if not is_binary_address(partner_address):
            raise InvalidAddress(
                'Expected binary address format for partner in get_channel')

        channel_list = self.get_channel_list(registry_address, token_address,
                                             partner_address)
        assert len(channel_list) <= 1

        if not channel_list:
            raise ChannelNotFound(
                "Channel with partner '{}' for token '{}' could not be found.".
                format(
                    to_checksum_address(partner_address),
                    to_checksum_address(token_address),
                ), )

        return channel_list[0]
Example #2
0
    def get_channel(self, registry_address, channel_address):
        if not is_binary_address(channel_address):
            raise InvalidAddress('Expected binary address format for channel in get_channel')

        channel_list = self.get_channel_list(registry_address)
        for channel in channel_list:
            if channel.identifier == channel_address:
                return channel

        raise ChannelNotFound()
Example #3
0
    def get_channel(self, channel_address):
        if not isaddress(channel_address):
            raise InvalidAddress(
                'Expected binary address format for channel in get_channel')
        channel_list = self.get_channel_list()
        for channel in channel_list:
            if channel.channel_address == channel_address:
                return channel

        raise ChannelNotFound()
Example #4
0
def _transform_snapshot(raw_snapshot: str) -> str:
    """
    This migration upgrades the object:
    - `MediatorTransferState` such that a list of routes is added
    to the state to be able to route a waiting transfer in case the
    receiving node comes back online.
    """
    snapshot = json.loads(raw_snapshot)
    secrethash_to_task = snapshot["payment_mapping"]["secrethashes_to_task"]
    for task in secrethash_to_task.values():
        if task["_type"] != "raiden.transfer.state.MediatorTask":
            continue

        mediator_state = task.get("mediator_state")

        # Make sure the old meditor_state was not migrated already.
        assert "routes" not in mediator_state

        mediator_state["routes"] = []

        waiting_transfer = mediator_state.get("waiting_transfer")
        if waiting_transfer is None:
            continue

        transfer = waiting_transfer.get("transfer")
        token_network_identifier = transfer["balance_proof"][
            "token_network_identifier"]
        token_network = get_token_network_by_identifier(
            snapshot, token_network_identifier)
        channel_identifier = transfer["balance_proof"]["channel_identifier"]
        channel = None
        if token_network is not None:
            channel = token_network.get("channelidentifiers_to_channels",
                                        {}).get(channel_identifier)
        if not channel:
            raise ChannelNotFound(
                f"Upgrading to v18 failed. "
                f"Could not find channel with identifier {channel_identifier} "
                f"in the current chain state.")

        # Only add the route for which the waiting transfer was intended.
        # At the time of migration, we cannot re-calculate the list of routes
        # that were originally calculated when the transfer was being
        # mediated so this step should be sufficient for now.
        mediator_state["routes"] = [
            RouteState.from_dict({
                "node_address":
                channel["partner_state"]["address"],
                "channel_identifier":
                channel_identifier,
            }).to_dict()
        ]
    return json.dumps(snapshot)
Example #5
0
def _transform_snapshot(raw_snapshot: Dict[Any, Any]) -> str:
    """
    This migration upgrades the object:
    - `MediatorTransferState` such that a list of routes is added
    to the state to be able to route a waiting transfer in case the
    receiving node comes back online.
    """
    snapshot = json.loads(raw_snapshot)
    secrethash_to_task = snapshot['payment_mapping']['secrethashes_to_task']
    for task in secrethash_to_task.values():
        if task['_type'] != 'raiden.transfer.state.MediatorTask':
            continue

        mediator_state = task.get('mediator_state')

        # Make sure the old meditor_state was not migrated already.
        assert 'routes' not in mediator_state

        mediator_state['routes'] = []

        waiting_transfer = mediator_state.get('waiting_transfer')
        if waiting_transfer is None:
            continue

        transfer = waiting_transfer.get('transfer')
        token_network_identifier = transfer['balance_proof'][
            'token_network_identifier']
        token_network = get_token_network_by_identifier(
            snapshot,
            token_network_identifier,
        )
        channel_identifier = transfer['balance_proof']['channel_identifier']
        channel = token_network.get('channelidentifiers_to_channels').get(
            channel_identifier)
        if not channel:
            raise ChannelNotFound(
                'Upgrading to v18 failed. '
                f'Could not find channel with identifier {channel_identifier} '
                'in the current chain state.', )

        # Only add the route for which the waiting transfer was intended.
        # At the time of migration, we cannot re-calculate the list of routes
        # that were originally calculated when the transfer was being
        # mediated so this step should be sufficient for now.
        mediator_state['routes'] = [
            RouteState.from_dict({
                'node_address':
                channel['partner_state']['address'],
                'channel_identifier':
                channel_identifier,
            }).to_dict(),
        ]
    return json.dumps(snapshot)
Example #6
0
    def get_channel(self, registry_address, token_address, partner_address):
        if not is_binary_address(token_address):
            raise InvalidAddress(
                'Expected binary address format for token in get_channel')

        if not is_binary_address(partner_address):
            raise InvalidAddress(
                'Expected binary address format for partner in get_channel')

        channel_identifer = calculate_channel_identifier(
            self.raiden.address, partner_address)

        channel_list = self.get_channel_list(registry_address, token_address,
                                             partner_address)
        for channel in channel_list:
            if channel.identifier == channel_identifer:
                return channel

        raise ChannelNotFound(
            "Channel with partner '{}' for token '{}' could not be found.".
            format(
                to_checksum_address(partner_address),
                to_checksum_address(token_address),
            ), )