Exemple #1
0
def handle_channel_closed(
    channel_state: NettingChannelState,
    state_change: ContractReceiveChannelClosed,
) -> TransitionResult:
    events = list()

    just_closed = (state_change.channel_identifier == channel_state.identifier
                   and get_status(channel_state)
                   in CHANNEL_STATES_PRIOR_TO_CLOSED)

    if just_closed:
        set_closed(channel_state, state_change.closed_block_number)

        balance_proof = channel_state.partner_state.balance_proof
        call_update = (
            state_change.closing_address != channel_state.our_state.address
            and balance_proof)
        if call_update:
            # The channel was closed by our partner, if there is a balance
            # proof available update this node half of the state
            update = ContractSendChannelUpdateTransfer(
                channel_state.identifier,
                balance_proof,
            )
            events.append(update)

        unlock_proofs = get_known_unlocks(channel_state.partner_state)
        if unlock_proofs:
            onchain_unlock = ContractSendChannelUnlock(
                channel_state.identifier,
                unlock_proofs,
            )
            events.append(onchain_unlock)

    return TransitionResult(channel_state, events)
Exemple #2
0
def test_is_transaction_expired():
    expiration = 24
    block_number = expiration + 1
    transaction = ContractSendChannelUpdateTransfer(
        expiration=expiration,
        balance_proof=None,
        triggered_by_block_hash=factories.make_block_hash(),
    )
    assert is_transaction_expired(transaction, block_number)
    transaction = ContractSendSecretReveal(
        expiration=expiration,
        secret=factories.UNIT_SECRET,
        triggered_by_block_hash=factories.make_block_hash(),
    )
    assert is_transaction_expired(transaction, block_number)

    transaction = ContractSendSecretReveal(
        expiration=block_number,
        secret=factories.UNIT_SECRET,
        triggered_by_block_hash=factories.make_block_hash(),
    )
    assert not is_transaction_expired(transaction, block_number)