def find_incoming_utxos(block_hash, transactions, isGenesis=False): """ Iterates through all the outputs and looks for any directed to user's wallet. If found, save to the utxo pool :return: """ myAddress = SHA256.new(get_public_key("string").encode()).hexdigest() conf = Configuration() for tnx_id, tnx_info in transactions.items(): # deserialize transaction tnx_payload = tnx_info tnx_payload["transaction_id"] = tnx_id tnx = Transaction(payload=tnx_payload) for index in range(len(tnx.outputs)): if tnx.outputs[index]["address"] == myAddress and not isGenesis: save_utxo(tnx.get_transaction_id(), index, block_hash, tnx.outputs[index]["amount"]) conf.add_balance(tnx.outputs[index]["amount"]) elif tnx.outputs[index]["address"] == myAddress and isGenesis: save_utxo(tnx.get_transaction_id(), -1, block_hash, tnx.outputs[index]["amount"]) conf.add_balance(tnx.outputs[index]["amount"])
def find_incoming_utxos(block_hash, transactions, isGenesis=False): """ Iterates through all the outputs and looks for any directed to user's wallet. If found, save to the utxo pool :return: """ myAddress = SHA256.new(get_public_key("string").encode()).hexdigest() conf = Configuration() for tnx_id, tnx_info in transactions.items(): # deserialize transaction tnx_payload = tnx_info tnx_payload["transaction_id"] = tnx_id tnx = Transaction(payload=tnx_payload) for index in range(len(tnx.outputs)): if tnx.outputs[index]["address"] == myAddress and not isGenesis: save_utxo(tnx.get_transaction_id(), index, block_hash, tnx.outputs[index]["amount"]) conf.add_balance(tnx.outputs[index]["amount"]) elif tnx.outputs[index]["address"] == myAddress and isGenesis: save_utxo(tnx.get_transaction_id(), -1, block_hash, tnx.outputs[index]["amount"]) conf.add_balance(tnx.outputs[index]["amount"])
def create_transaction(recipient, amount): """ creates a new transaction and add it to verified_transactions.json :param recipient: public address of the recipient :param amount: the amount of abc to be sent :return: None """ # TODO: Send a success message to client conf = Configuration() try: tx = Transaction() tx.add_output(recipient, amount) tx.unlock_inputs(get_private_key(), get_public_key("string")) save_verified_transaction(tx.get_transaction_id(), tx.get_data()) conf.subtract_balance(tx.sum_of_outputs()) except ValueError as e: # Will raise if insufficient utxos are found raise ValueError("INSUFFICIENT FUNDS")
def create_transaction(recipient, amount): """ creates a new transaction and add it to verified_transactions.json :param recipient: public address of the recipient :param amount: the amount of abc to be sent :return: None """ # TODO: Send a success message to client conf = Configuration() try: tx = Transaction() tx.add_output(recipient, amount) tx.unlock_inputs(get_private_key(), get_public_key("string")) save_verified_transaction(tx.get_transaction_id(), tx.get_data()) conf.subtract_balance(tx.sum_of_outputs()) except ValueError as e: # Will raise if insufficient utxos are found raise ValueError("INSUFFICIENT FUNDS")