def insert_transaction(transaction, db): """Add a transaction to the database.""" cursor = db.cursor() block = (transaction['block_index'], transaction['block_hash'], transaction['block_time'], None, None, None, None) cursor.execute('''INSERT INTO blocks (block_index, block_hash, block_time, ledger_hash, txlist_hash, previous_block_hash, difficulty) VALUES (?,?,?,?,?,?,?)''', block) keys = ",".join(transaction.keys()) cursor.execute('''INSERT INTO transactions ({}) VALUES (?,?,?,?,?,?,?,?,?,?,?)'''.format(keys), tuple(transaction.values())) cursor.close() util.CURRENT_BLOCK_INDEX = transaction['block_index']