Exemple #1
0
def handle_cancelroute(
    payment_state: InitiatorPaymentState,
    state_change: ActionCancelRoute,
    channelidentifiers_to_channels: typing.ChannelMap,
    pseudo_random_generator: random.Random,
    block_number: typing.BlockNumber,
) -> TransitionResult:
    events: typing.List[Event] = list()
    if can_cancel(payment_state):
        old_initiator_state = payment_state.initiator
        transfer_description = payment_state.initiator.transfer_description
        cancel_events = cancel_current_route(payment_state)

        msg = 'The previous transfer must be cancelled prior to trying a new route'
        assert payment_state.initiator is None, msg

        sub_iteration = initiator.try_new_route(
            old_initiator_state=old_initiator_state,
            channelidentifiers_to_channels=channelidentifiers_to_channels,
            available_routes=state_change.routes,
            transfer_description=transfer_description,
            pseudo_random_generator=pseudo_random_generator,
            block_number=block_number,
        )

        events.extend(cancel_events)
        events.extend(sub_iteration.events)
        assert sub_iteration.new_state
        payment_state.initiator = sub_iteration.new_state

    iteration = TransitionResult(payment_state, events)

    return iteration
def handle_cancelroute(
        payment_state: InitiatorPaymentState,
        state_change: ActionCancelRoute,
        channelidentifiers_to_channels: initiator.ChannelMap,
        pseudo_random_generator: random.Random,
        block_number: typing.BlockNumber,
) -> TransitionResult:
    events = list()
    if can_cancel(payment_state):
        transfer_description = payment_state.initiator.transfer_description
        cancel_events = cancel_current_route(payment_state)

        msg = 'The previous transfer must be cancelled prior to trying a new route'
        assert payment_state.initiator is None, msg
        sub_iteration = initiator.try_new_route(
            channelidentifiers_to_channels,
            state_change.routes,
            transfer_description,
            pseudo_random_generator,
            block_number,
        )

        events.extend(cancel_events)
        events.extend(sub_iteration.events)

        if sub_iteration.new_state:
            payment_state.initiator = sub_iteration.new_state
        else:
            payment_state = None

    iteration = TransitionResult(payment_state, events)

    return iteration
Exemple #3
0
def iteration_from_sub(
    payment_state: InitiatorPaymentState,
    iteration: TransitionResult,
) -> TransitionResult:

    if iteration.new_state:
        payment_state.initiator = iteration.new_state
        return TransitionResult(payment_state, iteration.events)
    return iteration
def iteration_from_sub(
        payment_state: InitiatorPaymentState,
        iteration: TransitionResult,
) -> TransitionResult:

    if iteration.new_state:
        payment_state.initiator = iteration.new_state
        return TransitionResult(payment_state, iteration.events)
    return iteration
Exemple #5
0
def cancel_current_route(payment_state: InitiatorPaymentState) -> typing.List[Event]:
    """ Cancel current route.

    This allows a new route to be tried.
    """
    assert can_cancel(payment_state), 'Cannot cancel a route after the secret is revealed'

    transfer_description = payment_state.initiator.transfer_description

    payment_state.cancelled_channels.append(payment_state.initiator.channel_identifier)
    payment_state.initiator = None

    return events_for_cancel_current_route(transfer_description)
def cancel_current_route(payment_state: InitiatorPaymentState) -> typing.List[Event]:
    """ Cancel current route.

    This allows a new route to be tried.
    """
    assert can_cancel(payment_state), 'Cannot cancel a route after the secret is revealed'

    transfer_description = payment_state.initiator.transfer_description

    payment_state.cancelled_channels.append(payment_state.initiator.channel_identifier)
    payment_state.initiator = None

    return events_for_cancel_current_route(transfer_description)