Example #1
0
    def signing_format(self):
        """
        converts Transaction object into a hexadecimal string, as per signing protocol
        :return: hexadecimal transaction in signing format
        :rtype: str
        """
        inputs_amount = len(self.inputs)
        outputs_amount = len(self.outputs)

        message = "{}{}".format(inputs_amount, outputs_amount)

        for inp in self.inputs:
            input_key = inp[0]
            input_block_number = hexify(inp[1], 6)
            input_transaction_number = hexify(inp[2], 2)
            message += input_key + input_block_number + input_transaction_number
        for output in self.outputs:
            output_address = output[0]
            amount = hexify(output[1], 4)
            message += output_address + amount
        return message
Example #2
0
    def network_format(self):
        """
        converts Transaction object into a hexadecimal string of the transaction in the network protocol format
        :return: hexadecimal transaction in the network protocol format
        :rtype: str
        """
        message = ""

        time_created = hexify(int(self.timestamp.timestamp()), 8)

        inputs_amount = hexify(len(self.inputs), 1)

        outputs_amount = hexify(len(self.outputs), 1)

        message = "e{}{}{}".format(time_created, inputs_amount, outputs_amount)

        for inp in self.inputs:
            input_key = inp[0]
            input_block_number = hexify(inp[1], 6)
            input_transaction_number = hexify(inp[2], 2)
            signature = inp[3]

            message += input_key + input_block_number + input_transaction_number + signature

        for output in self.outputs:
            output_address = output[0]
            amount = hexify(output[1], 4)

            message += output_address + amount
        message = message.replace(" ", "")
        return message
Example #3
0
 def network_format(self):
     """
     returns the Block in the network format
     :return: block in the network format
     :rtype: str
     """
     network_format = "d{}{}{}{}{}{}{}".format(
         hexify(self.block_number, 6), hexify(self.timestamp, 8),
         hexify(self.difficulty, 2), hexify(self.nonce, 64), self.prev_hash,
         self.merkle_root_hash, hexify(len(self.transactions), 2))
     for t in self.transactions:
         if isinstance(t, str):
             t = Transaction.from_network_format(t)
         network_format += hexify(len(t.network_format()), 5)
         network_format += t.network_format()
     return network_format