How to use the raiden.utils.typing.BlockTimeout 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-services / tests / pathfinding / test_fee_updates.py View on Github external
def setup_channel(service: PathfindingService) -> TokenNetwork:
    token_network = TokenNetwork(token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS)
    service.token_networks[token_network.address] = token_network

    token_network.handle_channel_opened_event(
        channel_identifier=DEFAULT_CHANNEL_ID,
        participant1=PRIVATE_KEY_1_ADDRESS,
        participant2=PRIVATE_KEY_2_ADDRESS,
        settle_timeout=BlockTimeout(15),
    )

    # Check that the new channel has id == 0
    assert set(token_network.channel_id_to_addresses[DEFAULT_CHANNEL_ID]) == {
        PRIVATE_KEY_1_ADDRESS,
        PRIVATE_KEY_2_ADDRESS,
    }

    return token_network
github raiden-network / raiden-services / tests / monitoring / monitoring_service / factories.py View on Github external
TokenAmount,
    TokenNetworkAddress,
)
from raiden_contracts.constants import ChannelState
from raiden_contracts.utils.type_aliases import PrivateKey
from raiden_libs.utils import private_key_to_address

DEFAULT_TOKEN_NETWORK_ADDRESS = TokenNetworkAddress(bytes([1] * 20))
DEFAULT_TOKEN_ADDRESS = TokenAddress(bytes([9] * 20))
DEFAULT_CHANNEL_IDENTIFIER = ChannelID(3)
DEFAULT_PRIVATE_KEY1 = PrivateKey(decode_hex("0x" + "1" * 64))
DEFAULT_PRIVATE_KEY2 = PrivateKey(decode_hex("0x" + "2" * 64))
DEFAULT_PARTICIPANT1 = private_key_to_address(DEFAULT_PRIVATE_KEY1)
DEFAULT_PARTICIPANT2 = private_key_to_address(DEFAULT_PRIVATE_KEY2)
DEFAULT_REWARD_AMOUNT = TokenAmount(1)
DEFAULT_SETTLE_TIMEOUT = BlockTimeout(100)


def create_signed_monitor_request(
    chain_id: ChainID = ChainID(61),
    nonce: Nonce = Nonce(5),
    reward_amount: TokenAmount = DEFAULT_REWARD_AMOUNT,
    closing_privkey: PrivateKey = DEFAULT_PRIVATE_KEY1,
    nonclosing_privkey: PrivateKey = DEFAULT_PRIVATE_KEY2,
) -> MonitorRequest:
    bp = HashedBalanceProof(
        channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
        token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
        chain_id=chain_id,
        balance_hash="",
        nonce=nonce,
        additional_hash="",
github raiden-network / raiden-services / tests / pathfinding / test_service.py View on Github external
def setup_channel(pathfinding_service_mock, token_network_model):
    channel_event = ReceiveChannelOpenedEvent(
        token_network_address=token_network_model.address,
        channel_identifier=ChannelID(1),
        participant1=PARTICIPANT1,
        participant2=PARTICIPANT2,
        settle_timeout=BlockTimeout(20),
        block_number=BlockNumber(1),
    )
    assert len(pathfinding_service_mock.token_networks) == 1
    assert len(token_network_model.channel_id_to_addresses) == 0
    pathfinding_service_mock.handle_event(channel_event)
github raiden-network / raiden-services / tests / pathfinding / test_capacity_updates.py View on Github external
def get_capacity_update_message(  # pylint: disable=too-many-arguments
    updating_participant: Address,
    other_participant: Address,
    chain_id=ChainID(61),
    channel_identifier=DEFAULT_CHANNEL_ID,
    token_network_address: TokenNetworkAddress = DEFAULT_TOKEN_NETWORK_ADDRESS,
    updating_nonce=Nonce(1),
    other_nonce=Nonce(0),
    updating_capacity=TA(90),
    other_capacity=TA(110),
    reveal_timeout: BlockTimeout = BlockTimeout(2),
    privkey_signer: bytes = PRIVATE_KEY_1,
) -> PFSCapacityUpdate:
    updatepfs_message = PFSCapacityUpdate(
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            channel_identifier=channel_identifier,
            token_network_address=token_network_address,
        ),
        updating_participant=updating_participant,
        other_participant=other_participant,
        updating_nonce=updating_nonce,
        other_nonce=other_nonce,
        updating_capacity=updating_capacity,
        other_capacity=other_capacity,
        reveal_timeout=reveal_timeout,
        signature=EMPTY_SIGNATURE,
github raiden-network / raiden / raiden / transfer / mediated_transfer / mediator.py View on Github external
route_state_table: list of all candidate routes
        channelidentifiers_to_channels: All the channels available for this
            transfer.

        pseudo_random_generator: Number generator to generate a message id.
        block_number: The current block number.
    """
    # check channel
    payee_channel = channelidentifiers_to_channels.get(route_state.forward_channel_id)
    if not payee_channel:
        return None, []

    amount_after_fees = get_lock_amount_after_fees(
        payer_transfer.lock, payer_channel, payee_channel
    )
    lock_timeout = BlockTimeout(payer_transfer.lock.expiration - block_number)
    safe_to_use_channel = channel.is_channel_usable_for_mediation(
        channel_state=payee_channel, transfer_amount=amount_after_fees, lock_timeout=lock_timeout
    )

    if not safe_to_use_channel:
        return None, []

    assert payee_channel.settle_timeout >= lock_timeout
    assert payee_channel.token_address == payer_transfer.token

    route_states = routes.prune_route_table(
        route_states=route_state_table, selected_route=route_state
    )
    message_identifier = message_identifier_from_prng(pseudo_random_generator)
    lockedtransfer_event = channel.send_lockedtransfer(
        channel_state=payee_channel,
github raiden-network / raiden / raiden / transfer / mediated_transfer / mediator.py View on Github external
Args:
        backward_channel: The original channel which sent the mediated transfer
            to this node.
        payer_transfer: The *latest* payer transfer which is backing the
            mediation.
        block_number: The current block number.

    Returns:
        The mediator pair and the correspoding refund event.
    """
    transfer_pair = None
    events: List[Event] = list()

    lock = payer_transfer.lock
    lock_timeout = BlockTimeout(lock.expiration - block_number)

    # Ensure the refund transfer's lock has a safe expiration, otherwise don't
    # do anything and wait for the received lock to expire.
    if channel.is_channel_usable_for_mediation(backward_channel, lock.amount, lock_timeout):
        message_identifier = message_identifier_from_prng(pseudo_random_generator)

        backward_route_state = RouteState(
            route=[backward_channel.our_state.address],
            forward_channel_id=backward_channel.canonical_identifier.channel_identifier,
        )

        refund_transfer = channel.send_refundtransfer(
            channel_state=backward_channel,
            initiator=payer_transfer.initiator,
            target=payer_transfer.target,
            # `amount` should be `get_lock_amount_after_fees(...)`, but fees
github raiden-network / raiden / raiden / transfer / mediated_transfer / mediator.py View on Github external
pseudo_random_generator: Number generator to generate a message id.
        block_number: The current block number.
    """
    # check channel
    payee_channel = channelidentifiers_to_channels.get(route_state.forward_channel_id)
    if not payee_channel:
        return None, []

    amount_after_fees = get_lock_amount_after_fees(
        payer_transfer.lock, payer_channel, payee_channel
    )
    if not amount_after_fees:
        return None, []

    lock_timeout = BlockTimeout(payer_transfer.lock.expiration - block_number)
    safe_to_use_channel = channel.is_channel_usable_for_mediation(
        channel_state=payee_channel, transfer_amount=amount_after_fees, lock_timeout=lock_timeout
    )

    if not safe_to_use_channel:
        return None, []

    assert payee_channel.settle_timeout >= lock_timeout
    assert payee_channel.token_address == payer_transfer.token

    route_states = routes.prune_route_table(
        route_states=route_state_table, selected_route=route_state
    )
    message_identifier = message_identifier_from_prng(pseudo_random_generator)
    lockedtransfer_event = channel.send_lockedtransfer(
        channel_state=payee_channel,