Example #1
0
    def test_verify_transaction(self):
        cost = TransactionCosts(0.0001, 0.0000275, 3)
        tx_input = Spendable(200, '18eKkAWyU9kvRNHPKxnZb6wwtPMrNmRRRA',
                             h2b('8443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b154'), 0)
        tx_outs = [trx_utils.create_transaction_output('mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', 0.0000275)]
        op_return_val = h2b('e9cee71ab932fde863338d08be4de9dfe39ea049bdafb342ce659ec5450b69ae')
        tx = trx_utils.create_trx(op_return_val, cost, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, tx_input)

        hextx = hexlify(tx.serialize())

        trx_utils.verify_transaction(hextx, hexlify(op_return_val))
Example #2
0
    def issue_on_blockchain(self, revocation_address,
                            issuing_transaction_cost):
        """
        Issue the certificates on the Bitcoin blockchain
        :param revocation_address:
        :param issuing_transaction_cost:
        :return:
        """
        transactions_data = self.create_transactions(revocation_address,
                                                     issuing_transaction_cost)
        for transaction_data in transactions_data:
            unsigned_tx_file_name = transaction_data.batch_metadata.unsigned_tx_file_name
            signed_tx_file_name = transaction_data.batch_metadata.unsent_tx_file_name
            sent_tx_file_name = transaction_data.batch_metadata.sent_tx_file_name

            # persist the transaction in case broadcasting fails
            hex_tx = hexlify(transaction_data.tx.serialize())
            with open(unsigned_tx_file_name, 'w') as out_file:
                out_file.write(hex_tx)

            # sign transaction and persist result
            signed_tx = self.signer.sign_tx(hex_tx, transaction_data.tx_input,
                                            self.netcode)

            # log the actual byte count
            tx_byte_count = trx_utils.get_byte_count(signed_tx)
            logging.info('The actual transaction size is %d bytes',
                         tx_byte_count)

            signed_hextx = signed_tx.as_hex()
            with open(signed_tx_file_name, 'w') as out_file:
                out_file.write(signed_hextx)

            # verify transaction before broadcasting
            trx_utils.verify_transaction(signed_hextx,
                                         transaction_data.op_return_value)

            # send tx and persist txid
            tx_id = self.connector.broadcast_tx(signed_tx)
            if tx_id:
                logging.info('Broadcast transaction with txid %s', tx_id)
            else:
                logging.warning(
                    'could not broadcast transaction but you can manually do it! signed hextx=%s',
                    signed_hextx)

            self.persist_tx(sent_tx_file_name, tx_id)
    def issue_on_blockchain(self, revocation_address, issuing_transaction_cost):
        """
        Issue the certificates on the Bitcoin blockchain
        :param revocation_address:
        :param issuing_transaction_cost:
        :return:
        """
        transactions_data = self.create_transactions(revocation_address, issuing_transaction_cost)
        for transaction_data in transactions_data:
            # persist the transaction in case broadcasting fails
            hex_tx = hexlify(transaction_data.tx.serialize())
            with open(transaction_data.unsigned_tx_file_name, 'w') as out_file:
                out_file.write(hex_tx)

            # sign transaction and persist result
            signed_tx = trx_utils.sign_tx(hex_tx, transaction_data.tx_input)

            # log the actual byte count
            tx_byte_count = trx_utils.get_byte_count(signed_tx)
            logging.info('The actual transaction size is %d bytes', tx_byte_count)

            signed_hextx = signed_tx.as_hex()
            with open(transaction_data.signed_tx_file_name, 'w') as out_file:
                out_file.write(signed_hextx)

            # verify transaction before broadcasting
            trx_utils.verify_transaction(signed_hextx, transaction_data.op_return_value)

            # send tx and persist txid
            tx_id = broadcast_tx(signed_tx)
            if tx_id:
                logging.info('Broadcast transaction with txid %s', tx_id)
            else:
                logging.warning(
                    'could not broadcast transaction but you can manually do it! signed hextx=%s', signed_hextx)

            self.finish_tx(transaction_data.sent_tx_file_name, tx_id)