Beispiel #1
0
    def message_mediatedtransfer(self, message):
        self.balance_proof(message)

        # TODO: Reject mediated transfer that the hashlock/identifier is known,
        # this is a downstream bug and the transfer is going in cycles (issue #490)

        if message.token in self.blocked_tokens:
            raise TransferUnwanted()

        graph = self.raiden.token_to_channelgraph[message.token]
        if not graph.has_channel(self.raiden.address, message.sender):
            raise UnknownAddress(
                'Mediated transfer from node without an existing channel: {}'.
                format(pex(message.sender), ))

        channel = graph.partneraddress_to_channel[message.sender]

        if channel.state != CHANNEL_STATE_OPENED:
            raise TransferWhenClosed(
                'Mediated transfer received but the channel is closed: {}'.
                format(pex(channel.channel_address), ))

        # raises if the message is invalid
        channel.register_transfer(self.raiden.get_block_number(), message)

        if message.target == self.raiden.address:
            self.raiden.target_mediated_transfer(message)
        else:
            self.raiden.mediate_mediated_transfer(message)
Beispiel #2
0
    def message_directtransfer(self, message):
        self.balance_proof(message)

        if message.token not in self.raiden.token_to_channelgraph:
            raise UnknownTokenAddress('Unknown token address {}'.format(pex(message.token)))

        if message.token in self.blocked_tokens:
            raise TransferUnwanted()

        graph = self.raiden.token_to_channelgraph[message.token]

        if not graph.has_channel(self.raiden.address, message.sender):
            raise UnknownAddress(
                'Direct transfer from node without an existing channel: {}'.format(
                    pex(message.sender),
                )
            )

        channel = graph.partneraddress_to_channel[message.sender]

        if channel.state != CHANNEL_STATE_OPENED:
            raise TransferWhenClosed(
                'Direct transfer received for a closed channel: {}'.format(
                    pex(channel.channel_address),
                )
            )

        amount = message.transferred_amount - channel.partner_state.transferred_amount
        state_change = ReceiveTransferDirect(
            message.identifier,
            amount,
            message.token,
            message.sender,
        )
        state_change_id = self.raiden.transaction_log.log(state_change)

        channel.register_transfer(
            self.raiden.get_block_number(),
            message,
        )

        receive_success = EventTransferReceivedSuccess(
            message.identifier,
            amount,
            message.sender,
        )
        self.raiden.transaction_log.log_events(
            state_change_id,
            [receive_success],
            self.raiden.get_block_number()
        )
Beispiel #3
0
    def message_directtransfer(self, message):
        if message.token not in self.raiden.channelgraphs:
            raise UnknownTokenAddress('Unknown token address {}'.format(
                pex(message.token)))

        graph = self.raiden.channelgraphs[message.token]

        if not graph.has_channel(self.raiden.address, message.sender):
            raise UnknownAddress(
                'Direct transfer from node without an existing channel: {}'.
                format(pex(message.sender), ))

        channel = graph.partneraddress_channel[message.sender]

        if channel.state != CHANNEL_STATE_OPENED:
            raise TransferWhenClosed(
                'Direct transfer received for a closed channel: {}'.format(
                    pex(channel.channel_address), ))

        channel.register_transfer(message)
Beispiel #4
0
    def message_mediatedtransfer(self, message):
        # TODO: Reject mediated transfer that the hashlock/identifier is known,
        # this is a downstream bug and the transfer is going in cycles (issue #490)

        key = SwapKey(
            message.identifier,
            message.token,
            message.lock.amount,
        )

        # TODO: add a separate message for token swaps to simplify message
        # handling (issue #487)
        if key in self.raiden.swapkeys_tokenswaps:
            self.message_tokenswap(message)
            return

        graph = self.raiden.channelgraphs[message.token]

        if not graph.has_channel(self.raiden.address, message.sender):
            raise UnknownAddress(
                'Direct transfer from node without an existing channel: {}'.format(
                    pex(message.sender),
                )
            )

        channel = graph.partneraddress_channel[message.sender]

        if not channel.isopen:
            raise TransferWhenClosed(
                'Direct transfer received for a closed channel: {}'.format(
                    pex(channel.channel_address),
                )
            )

        channel.register_transfer(message)  # raises if the message is invalid

        if message.target == self.raiden.address:
            self.raiden.target_mediated_transfer(message)

        else:
            self.raiden.mediate_mediated_transfer(message)
    def message_mediatedtransfer(self, message):
        # TODO: Reject mediated transfer that the hashlock/identifier is known,
        # this is a downstream bug and the transfer is going in cycles (issue #490)

        key = SwapKey(
            message.identifier,
            message.token,
            message.lock.amount,
        )

        if message.token in self.blocked_tokens:
            raise TransferUnwanted()

        # TODO: add a separate message for token swaps to simplify message
        # handling (issue #487)
        if key in self.raiden.swapkey_to_tokenswap:
            self.message_tokenswap(message)
            return

        graph = self.raiden.token_to_channelgraph[message.token]
        if not graph.has_channel(self.raiden.address, message.sender):
            raise UnknownAddress(
                'Mediated transfer from node without an existing channel: {}'.
                format(pex(message.sender), ))

        channel = graph.partneraddress_to_channel[message.sender]

        if channel.state != CHANNEL_STATE_OPENED:
            raise TransferWhenClosed(
                'Mediated transfer received but the channel is closed: {}'.
                format(pex(channel.channel_address), ))

        # raises if the message is invalid
        channel.register_transfer(self.raiden.get_block_number(), message)

        if message.target == self.raiden.address:
            self.raiden.target_mediated_transfer(message)
        else:
            self.raiden.mediate_mediated_transfer(message)