From 653fb3d47b760d26010f44ec7703feb3818ee8dc Mon Sep 17 00:00:00 2001 From: Xavier Fiechter Date: Mon, 4 Mar 2024 12:07:29 +0100 Subject: [PATCH] . --- .gitignore | 3 +- django/labellabor/make_config.py | 15 +- django/labellabor/settings.py | 2 +- django/labellabor/views.py | 7 +- django/templates/_base.html | 58 +++--- django/templates/label_edit.html | 13 +- django/templates/label_edit_labeling.html | 191 ++++++++++++++++++ .../templates/label_edit_output_details.html | 22 ++ django/templates/profile.html | 20 +- docker-compose.yml | 36 +--- mysql/init.sql | 2 +- 11 files changed, 285 insertions(+), 84 deletions(-) create mode 100644 django/templates/label_edit_labeling.html create mode 100644 django/templates/label_edit_output_details.html diff --git a/.gitignore b/.gitignore index da16231..fd3bc6d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ db/ *.pyc __pycache__ django/importer/uploadeddata/* -_scratches +#_scratches +exports.sh diff --git a/django/labellabor/make_config.py b/django/labellabor/make_config.py index 195fa66..dfe547c 100644 --- a/django/labellabor/make_config.py +++ b/django/labellabor/make_config.py @@ -6,6 +6,12 @@ import configparser import time import os +def read_file_content(file_path): + with open(file_path, 'r') as file: + content = file.read() + return content.strip() + + def generate_random_string(length): # Exclude curly braces '{}' from the pool of characters characters = string.ascii_letters + string.digits @@ -14,14 +20,11 @@ def generate_random_string(length): def generate_config_file(config_file_path="config.ini"): config = configparser.ConfigParser() - # Generate random values where needed dj_secret_key = generate_random_string(50) - database_password = "10almm6a62ec3z8jm4jjw6dny5" # os.getenv("MYSQL_PASSWORD") - print("*"*20) - print (database_password) - print("*"*20) - crypto_salt = 'labelbase_{}_'.format(generate_random_string(8)) + #database_password = read_file_content("/run/secrets/mysql_password") + database_password = os.getenv("MYSQL_PASSWORD") + crypto_salt = 'labelbase_{}_'.format(generate_random_string(32)) # Set the values in the configuration file config['internal'] = { diff --git a/django/labellabor/settings.py b/django/labellabor/settings.py index dd9e54a..9b4f983 100644 --- a/django/labellabor/settings.py +++ b/django/labellabor/settings.py @@ -107,7 +107,7 @@ INSTALLED_APPS = [ "importer", "finances", "background_task", - "connectrum", + "connectrum", ] diff --git a/django/labellabor/views.py b/django/labellabor/views.py index 980c64c..f92eeb9 100644 --- a/django/labellabor/views.py +++ b/django/labellabor/views.py @@ -549,6 +549,9 @@ class LabelUpdateView(UpdateView): action = self.kwargs['action'] if action == 'labeling': return "label_edit_labeling.html" + elif action == 'output-details': + return "label_edit_output_details.html" + return "label_edit_update.html" def get_context_data(self, **kwargs): @@ -557,7 +560,9 @@ class LabelUpdateView(UpdateView): context["labelbase"] = self.object.labelbase context["action"] = self.kwargs.get('action', 'update') if context["action"] == "labeling": - # mempool_api = self.object.labelbase.get_mempool_api() + context["labelform"] = LabelForm( + request=self.request, labelbase_id=self.object.labelbase.id + ) if self.object.type == "tx": mempool_api = self.object.labelbase.get_mempool_api() context["res_tx"] = mempool_api.get_transaction(self.object.ref) diff --git a/django/templates/_base.html b/django/templates/_base.html index acfd652..eea55b3 100644 --- a/django/templates/_base.html +++ b/django/templates/_base.html @@ -385,40 +385,40 @@ $(document).ready(function () { + // Disable the Origin field by default if not Tx + {% if label.type == "tx" %} + {% else %} + $('#id_origin').prop('disabled', true); + {% endif %} - // Disable the Origin field by default if not Tx - {% if label.type == "tx" %} - {% else %} - $('#id_origin').prop('disabled', true); - {% endif %} + // Disable the Spendable field by default if not output + {% if label.type == "output" %} + {% else %} + $('#id_spendable').prop('disabled', true); + {% endif %} + // Monitor changes in the Type dropdown + $('#id_type').change(function () { + var selectedType = $(this).val(); - // Disable the Spendable field by default if not output - {% if label.type == "output" %} - {% else %} - $('#id_spendable').prop('disabled', true); - {% endif %} - // Monitor changes in the Type dropdown - $('#id_type').change(function () { - var selectedType = $(this).val(); + // Enable or disable the Origin field based on the selected Type + if (selectedType === 'tx') { + $('#id_origin').prop('disabled', false); + $('#id_origin').val(''); + } else { + $('#id_origin').prop('disabled', true); + } - // Enable or disable the Origin field based on the selected Type - if (selectedType === 'tx') { - $('#id_origin').prop('disabled', false); - $('#id_origin').val(''); - } else { - $('#id_origin').prop('disabled', true); - } - - // Enable or disable the Spendable field based on the selected Type - if (selectedType === 'output') { - $('#id_spendable').prop('disabled', false); - } else { - $('#id_spendable').val("unknown").change(); - $('#id_spendable').prop('disabled', true); - } - }); + // Enable or disable the Spendable field based on the selected Type + if (selectedType === 'output') { + $('#id_spendable').prop('disabled', false); + } else { + $('#id_spendable').val("unknown").change(); + $('#id_spendable').prop('disabled', true); + } }); + }); + diff --git a/django/templates/label_edit.html b/django/templates/label_edit.html index 191b9e0..ce05f16 100644 --- a/django/templates/label_edit.html +++ b/django/templates/label_edit.html @@ -38,6 +38,9 @@ -->{% endcomment %} {% case "output" %} + {% comment %}{% endcomment %} - {% case "addr" %} - {% comment %}{% endcomment %} + + + + {% endswitch %} diff --git a/django/templates/label_edit_labeling.html b/django/templates/label_edit_labeling.html new file mode 100644 index 0000000..034cbcc --- /dev/null +++ b/django/templates/label_edit_labeling.html @@ -0,0 +1,191 @@ +{% extends "label_edit.html" %} +{% load bootstrap %} +{% load i18n %} +{% load sekizai_tags %} + +{% block label_edit_content %} + +{% include "_modal_add_label.html" %} + + +{% if action == "labeling" %} + {% if form.instance.type == "tx" %} + + + +
+
+

Inputs

+ + {% for vin in res_tx.vin %} + +
+
+ +
+

+ New "input" Label + + {{ vin.txid|slice:"0:12" }}…{{ vin.txid|slice:"-"|slice:"-12:" }}:{{ vin.vout }} + {{ vin.txid|slice:"0:4" }}…{{ vin.txid|slice:"-"|slice:"-4:" }}:{{ vin.vout }} + {{ vin.txid|slice:"0:12" }}…{{ vin.txid|slice:"-"|slice:"-6:" }}:{{ vin.vout }} +
+ {{ vin.prevout.value }} sats + +

+
+
+ +
+ +
+
+ + {% endfor %} +
+ +
+ + + + +
+ + +
+

Transaction

+ {% if res_tx.status.confirmed %}confirmed{% else %}unconfirmed{% endif %} +
+ +
+ +
+
Transaction ID
+
+

{{ form.instance.ref }}

+ + New "tx" Label +
+ {% if  res_tx.status.block_height %} + +
+
Block Height
+ {# {{ res_tx.status.block_time }} #} +
+

{{  res_tx.status.block_height }}

+ {{ res_tx.status.block_time }} +
+ {% endif %} +
+ + + + + +
+ +
+

Outputs

+ + + {% for vout in res_tx.vout %} + + + +
+
+
Output #{{ forloop.counter }}
+

{{ form.instance.ref }}:{{ forloop.counter0 }}

+

{{ vout.scriptpubkey_address }}

+

{{ vout.value }} sats

+ New "addr" Label + New "output" Label + + + +
+ +
+
+ + + {% endfor %} +
+
+ + + + {% endif %} +{% endif %} +{% endblock %} diff --git a/django/templates/label_edit_output_details.html b/django/templates/label_edit_output_details.html new file mode 100644 index 0000000..e09e21b --- /dev/null +++ b/django/templates/label_edit_output_details.html @@ -0,0 +1,22 @@ +{% extends "label_edit.html" %} +{% load bootstrap %} +{% load i18n %} + + +{% block label_edit_content %} + +{% if action == "output-details" %} + {% if form.instance.type == "output" %} +
+
+    Output, ref:  {{ label.ref }}
+    Output value, in sats: {{ output.value }}
+    Confirmed at block height: {{ output.confirmed_at_block_height }}
+    Confirmed at block time: {{ output.confirmed_at_block_time }}
+    Network: {{ output.get_network_display }}
+  
+ {% endif %} +{% endif %} +{% endblock %} diff --git a/django/templates/profile.html b/django/templates/profile.html index 45eca1a..72c511e 100644 --- a/django/templates/profile.html +++ b/django/templates/profile.html @@ -19,8 +19,8 @@ - Fiat Finances - Enable or disable fiat currency parsing and its associated functions. + Fiat Finances + Enable or disable fiat currency parsing and its associated functions.
@@ -28,8 +28,8 @@ - Hashtags - Enable or disable hashtag parsing and its associated functions. + Hashtags + Enable or disable hashtag parsing and its associated functions.
@@ -37,8 +37,8 @@ - Tree Map - Enable or disable Tree Map. + Tree Map + Enable or disable Tree Map.
@@ -52,8 +52,8 @@ - - + +
SentryEnable or disable anonymized error tracking.SentryEnable or disable anonymized error tracking.
@@ -68,8 +68,8 @@ - - +
Update spent Outputs + Update spent Outputs Check and update all unspent outputs using Electrum. diff --git a/docker-compose.yml b/docker-compose.yml index f6ffab8..548dc3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,34 +1,22 @@ version: "3.7" -#x-common-variables: &common-variables -# MYSQL_ROOT_PASSWORD: -# MYSQL_DATABASE: labelbase -# MYSQL_USER: ulabelbase -# MYSQL_PASSWORD: - - services: labelbase_mysql: build: context: ./mysql stop_grace_period: 1m restart: always - #secrets: - # - mysql_root_password - # - mysql_user_password environment: - MYSQL_DATABASE=labelbase - MYSQL_USER=ulabelbase - - MYSQL_ROOT_PASSWORD=10almm6a62ec3z8jm4jjw6dny5 - - MYSQL_PASSWORD=10almm6a62ec3z8jm4jjw6dny5 - #- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password - #- MYSQL_PASSWORD_FILE=/run/secrets/mysql_user_password + - MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD + - MYSQL_PASSWORD=$MYSQL_PASSWORD ports: - "3306:3306" volumes: - db_data:/var/lib/mysql - db_data:/run/mysqld - - db_data:/run/secrets + #- db_data:/run/secrets networks: - compose_network labelbase_django: @@ -42,22 +30,18 @@ services: - db_data:/var/lib/mysql - db_data:/run/mysqld - web_static:/app/static/ - - db_data:/run/secrets + #- db_data:/run/secrets depends_on: - labelbase_mysql restart: always networks: - compose_network environment: - - DB_PASSWORD=${DB_PASSWORD} +# - DB_PASSWORD=${DB_PASSWORD} - MYSQL_USER=ulabelbase - MYSQL_DATABASE=labelbase - - MYSQL_ROOT_PASSWORD=10almm6a62ec3z8jm4jjw6dny5 - - MYSQL_PASSWORD=10almm6a62ec3z8jm4jjw6dny5 - #- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql_root_password - #- MYSQL_PASSWORD_FILE=/run/secrets/mysql_user_password - #secrets: - # - mysql_user_password + - MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD + - MYSQL_PASSWORD=$MYSQL_PASSWORD command: /app/run.sh labelbase_nginx: build: @@ -78,11 +62,5 @@ volumes: tmp: web_static: -#secrets: -# mysql_root_password: -# file: ./mysql_root_password.txt -# mysql_user_password: -# file: ./mysql_user_password.txt - networks: compose_network: diff --git a/mysql/init.sql b/mysql/init.sql index 7d4289c..c1bb8e9 100644 --- a/mysql/init.sql +++ b/mysql/init.sql @@ -7,7 +7,7 @@ CREATE DATABASE IF NOT EXISTS labelbase; USE labelbase; -- Create the user -CREATE USER 'ulabelbase'@'%' IDENTIFIED BY '10almm6a62ec3z8jm4jjw6dny5'; +CREATE USER 'ulabelbase'@'%' IDENTIFIED BY '$MYSQL_PASSWORD'; -- Grant privileges to the user GRANT ALL PRIVILEGES ON labelbase.* TO 'ulabelbase'@'%';