def create_transactions(self, wallet, revocation_address, issuing_transaction_cost, split_input_trxs): # finish tree self.tree.make_tree() op_return_value = unhexlify(self.tree.get_merkle_root()) unspent_outputs = wallet.get_unspent_outputs(self.issuing_address) last_output = unspent_outputs[-1] txouts = self.build_txouts(issuing_transaction_cost) txouts = txouts + [ trx_utils.create_transaction_output( revocation_address, issuing_transaction_cost.min_per_output) ] tx = trx_utils.create_trx(op_return_value, issuing_transaction_cost, self.issuing_address, txouts, last_output) unsigned_tx_file_name = convert_file_name( self.config.unsigned_txs_file_pattern, self.batch_id) unsent_tx_file_name = convert_file_name( self.config.signed_txs_file_pattern, self.batch_id) sent_tx_file_name = convert_file_name( self.config.sent_txs_file_pattern, self.batch_id) td = TransactionData(uid=self.batch_id, tx=tx, tx_input=last_output, op_return_value=hexlify(op_return_value), unsigned_tx_file_name=unsigned_tx_file_name, signed_tx_file_name=unsent_tx_file_name, sent_tx_file_name=sent_tx_file_name) return [td]
def test_create_trx(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)] tx = trx_utils.create_trx('TEST'.encode('utf-8'), cost, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, tx_input) hextx = hexlify(tx.serialize()) self.assertEquals(hextx, '01000000018443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b1540000000000ffffffff0300000000000000001976a914072a22e5913cd939904c46bbd0bc56755543384b88acc5000000000000001976a914072a22e5913cd939904c46bbd0bc56755543384b88ac0000000000000000066a045445535400000000')
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))
def create_transactions(self, revocation_address, issuing_transaction_cost): """ Create the batch Bitcoin transaction :param revocation_address: :param issuing_transaction_cost: :return: """ self.tree.make_tree() spendables = get_unspent_outputs(self.issuing_address) if not spendables: error_message = 'No money to spend at address {}'.format( self.issuing_address) logging.error(error_message) raise InsufficientFundsError(error_message) last_input = spendables[-1] op_return_value = unhexlify(self.tree.get_merkle_root()) tx_outs = self.build_recipient_tx_outs() tx_outs.append( trx_utils.create_transaction_output( revocation_address, issuing_transaction_cost.min_per_output)) transaction = trx_utils.create_trx(op_return_value, issuing_transaction_cost, self.issuing_address, tx_outs, last_input) unsigned_tx_file_name = convert_file_name( self.config.unsigned_txs_file_pattern, self.batch_id) unsent_tx_file_name = convert_file_name( self.config.signed_txs_file_pattern, self.batch_id) sent_tx_file_name = convert_file_name( self.config.sent_txs_file_pattern, self.batch_id) transaction_data = TransactionData( uid=self.batch_id, tx=transaction, tx_input=last_input, op_return_value=hexlify(op_return_value), unsigned_tx_file_name=unsigned_tx_file_name, signed_tx_file_name=unsent_tx_file_name, sent_tx_file_name=sent_tx_file_name) return [transaction_data]
def create_transactions(self, wallet, revocation_address, issuing_transaction_cost, split_input_trxs): unspent_outputs = wallet.get_unspent_outputs(self.issuing_address) current_tail = -1 txs = [] for uid, certificate_metadata in self.certificates_to_issue.items(): last_output = unspent_outputs[current_tail] with open(certificate_metadata.certificate_hash_file_name, 'r') as in_file: op_return_value = in_file.read() # send a transaction to the recipient's public key, and to a # revocation address txouts = trx_utils.create_recipient_outputs( issuing_transaction_cost.min_per_output, certificate_metadata.public_key, revocation_address) tx = trx_utils.create_trx(unhexlify(op_return_value), issuing_transaction_cost, self.issuing_address, txouts, last_output) unsigned_tx_file_name = convert_file_name( self.config.unsigned_txs_file_pattern, uid) unsent_tx_file_name = convert_file_name( self.config.signed_txs_file_pattern, uid) sent_tx_file_name = convert_file_name( self.config.sent_txs_file_pattern, uid) td = TransactionData(uid=certificate_metadata.uid, tx=tx, tx_input=last_output, op_return_value=op_return_value, unsigned_tx_file_name=unsigned_tx_file_name, signed_tx_file_name=unsent_tx_file_name, sent_tx_file_name=sent_tx_file_name) txs.append(td) if split_input_trxs: current_tail -= 1 return txs