From ea639eeac180caa52219071db3c88e55fbc0f93b Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Mon, 13 Oct 2025 12:18:06 -0400 Subject: [PATCH 1/6] Closes WikiDeck/wikideck#6 --- .gitignore | 2 ++ client-requirements.txt | 3 +++ wikideck/Mine/Database.py | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 client-requirements.txt diff --git a/.gitignore b/.gitignore index 10b5b15..c2244da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ venv/* mine_data/* mariadb_data/* +*.pem +*__pycache__* diff --git a/client-requirements.txt b/client-requirements.txt new file mode 100644 index 0000000..e6edb68 --- /dev/null +++ b/client-requirements.txt @@ -0,0 +1,3 @@ +cryptography +dotenv +wikipedia diff --git a/wikideck/Mine/Database.py b/wikideck/Mine/Database.py index 3064f6b..11c5c19 100644 --- a/wikideck/Mine/Database.py +++ b/wikideck/Mine/Database.py @@ -1,5 +1,6 @@ import base64 import datetime +import logging import mariadb import os import time @@ -181,6 +182,8 @@ class Database(): """ def __init__(self): + logging.basicConfig(filename=os.getenv('MINE_LOG_FILE', '/var/log/mine.log'), level=logging.INFO) + self.logger = logging.getLogger(__name__) delay = 2 while True: try: @@ -195,6 +198,7 @@ class Database(): for each in self.SQL_CREATE_TABLES: self.conn.cursor().execute(each) except mariadb.Error as e: + self.logger.error(e) time.sleep(delay := delay**2) continue break -- 2.45.2 From f1b3eab3a3b6edb98657764d3db2090c95b3a940 Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Mon, 13 Oct 2025 12:47:38 -0400 Subject: [PATCH 2/6] Closes WikiDeck/wikideck#5 --- docker-compose.yaml | 1 + wikideck/Mine/Mine.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index b1658fc..e8ec7c2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,6 +13,7 @@ services: MINE_DB_HOST: mariadb-mine MINE_DB_USER: mine MINE_DB_PASSWORD: 123abc + MINE_LOG_FILE: /tmp/mine.log depends_on: - mariadb-mine ports: diff --git a/wikideck/Mine/Mine.py b/wikideck/Mine/Mine.py index e5e5825..1e9f698 100644 --- a/wikideck/Mine/Mine.py +++ b/wikideck/Mine/Mine.py @@ -50,7 +50,7 @@ def generate_origin_block(): @mine.get('/') def index_get(): try: - return jsonify([each.as_dict() for each in db.get_blocks()]) + return flask.jsonify([each.as_dict() for each in db.get_blocks()]) except Exception as e: return flask.jsonify( {'Error': str(e)} -- 2.45.2 From 20931ba41f5845945fcf1795c0c66dffb1bdca70 Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Mon, 13 Oct 2025 13:10:15 -0400 Subject: [PATCH 3/6] Closes WikiDeck/wikideck#8 --- wikideck/Mine/Database.py | 4 ++-- wikideck/Mine/Mine.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wikideck/Mine/Database.py b/wikideck/Mine/Database.py index 11c5c19..d1613f8 100644 --- a/wikideck/Mine/Database.py +++ b/wikideck/Mine/Database.py @@ -246,8 +246,8 @@ class Database(): cur.execute(self.SQL_GET_LAST_BLOCK) blocks = cur.fetchall() if blocks: - blockCard = self.get_card_by_block_id(lastBlock[0]) - blockTransactions = self.get_transactions_by_block_id(lastBlock[0]) + blockCard = self.get_card_by_block_id(blocks[0]) + blockTransactions = self.get_transactions_by_block_id(blocks[0]) return [ Block( blockId = uuid.UUID(block[0]), diff --git a/wikideck/Mine/Mine.py b/wikideck/Mine/Mine.py index 1e9f698..5c076b4 100644 --- a/wikideck/Mine/Mine.py +++ b/wikideck/Mine/Mine.py @@ -171,6 +171,8 @@ def cards_get(): ) ) return flask.jsonify([card.as_dict() for card in deck] if deck else []) + else: + return flask.jsonify({'Error': "No public key."}), 400 except Exception as e: return flask.jsonify( {'Error': str(e)} -- 2.45.2 From 2b467ce248cf02fc4ccf1aefeeac54992c0e9920 Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Tue, 14 Oct 2025 12:26:48 -0400 Subject: [PATCH 4/6] Closes WikiDeck/wikideck#9 --- .gitignore | 1 + cli.py | 6 ++++-- wikideck/Mine/Database.py | 37 ++++++++++++++++--------------------- wikideck/Mine/Mine.py | 3 ++- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index c2244da..e85b5bb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ mine_data/* mariadb_data/* *.pem *__pycache__* +*.swp diff --git a/cli.py b/cli.py index e33ad77..0aec76c 100644 --- a/cli.py +++ b/cli.py @@ -263,8 +263,10 @@ def opt_view_deck(): msg_array[0] = "You have no cards to view"; return; - for i, card in enumerate(cards): - print(f"{i+1}. Card ID: {card['cardId']}, Page ID: {card['pageId']}"); + msg = "" + for card in cards: + msg += f"Card ID: {card['cardId']}, Page ID: {card['pageId']}\n" + msg_array[0] = msg except Exception as e: msg_array[0] = f"Error fetching cards: {str(e)}"; diff --git a/wikideck/Mine/Database.py b/wikideck/Mine/Database.py index d1613f8..11b5e47 100644 --- a/wikideck/Mine/Database.py +++ b/wikideck/Mine/Database.py @@ -243,28 +243,23 @@ class Database(): def get_blocks(self): cur = self.conn.cursor() - cur.execute(self.SQL_GET_LAST_BLOCK) + cur.execute(self.SQL_GET_BLOCKS) blocks = cur.fetchall() - if blocks: - blockCard = self.get_card_by_block_id(blocks[0]) - blockTransactions = self.get_transactions_by_block_id(blocks[0]) - return [ - Block( - blockId = uuid.UUID(block[0]), - previousHash = block[1], - timestamp = datetime.datetime.strptime( - block[2], - "%Y-%m-%d %H:%M:%S.%f%z" - ), - height = block[3], - difficulty = block[4], - nonce = block[5], - card = blockCard, - transactions = blockTransactions - ) - ] - else: - return None + return [ + Block( + blockId = uuid.UUID(block[0]), + previousHash = block[1], + timestamp = datetime.datetime.strptime( + block[2], + "%Y-%m-%d %H:%M:%S.%f%z" + ), + height = block[3], + difficulty = block[4], + nonce = block[5], + card = self.get_card_by_block_id(block[0]), + transactions = self.get_transactions_by_block_id(block[0]) + ) for block in blocks + ] if blocks else [] def get_last_block(self): cur = self.conn.cursor() diff --git a/wikideck/Mine/Mine.py b/wikideck/Mine/Mine.py index 5c076b4..c29aa59 100644 --- a/wikideck/Mine/Mine.py +++ b/wikideck/Mine/Mine.py @@ -50,7 +50,8 @@ def generate_origin_block(): @mine.get('/') def index_get(): try: - return flask.jsonify([each.as_dict() for each in db.get_blocks()]) + blocks = db.get_blocks() + return flask.jsonify([block.as_dict() for block in blocks]) if blocks else flask.jsonify({}) except Exception as e: return flask.jsonify( {'Error': str(e)} -- 2.45.2 From c945c8e229dcbf8221bef09d19f61510fba6fe18 Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Tue, 14 Oct 2025 17:16:17 -0400 Subject: [PATCH 5/6] Small change to cli.py --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index 0aec76c..6c27bfe 100644 --- a/cli.py +++ b/cli.py @@ -263,7 +263,7 @@ def opt_view_deck(): msg_array[0] = "You have no cards to view"; return; - msg = "" + msg = "Successfully listed deck." for card in cards: msg += f"Card ID: {card['cardId']}, Page ID: {card['pageId']}\n" msg_array[0] = msg -- 2.45.2 From 52cac5e19e11372960c30d9ba24241694bd11567 Mon Sep 17 00:00:00 2001 From: Eric Meehan Date: Tue, 14 Oct 2025 17:17:29 -0400 Subject: [PATCH 6/6] Another small change to cli.py --- cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli.py b/cli.py index 6c27bfe..cb5e056 100644 --- a/cli.py +++ b/cli.py @@ -263,7 +263,7 @@ def opt_view_deck(): msg_array[0] = "You have no cards to view"; return; - msg = "Successfully listed deck." + msg = "Successfully listed deck.\n" for card in cards: msg += f"Card ID: {card['cardId']}, Page ID: {card['pageId']}\n" msg_array[0] = msg -- 2.45.2