Esempio n. 1
0
def handle_channel_unlock(node_state, state_change):
    token_address = state_change.token_address
    payment_network_state, token_network_state = get_networks(
        node_state,
        state_change.payment_network_identifier,
        state_change.token_address,
    )

    # first dispatch the unlock claim to update the channel
    events = []
    if token_network_state:
        pseudo_random_generator = node_state.pseudo_random_generator
        sub_iteration = token_network.subdispatch_to_channel_by_id(
            token_network_state,
            state_change,
            pseudo_random_generator,
            node_state.block_number,
        )
        events.extend(sub_iteration.events)

        if sub_iteration.new_state is None:
            del payment_network_state.tokenaddresses_to_tokennetworks[token_address]

    # second emulate a secret reveal, to register the secret with all the other
    # channels and proceed with the protocol
    state_change = ReceiveSecretReveal(state_change.secret, None)
    sub_iteration_secret_reveal = handle_secret_reveal(
        node_state,
        state_change,
    )
    events.extend(sub_iteration_secret_reveal.events)

    return TransitionResult(node_state, events)
Esempio n. 2
0
def handle_channel_batch_unlock(
    node_state: NodeState,
    state_change: ContractReceiveChannelBatchUnlock,
) -> TransitionResult:
    token_network_identifier = state_change.token_network_identifier
    token_network_state = views.get_token_network_by_identifier(
        node_state,
        token_network_identifier,
    )

    events = []
    if token_network_state:
        pseudo_random_generator = node_state.pseudo_random_generator
        sub_iteration = token_network.subdispatch_to_channel_by_id(
            token_network_state,
            state_change,
            pseudo_random_generator,
            node_state.block_number,
        )
        events.extend(sub_iteration.events)

        if sub_iteration.new_state is None:
            payment_network_state = views.get_payment_network_by_identifier(
                node_state,
                token_network_state.address,
            )

            del payment_network_state.tokenaddresses_to_tokennetworks[
                token_network_state.token_address]
            del payment_network_state.tokenidentifiers_to_tokennetworks[
                token_network_identifier]

    return TransitionResult(node_state, events)