Пример #1
0
    def on_conditional_payment(self, command: str, customer: str, sender: str,
                               open_block_number: int, payout: int,
                               conditional_transfer: bool, image: bytes,
                               pay_sig: bytes):
        #print('\nconditional paymen\n')
        #debug_print([customer, sender, open_block_number, payout, conditional_transfer, 'image', image, 'pay_sig', pay_sig])
        customer = to_checksum_address(customer)
        sender = to_checksum_address(sender)

        try:
            job = self.jobs[customer, sender, open_block_number]
        except KeyError:
            self.log.info(
                'No such channel being outsourced (customer %s sender %s open_block_number %s',
                customer, sender, open_block_number)
            return

        assert job.sent_receipt
        assert payout > 0

        self.log.info('Conditional Payment (customer %s)\n', customer)
        self.log.debug(
            'Cond Payment (\n\tjob image %s, \n\tcustomer image %s)',
            encode_hex(job.last_image), encode_hex(image))

        assert image == job.last_image

        signer = verify_cond_payment(sender, open_block_number, payout,
                                     conditional_transfer, image, pay_sig)

        self.log.debug('conditional payment signed by %s, customer %s', signer,
                       customer)
        assert is_same_address(signer, customer)

        assert keccak256((job.last_preimage, 32)) == image
        p = ConditionalPayment(conditional_transfer, payout, image,
                               open_block_number, pay_sig)
        self.jobs[customer, sender, open_block_number].conditional_payment = p

        if self.reveal_pre_image:
            print(bcolors.OKBLUE +
                  '\nMonitor: Sending pre-image to customer %d...\n' %
                  job.last_preimage + bcolors.ENDC)
            job.respond = True
            return job.last_preimage
        else:
            print(bcolors.OKBLUE +
                  '\nMonitor: Not revealing pre-image to customer' +
                  bcolors.ENDC)
            #            job.respond = False
            return
Пример #2
0
        def sender_property_patched(self: Transaction):
            if self._sender:
                return self._sender

            if self.v and self.v >= 35:
                v = bytes([self.v])
                r = self.r.to_bytes(32, byteorder='big')
                s = self.s.to_bytes(32, byteorder='big')
                raw_tx = Transaction(self.nonce, self.gasprice, self.startgas,
                                     self.to, self.value, self.data,
                                     (self.v - 35) // 2, 0, 0)
                msg = keccak256(rlp.encode(raw_tx))
                self._sender = decode_hex(addr_from_sig(r + s + v, msg))
                return self._sender
            else:
                return sender_property_original(self)
Пример #3
0
    def create_signed_receipt(self, customer: str, sender: str,
                              open_block_number: int,
                              balance_message_hash: bytes, signature: str,
                              round_number: int):
        #def create_signed_receipt(self, customer: str, sender: str, open_block_number: int, balance_message_hash: bytes, round_number: int, signature: str):

        customer = to_checksum_address(customer)
        sender = to_checksum_address(sender)

        pre_image = self.rng.randint(0, 2**20)
        image = keccak256((pre_image, 32))

        self.log.info('Receipt (pre image %d, image %s)\n', pre_image,
                      encode_hex(image))

        self.jobs[customer, sender, open_block_number].last_image = image
        self.jobs[customer, sender,
                  open_block_number].last_preimage = pre_image

        #delta_settle = int(self.channel_monitor_contract.call().delta_settle())
        curr_block = self.blockchain.web3.eth.blockNumber

        t_start = curr_block
        t_expire = t_start + self.delta_receipt

        receipt_msg = sign_receipt2(self.private_key, customer, sender,
                                    open_block_number, image, t_start,
                                    t_expire, round_number,
                                    balance_message_hash)
        """
        Output for demonstration video
        """
        print(bcolors.OKBLUE + '\nMonitor: Sending receipt to monitor...' +
              bcolors.OKBLUE)
        print(bcolors.OKBLUE + 'Receipt:' + '\n\tStart: %s' % t_start +
              '\n\tExpire: %s' % t_expire + '\n\tpre image: %s' % pre_image +
              '\n\timage: %s' % encode_hex(image) + bcolors.ENDC)

        #return [MONITOR_RECEIPT, (customer,sender,open_block_number,image,t_start,t_expire,balance_message_hash), receipt_msg]
        return [
            MONITOR_RECEIPT,
            (customer, sender, open_block_number, image, t_start, t_expire,
             round_number, balance_message_hash), receipt_msg
        ]
Пример #4
0
 def key(self) -> bytes:
     return keccak256(self.sender, self.receiver, self.block)
Пример #5
0
def test_sign_v0():
    msg = keccak256('hello v=0')
    sig = sign(SENDER_PRIVATE_KEY, msg)
    assert sig[-1] == 1
    assert is_same_address(addr_from_sig(sig, msg), SENDER_ADDR)
Пример #6
0
def test_sign_v0():
    msg = keccak256('hello v=0')
    sig = sign(SENDER_PRIVATE_KEY, msg)
    assert sig[-1] == 1
    assert is_same_address(addr_from_sig(sig, msg), SENDER_ADDR)
Пример #7
0
 def key(self) -> bytes:
     return keccak256(self.sender, self.receiver, self.block)