Exemple #1
0
    def transfer(self, amount, target, callback=None):
        """ Transfer `amount` between this node and `target`.

        This method will start a asyncronous transfer, the transfer might fail
        or succeed depending on a couple of factors:
            - Existence of a path that can be used, through the usage of direct
            or intermediary channels.
            - Network speed, making the transfer suficiently fast so it doesn't
            timeout.
        """

        if target in self.assetmanager.partneraddress_channel:
            channel = self.assetmanager.partneraddress_channel[target]
            direct_transfer = channel.create_directtransfer(amount)
            self.assetmanager.raiden.sign(direct_transfer)
            channel.register_transfer(direct_transfer, callback=callback)

            task = self.assetmanager.raiden.protocol.send(
                target,
                direct_transfer,
            )

        else:
            task = StartMediatedTransferTask(
                self,
                amount,
                target,
            )
            if callback:
                self.on_task_completed_callbacks.append(callback)

        task.start()
        return task
Exemple #2
0
def mediated_transfer(initiator_app, target_app, asset, amount, identifier=None):
    """ Nice to read shortcut to make a MediatedTransfer.

    The secret will be revealed and the apps will be synchronized.
    """
    # pylint: disable=too-many-arguments

    assetmanager = initiator_app.raiden.managers_by_asset_address[asset]
    has_channel = initiator_app.raiden.address in assetmanager.partneraddress_channel

    # api.transfer() would do a DirectTransfer
    if has_channel:
        transfermanager = assetmanager.transfermanager
        # Explicitly call the default identifier creation since this mock
        # function here completely skips the `transfer_async()` call.
        if not identifier:
            identifier = transfermanager.create_default_identifier(target_app.raiden.address)

        result = AsyncResult()
        task = StartMediatedTransferTask(
            transfermanager,
            amount,
            identifier,
            target_app.raiden.address,
            result,
        )
        task.start()
        result.wait()
    else:
        initiator_app.raiden.api.transfer(
            asset,
            amount,
            target_app.raiden.address,
            identifier
        )
Exemple #3
0
def mediated_transfer(initiator_app, target_app, token, amount, identifier=None):
    """ Nice to read shortcut to make a MediatedTransfer.

    The secret will be revealed and the apps will be synchronized.
    """
    # pylint: disable=too-many-arguments

    tokenmanager = initiator_app.raiden.managers_by_token_address[token]
    has_channel = initiator_app.raiden.address in tokenmanager.partneraddress_channel

    # api.transfer() would do a DirectTransfer
    if has_channel:
        transfermanager = tokenmanager.transfermanager
        # Explicitly call the default identifier creation since this mock
        # function here completely skips the `transfer_async()` call.
        if not identifier:
            identifier = transfermanager.create_default_identifier(target_app.raiden.address)

        result = AsyncResult()
        task = StartMediatedTransferTask(
            transfermanager,
            amount,
            identifier,
            target_app.raiden.address,
            result,
        )
        task.start()
        result.wait()
    else:
        initiator_app.raiden.api.transfer(
            token,
            amount,
            target_app.raiden.address,
            identifier
        )
Exemple #4
0
    def _mediated_transfer(self, amount, identifier, target):
        async_result = AsyncResult()
        task = StartMediatedTransferTask(
            self.tokenmanager.raiden,
            self.tokenmanager.token_address,
            amount,
            identifier,
            target,
            async_result,
        )
        task.start()

        return async_result
    def _mediated_transfer(self, amount, identifier, target, callback):
        asunc_result = AsyncResult()
        task = StartMediatedTransferTask(
            self.tokenmanager.raiden,
            self.tokenmanager.token_address,
            amount,
            identifier,
            target,
            asunc_result,
        )
        task.start()

        if callback:
            self.on_task_completed_callbacks.append(callback)

        return asunc_result
    def _mediated_transfer(self, amount, identifier, target, callback):
        asunc_result = AsyncResult()
        task = StartMediatedTransferTask(
            self.assetmanager.raiden,
            self.assetmanager.asset_address,
            amount,
            identifier,
            target,
            asunc_result,
        )
        task.start()

        if callback:
            self.on_task_completed_callbacks.append(callback)

        return asunc_result
Exemple #7
0
def mediated_transfer(initiator_app, target_app, asset, amount):  # pylint: disable=too-many-arguments
    """ Nice to read shortcut to make a MediatedTransfer.

    The secret will be revealed and the apps will be synchronized.
    """
    assetmanager = initiator_app.raiden.managers_by_asset_address[asset]
    has_channel = initiator_app.raiden.address in assetmanager.partneraddress_channel

    # api.transfer() would do a DirectTransfer
    if has_channel:
        transfermanager = assetmanager.transfermanager

        task = StartMediatedTransferTask(
            transfermanager,
            amount,
            target_app.raiden.address,
        )
        task.start()
        task.join()
    else:
        initiator_app.raiden.api.transfer(asset, amount, target_app.raiden.address)
Exemple #8
0
def mediated_transfer(initiator_app, target_app, asset, amount):  # pylint: disable=too-many-arguments
    """ Nice to read shortcut to make a MediatedTransfer.

    The secret will be revealed and the apps will be synchronized.
    """
    assetmanager = initiator_app.raiden.managers_by_asset_address[asset]
    has_channel = initiator_app.raiden.address in assetmanager.partneraddress_channel

    # api.transfer() would do a DirectTransfer
    if has_channel:
        transfermanager = assetmanager.transfermanager

        task = StartMediatedTransferTask(
            transfermanager,
            amount,
            target_app.raiden.address,
        )
        task.start()
        task.join()
    else:
        initiator_app.raiden.api.transfer(asset, amount, target_app.raiden.address)