How to use the raiden.utils.pex function in raiden

To help you get started, we’ve selected a few raiden examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raiden-network / raiden / raiden / network / proxies / discovery.py View on Github external
def register_endpoint(self, node_address: Address, endpoint: Endpoint) -> None:
        if node_address != self.client.address:
            raise ValueError("node_address doesnt match this node's address")

        log_details = {
            "node": pex(self.node_address),
            "node_address": pex(node_address),
            "endpoint": endpoint,
        }
        log.debug("registerEndpoint called", **log_details)

        transaction_hash = self.proxy.transact(
            "registerEndpoint", safe_gas_limit(GAS_REQUIRED_FOR_ENDPOINT_REGISTER), endpoint
        )

        self.client.poll(transaction_hash)

        receipt_or_none = check_transaction_threw(self.client, transaction_hash)
        if receipt_or_none:
            log.critical("registerEndpoint failed", **log_details)
            raise TransactionThrew("Register Endpoint", receipt_or_none)
github raiden-network / raiden / raiden / network / protocol.py View on Github external
# message identifiers must be unique
        message_id = message.message_identifier

        # ignore duplicates
        if message_id not in self.messageids_to_asyncresults:
            self.messageids_to_asyncresults[message_id] = AsyncResult()

            queue = self.get_queue_for(recipient, queue_name)
            queue.put((messagedata, message_id))

            log.debug(
                'MESSAGE QUEUED',
                node=pex(self.raiden.address),
                queue_name=queue_name,
                to=pex(recipient),
                message=message,
            )
github raiden-network / raiden / raiden / transfermanager.py View on Github external
def _direct_or_mediated_transfer(self, amount, identifier, direct_channel):
        """ Check the direct channel and if possible use it, otherwise start a
        mediated transfer.
        """

        if not direct_channel.isopen:
            log.info(
                'DIRECT CHANNEL %s > %s is closed',
                pex(direct_channel.our_state.address),
                pex(direct_channel.partner_state.address),
            )

            async_result = self._mediated_transfer(
                amount,
                identifier,
                direct_channel.partner_state.address,
            )
            return async_result

        elif amount > direct_channel.distributable:
            log.info(
                'DIRECT CHANNEL %s > %s doesnt have enough funds [%s]',
                pex(direct_channel.our_state.address),
                pex(direct_channel.partner_state.address),
                amount,
github raiden-network / raiden / raiden / blockchain / net_contract.py View on Github external
def partner(self, address):
        """ Returns the address of the other participant in the contract. """

        if address not in self.participants:
            msg = 'The address {address} is not a participant of this contract'.format(
                address=pex(address),
            )
            raise ValueError(msg)

        all_participants = list(self.participants.keys())
        all_participants.remove(address)
        return all_participants[0]
github raiden-network / raiden / raiden / channel / netting_channel.py View on Github external
)
                )

        # all checks need to be done before the internal state of the channel
        # is changed, otherwise if a check fails and the state was changed the
        # channel will be left trashed

        if isinstance(transfer, LockedTransfer):
            if log.isEnabledFor(logging.DEBUG):
                lockhashes = list(from_state.hashlocks_to_unclaimedlocks.values())
                lockhashes.extend(from_state.hashlocks_to_pendinglocks.values())
                log.debug(
                    'REGISTERED LOCK',
                    node=pex(self.our_state.address),
                    from_=pex(from_state.address),
                    to=pex(to_state.address),
                    currentlocksroot=pex(merkleroot(from_state.merkletree)),
                    lockhashes=lpex(str(l).encode() for l in lockhashes),
                    lock_amount=transfer.lock.amount,
                    lock_expiration=transfer.lock.expiration,
                    lock_hashlock=pex(transfer.lock.hashlock),
                    lockhash=pex(sha3(transfer.lock.as_bytes)),
                )

            from_state.register_locked_transfer(transfer)

            # register this channel as waiting for the secret (the secret can
            # be revealed through a message or a blockchain log)
            self.external_state.register_channel_for_hashlock(
                self,
                transfer.lock.hashlock,
            )
github raiden-network / raiden / raiden / network / proxies / netting_channel.py View on Github external
def close(self, nonce, transferred_amount, locked_amount, locksroot, extra_hash, signature):
        """ Close the channel using the provided balance proof.

        Raises:
            AddressWithoutCode: If the channel was settled prior to the call.
            ChannelBusyError: If the channel is busy with another operation.
        """

        log.info(
            'close called',
            node=pex(self.node_address),
            contract=pex(self.address),
            nonce=nonce,
            transferred_amount=transferred_amount,
            locked_amount=locked_amount,
            locksroot=encode_hex(locksroot),
            extra_hash=encode_hex(extra_hash),
            signature=encode_hex(signature),
        )

        if not self.channel_operations_lock.acquire(blocking=False):
            raise ChannelBusyError(
                f'Channel with address {self.address} is '
                f'busy with another ongoing operation.',
            )

        with releasing(self.channel_operations_lock):
github raiden-network / raiden / raiden / network / channelgraph.py View on Github external
'channel %s - %s doesnt have enough funds [%s], ignoring',
                    pex(our_address),
                    pex(partner_address),
                    amount,
                )
            continue

        network_state = nodeaddresses_statuses[partner_address]
        route_state = channel_to_routestate(channel, partner_address)

        if network_state != NODE_NETWORK_REACHABLE:
            if log.isEnabledFor(logging.INFO):
                log.info(
                    'partner for channel %s - %s is not %s, ignoring',
                    pex(our_address),
                    pex(partner_address),
                    NODE_NETWORK_REACHABLE,
                )
            continue

        online_nodes.append(route_state)

    return online_nodes
github raiden-network / raiden / raiden / event_handler.py View on Github external
)
            self.raiden.send_async(receiver, refund_transfer)

        elif isinstance(event, EventTransferSentSuccess):
            for result in self.raiden.identifier_to_results[event.identifier]:
                result.set(True)

        elif isinstance(event, EventTransferSentFailed):
            for result in self.raiden.identifier_to_results[event.identifier]:
                result.set(False)
        elif isinstance(event, UNEVENTFUL_EVENTS):
            pass
        elif isinstance(event, EventUnlockFailed):
            log.error(
                'UnlockFailed!',
                hashlock=pex(event.hashlock),
                reason=event.reason
            )

        elif isinstance(event, ContractSendChannelClose):
            graph = self.raiden.token_to_channelgraph[event.token]
            channel = graph.address_to_channel[event.channel_address]

            balance_proof = channel.our_state.balance_proof
            channel.external_state.close(balance_proof)

        else:
            log.error('Unknown event {}'.format(type(event)))
github raiden-network / raiden / raiden / tokenmanager.py View on Github external
# let the task use as many as required to finish the transfer.

        for path in available_paths:
            assert path[0] == self.raiden.address
            assert path[1] in self.partneraddress_channel
            assert path[-1] == target

            partner = path[1]
            channel = self.partneraddress_channel[partner]

            if not channel.isopen:
                if log.isEnabledFor(logging.INFO):
                    log.info(
                        'channel %s - %s is close, ignoring',
                        pex(path[0]),
                        pex(path[1]),
                    )

                continue

            # we can't intermediate the transfer if we don't have enough funds
            if amount > channel.distributable:
                if log.isEnabledFor(logging.INFO):
                    log.info(
                        'channel %s - %s doesnt have enough funds [%s], ignoring',
                        pex(path[0]),
                        pex(path[1]),
                        amount,
                    )
                continue

            if lock_timeout:
github raiden-network / raiden / raiden / network / proxies / registry.py View on Github external
if manager_address is None:
            log.info(
                'add_token failed and check_transaction_threw didnt detect it',
                node=pex(self.node_address),
                token_address=pex(token_address),
                registry_address=pex(self.address),
            )

            raise RuntimeError('channelManagerByToken failed')

        log.info(
            'add_token sucessful',
            node=pex(self.node_address),
            token_address=pex(token_address),
            registry_address=pex(self.address),
            manager_address=pex(manager_address),
        )

        return manager_address