Esempio n. 1
0
def test_update_pfs():
    balance_proof = BalanceProofUnsignedState.from_dict(
        make_balance_proof(signer=signer, amount=1).to_dict(), )
    message = UpdatePFS.from_balance_proof(
        balance_proof=balance_proof,
        reveal_timeout=1,
    )
    assert message.signature == b''
    message.sign(signer)
    assert recover(message._data_to_sign(), message.signature) == ADDRESS
Esempio n. 2
0
    def update_pfs(raiden: RaidenService, event: Event):
        channel_state = get_channelstate_by_token_network_and_partner(
            chain_state=state_from_raiden(raiden),
            token_network_id=to_canonical_address(
                event.balance_proof.token_network_identifier, ),
            partner_address=to_canonical_address(event.recipient),
        )
        error_msg = 'tried to send a balance proof in non-existant channel '
        f'token_network_address: {pex(event.balance_proof.token_network_identifier)} '
        f'recipient: {pex(event.recipient)}'
        assert channel_state is not None, error_msg

        msg = UpdatePFS.from_balance_proof(
            balance_proof=event.balance_proof,
            reveal_timeout=channel_state.reveal_timeout,
        )
        msg.sign(raiden.signer)
        raiden.transport.send_global(PATH_FINDING_BROADCASTING_ROOM, msg)
        log.debug(
            'sent a PFS Update',
            balance_proof=event.balance_proof,
            recipient=event.recipient,
        )