コード例 #1
0
 def test_broadcast_tx_mainnet(self):
     """
     Broadcasting tests fail because the transaction has already been pushed. So we're looking for a 'transaction
     already in blockchain' error
     """
     try:
         tx = Tx.from_hex(MAINNET_TX)
         broadcast_tx(tx)
         self.assertTrue(False)
     except Exception as e:
         self.assertTrue('already in block chain', str(e.args[0]))
         return
     self.assertTrue(False)
コード例 #2
0
 def test_broadcast_tx_mainnet(self):
     """
     Broadcasting tests fail because the transaction has already been pushed. So we're looking for a 'transaction
     already in blockchain' error
     """
     try:
         tx = Tx.from_hex(MAINNET_TX)
         broadcast_tx(tx)
         self.assertTrue(False)
     except Exception as e:
         self.assertTrue('already in block chain', str(e.args[0]))
         return
     self.assertTrue(False)
コード例 #3
0
ファイル: issuer.py プロジェクト: funwhilelost/cert-issuer
    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)