示例#1
0
def close_channel_cooperatively(
        channel: Channel, privkey_receiver: str, contract_address: str, balance: int=None
):
    if balance is not None:
        channel.balance = balance
    closing_sig = sign_close(privkey_receiver, channel.balance_sig)
    assert channel.close_cooperatively(closing_sig)
示例#2
0
def close_channel_cooperatively(channel: Channel,
                                privkey_receiver: str,
                                balance: int = None):
    if balance is not None:
        channel.update_balance(balance)
    closing_sig = sign_close(privkey_receiver, channel.balance_sig)
    assert channel.close_cooperatively(closing_sig)
示例#3
0
def test_cooperative_close(client: Client, receiver_privkey, receiver_address):
    c = client.get_suitable_channel(receiver_address, 3)
    c.create_transfer(3)

    assert c.deposit >= 3
    assert c.balance == 3

    sig = sign_close(receiver_privkey, c.balance_sig)
    assert c.close_cooperatively(sig)
    assert c.state == Channel.State.closed
示例#4
0
 def delete(self, sender_address):
     parser = reqparse.RequestParser()
     parser.add_argument('open_block', type=int, help='block the channel was opened')
     parser.add_argument('signature', help='last balance proof signature')
     args = parser.parse_args()
     if args.signature is None:
         return "Bad signature format", 400
     if args.block is None:
         return "No opening block specified", 400
     channel = self.channel_manager.channels[sender_address, args.block]
     if channel.last_signature != args.signature:
         return "Invalid or outdated balance signature", 400
     ret = sign_close(self.channel_manager.private_key, args.signature)
     return ret, 200
示例#5
0
 def sign_close(self, sender, open_block_number, balance):
     """Sign an agreement for a channel closing."""
     if (sender, open_block_number) not in self.channels:
         raise NoOpenChannel('Channel does not exist or has been closed'
                             '(sender=%s, open_block_number=%d)' % (sender, open_block_number))
     c = self.channels[sender, open_block_number]
     if c.is_closed:
         raise NoOpenChannel('Channel closing has been requested already.')
     assert balance is not None
     if c.last_signature is None:
         raise NoBalanceProofReceived('Payment has not been registered.')
     if balance != c.balance:
         raise InvalidBalanceProof('Requested closing balance does not match latest one.')
     c.is_closed = True
     c.mtime = time.time()
     receiver_sig = sign_close(self.private_key, c.last_signature)
     self.state.set_channel(c)
     self.log.info('signed cooperative closing message (sender %s, block number %s)',
                   sender, open_block_number)
     return receiver_sig