Beispiel #1
0
 def register_payment(self, sender: str, open_block_number: int, balance: int, signature: str):
     """Register a payment.
     Method will try to reconstruct (verify) balance update data
     with a signature sent by the client.
     If verification is succesfull, an internal payment state is updated.
     Parameters:
         sender (str):               sender of the balance proof
         open_block_number (int):    block the channel was opened in
         balance (int):              updated balance
         signature(str):             balance proof to verify
     """
     assert is_checksum_address(sender)
     c = self.verify_balance_proof(sender, open_block_number, balance, signature)
     if balance <= c.balance:
         raise InvalidBalanceAmount('The balance must not decrease.')
     if balance > c.deposit:
         raise InvalidBalanceProof('Balance must not be greater than deposit')
     received = balance - c.balance
     c.old_balance = c.balance
     c.balance = balance
     c.old_signature = c.last_signature
     c.last_signature = signature
     c.mtime = time.time()
     self.state.set_channel(c)
     self.log.debug('registered payment (sender %s, block number %s, new balance %s)',
                    c.sender, open_block_number, balance)
     return c.sender, received
Beispiel #2
0
 def register_payment(self, sender, open_block_number, balance, signature):
     """Register a payment."""
     c = self.verify_balance_proof(sender, open_block_number, balance, signature)
     if balance <= c.balance:
         raise InvalidBalanceAmount('The balance must increase.')
     if balance > c.deposit:
         raise InvalidBalanceProof('Balance must not be greater than deposit.')
     received = balance - c.balance
     c.balance = balance
     c.last_signature = signature
     c.mtime = time.time()
     self.state.store()
     self.log.debug('registered payment (sender %s, block number %s, new balance %s)',
                    c.sender, open_block_number, balance)
     return (c.sender, received)