Esempio n. 1
0
    def f():
        contract_address = get_random_address()
        channel_identifier = get_random_identifier()

        balance_hash_data = '%d' % random.randint(0, UINT64_MAX)
        additional_hash_data = '%d' % random.randint(0, UINT64_MAX)

        balance_hash = encode_hex((balance_hash_data.encode()))
        nonce = random.randint(0, UINT64_MAX)
        additional_hash = encode_hex(keccak(additional_hash_data.encode()))
        chain_id = 1

        privkey = get_random_privkey()
        privkey_non_closing = get_random_privkey()

        bp = HashedBalanceProof(  # type: ignore
            channel_identifier=channel_identifier,
            token_network_address=contract_address,
            chain_id=chain_id,
            balance_hash=balance_hash,
            nonce=nonce,
            additional_hash=additional_hash,
            priv_key=privkey,
        )
        monitor_request = UnsignedMonitorRequest.from_balance_proof(
            bp, reward_amount=TokenAmount(0)).sign(privkey_non_closing)
        return monitor_request, privkey, privkey_non_closing
Esempio n. 2
0
def create_signed_monitor_request(
    nonce: Nonce = Nonce(5),
    reward_amount: TokenAmount = DEFAULT_REWARD_AMOUNT,
    closing_privkey: str = DEFAULT_PRIVATE_KEY1,
    nonclosing_privkey: str = DEFAULT_PRIVATE_KEY2,
) -> MonitorRequest:
    bp = HashedBalanceProof(
        channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
        token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
        chain_id=ChainID(1),
        balance_hash="",
        nonce=nonce,
        additional_hash="",
        priv_key=closing_privkey,
    )
    monitor_request = UnsignedMonitorRequest.from_balance_proof(
        bp, reward_amount=reward_amount).sign(nonclosing_privkey)

    # Some signature correctness checks
    assert monitor_request.signer == private_key_to_address(closing_privkey)
    assert monitor_request.non_closing_signer == private_key_to_address(
        nonclosing_privkey)
    assert monitor_request.reward_proof_signer == private_key_to_address(
        nonclosing_privkey)

    return monitor_request
Esempio n. 3
0
 def get_monitor_request(self, balance_proof: HashedBalanceProof,
                         reward_amount: TokenAmount) -> MonitorRequest:
     """Get monitor request message for a given balance proof."""
     assert balance_proof.signature
     return UnsignedMonitorRequest(
         channel_identifier=balance_proof.channel_identifier,
         token_network_address=balance_proof.token_network_address,
         chain_id=balance_proof.chain_id,
         balance_hash=balance_proof.balance_hash,
         nonce=balance_proof.nonce,
         additional_hash=balance_proof.additional_hash,
         closing_signature=balance_proof.signature,
         reward_amount=reward_amount,
     ).sign(self.privkey)
Esempio n. 4
0
def get_signed_monitor_request(
    nonce: int = 5,
    reward_amount: TokenAmount = DEFAULT_REWARD_AMOUNT,
    closing_privkey: str = DEFAULT_PRIVATE_KEY1,
    nonclosing_privkey: str = DEFAULT_PRIVATE_KEY2,
) -> MonitorRequest:
    bp = HashedBalanceProof(  # type: ignore
        channel_identifier=DEFAULT_CHANNEL_IDENTIFIER,
        token_network_address=DEFAULT_TOKEN_NETWORK_ADDRESS,
        chain_id=1,
        balance_hash='',
        nonce=nonce,
        additional_hash='',
        priv_key=closing_privkey,
    )
    monitor_request = UnsignedMonitorRequest.from_balance_proof(
        bp, reward_amount=reward_amount).sign(nonclosing_privkey)
    return monitor_request