Compare commits
No commits in common. "main" and "main" have entirely different histories.
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,3 @@
|
|||||||
venv/*
|
venv/*
|
||||||
mine_data/*
|
mine_data/*
|
||||||
mariadb_data/*
|
mariadb_data/*
|
||||||
*.pem
|
|
||||||
*__pycache__*
|
|
||||||
*.swp
|
|
||||||
|
|||||||
6
cli.py
6
cli.py
@ -263,10 +263,8 @@ def opt_view_deck():
|
|||||||
msg_array[0] = "You have no cards to view";
|
msg_array[0] = "You have no cards to view";
|
||||||
return;
|
return;
|
||||||
|
|
||||||
msg = "Successfully listed deck.\n"
|
for i, card in enumerate(cards):
|
||||||
for card in cards:
|
print(f"{i+1}. Card ID: {card['cardId']}, Page ID: {card['pageId']}");
|
||||||
msg += f"Card ID: {card['cardId']}, Page ID: {card['pageId']}\n"
|
|
||||||
msg_array[0] = msg
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg_array[0] = f"Error fetching cards: {str(e)}";
|
msg_array[0] = f"Error fetching cards: {str(e)}";
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
cryptography
|
|
||||||
dotenv
|
|
||||||
wikipedia
|
|
||||||
@ -13,7 +13,6 @@ services:
|
|||||||
MINE_DB_HOST: mariadb-mine
|
MINE_DB_HOST: mariadb-mine
|
||||||
MINE_DB_USER: mine
|
MINE_DB_USER: mine
|
||||||
MINE_DB_PASSWORD: 123abc
|
MINE_DB_PASSWORD: 123abc
|
||||||
MINE_LOG_FILE: /tmp/mine.log
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- mariadb-mine
|
- mariadb-mine
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import base64
|
import base64
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
|
||||||
import mariadb
|
import mariadb
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@ -182,8 +181,6 @@ class Database():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
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
|
delay = 2
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -198,7 +195,6 @@ class Database():
|
|||||||
for each in self.SQL_CREATE_TABLES:
|
for each in self.SQL_CREATE_TABLES:
|
||||||
self.conn.cursor().execute(each)
|
self.conn.cursor().execute(each)
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
self.logger.error(e)
|
|
||||||
time.sleep(delay := delay**2)
|
time.sleep(delay := delay**2)
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
@ -243,8 +239,11 @@ class Database():
|
|||||||
|
|
||||||
def get_blocks(self):
|
def get_blocks(self):
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
cur.execute(self.SQL_GET_BLOCKS)
|
cur.execute(self.SQL_GET_LAST_BLOCK)
|
||||||
blocks = cur.fetchall()
|
blocks = cur.fetchall()
|
||||||
|
if blocks:
|
||||||
|
blockCard = self.get_card_by_block_id(lastBlock[0])
|
||||||
|
blockTransactions = self.get_transactions_by_block_id(lastBlock[0])
|
||||||
return [
|
return [
|
||||||
Block(
|
Block(
|
||||||
blockId = uuid.UUID(block[0]),
|
blockId = uuid.UUID(block[0]),
|
||||||
@ -256,10 +255,12 @@ class Database():
|
|||||||
height = block[3],
|
height = block[3],
|
||||||
difficulty = block[4],
|
difficulty = block[4],
|
||||||
nonce = block[5],
|
nonce = block[5],
|
||||||
card = self.get_card_by_block_id(block[0]),
|
card = blockCard,
|
||||||
transactions = self.get_transactions_by_block_id(block[0])
|
transactions = blockTransactions
|
||||||
) for block in blocks
|
)
|
||||||
] if blocks else []
|
]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_last_block(self):
|
def get_last_block(self):
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
|
|||||||
@ -50,8 +50,7 @@ def generate_origin_block():
|
|||||||
@mine.get('/')
|
@mine.get('/')
|
||||||
def index_get():
|
def index_get():
|
||||||
try:
|
try:
|
||||||
blocks = db.get_blocks()
|
return jsonify([each.as_dict() for each in db.get_blocks()])
|
||||||
return flask.jsonify([block.as_dict() for block in blocks]) if blocks else flask.jsonify({})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return flask.jsonify(
|
return flask.jsonify(
|
||||||
{'Error': str(e)}
|
{'Error': str(e)}
|
||||||
@ -172,8 +171,6 @@ def cards_get():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return flask.jsonify([card.as_dict() for card in deck] if deck else [])
|
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:
|
except Exception as e:
|
||||||
return flask.jsonify(
|
return flask.jsonify(
|
||||||
{'Error': str(e)}
|
{'Error': str(e)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user