This commit is contained in:
Xavier Fiechter 2024-03-04 12:07:29 +01:00
parent 695cd5ba33
commit 653fb3d47b
11 changed files with 285 additions and 84 deletions

3
.gitignore vendored
View file

@ -7,4 +7,5 @@ db/
*.pyc
__pycache__
django/importer/uploadeddata/*
_scratches
#_scratches
exports.sh

View file

@ -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'] = {

View file

@ -107,7 +107,7 @@ INSTALLED_APPS = [
"importer",
"finances",
"background_task",
"connectrum",
"connectrum",
]

View file

@ -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)

View file

@ -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);
}
});
});
</script>
</body>

View file

@ -38,6 +38,9 @@
</li>
-->{% endcomment %}
{% case "output" %}
<li class="nav-item">
<a class="nav-link {% if action == "output-details" %}active" aria-current="page" {% else %}"{% endif %} href="{% url 'edit_label' label.id %}output-details/">Output Details</a>
</li>
{% comment %}<!--
@ -63,12 +66,10 @@
</li>
-->{% endcomment %}
{% case "addr" %}
{% comment %}<!--
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Coin Value</a>
</li>
-->{% endcomment %}
{% endswitch %}

View file

@ -0,0 +1,191 @@
{% extends "label_edit.html" %}
{% load bootstrap %}
{% load i18n %}
{% load sekizai_tags %}
{% block label_edit_content %}
{% include "_modal_add_label.html" %}
<!--
{{  res_tx|safe }}
-->
{% if action == "labeling" %}
{% if form.instance.type == "tx" %}
<style>
.connector button {
min-width: 10rem;
}
.connector {
margin-bottom: 0.5rem;
/* height: 2.5rem;
border-bottom: 2px solid #ccc; */
position: relative;
}
.connector-float-left {
float: left;
}
.connector-float-right {
float: right;
}
</style>
<div class="row" style="padding-top: 1rem; padding-bottom: 1rem;">
<div class="col-md-4">
<h4 class="mb-4">Inputs</h4>
{% for vin in res_tx.vin %}
<div class="card text-center" style="border-right:0;">
<div class="card-body">
<div class="connector ">
<p>
<a href="javascript:void(0);" class="btn btn-outline-primary btn-sm connector-float-right open-modal"
data-label=""
data-type="input"
data-ref="{{ vin.txid }}:{{ vin.vout }}">New "input" Label</a>
<span class="connector-float-left d-block d-md-none">{{ vin.txid|slice:"0:12" }}…{{ vin.txid|slice:"-"|slice:"-12:" }}:{{ vin.vout }}</span>
<span class="connector-float-left d-none d-md-block d-lg-none">{{ vin.txid|slice:"0:4" }}…{{ vin.txid|slice:"-"|slice:"-4:" }}:{{ vin.vout }} </span>
<span class="connector-float-left d-none d-lg-block">{{ vin.txid|slice:"0:12" }}…{{ vin.txid|slice:"-"|slice:"-6:" }}:{{ vin.vout }}</span>
<br>
<small><i>{{ vin.prevout.value }} sats</i></small>
</p>
<hr>
</div>
</div>
<!--div class="card-footer text-body-secondary">
2 days ago
</div-->
</div>
<br>
{% endfor %}
</div>
<div class="col-md-4">
<div class="list-group">
<span class="list-group-item " style="background-color:whitesmoke;" >
<div class="d-flex w-100 justify-content-between">
<h4 class="mb-1">Transaction</h4>
<small class="text-body-secondary">{% if res_tx.status.confirmed %}confirmed{% else %}unconfirmed{% endif %}</small>
</div>
</span>
<span class="list-group-item ">
<div class="d-flex w-100 justify-content-between ">
<h6 class="mb-1">Transaction ID</h6>
</div>
<p class="mb-1" style="word-break: break-word;"> {{ form.instance.ref }}</p>
<small class="text-body-secondary"></small>
<a href="javascript:void(0);" class="btn btn-outline-primary btn-sm connector-float-right open-modal"
data-label=""
data-type="tx"
data-ref="{{ form.instance.ref }}">New "tx" Label</a>
</span>
{% if  res_tx.status.block_height %}
<span class="list-group-item ">
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1">Block Height</h6>
{# <small><!--3 days ago-->{{ res_tx.status.block_time }}</small> #}
</div>
<p class="mb-1">{{  res_tx.status.block_height }}</p>
<small class="text-body-secondary">{{ res_tx.status.block_time }}</small>
</span>
{% endif %}
</div>
</div>
<div class="col-md-4">
<h4 class="mb-4">Outputs</h4>
{% for vout in res_tx.vout %}
<div class="card text-center" style="border-left:0;">
<div class="card-body">
<h5 class="card-title">Output #{{ forloop.counter }}</h5>
<p class="card-text">{{ form.instance.ref }}:{{ forloop.counter0 }}</p>
<p class="card-text">{{ vout.scriptpubkey_address }}</p>
<p class="card-text">{{ vout.value }} sats</p>
<a href="javascript:void(0);" class="btn btn-outline-primary btn-sm open-modal"
data-label=""
data-type="addr"
data-ref="{{ vout.scriptpubkey_address }}">New "addr" Label</a>
<a href="javascript:void(0);" class="btn btn-outline-primary btn-sm open-modal"
data-label=""
data-type="output"
data-ref="{{ form.instance.ref }}:{{ forloop.counter0 }}">New "output" Label</a>
</div>
<!--div class="card-footer text-body-secondary">
2 days ago
</div-->
</div>
<br>
<div class="connector" style="display:none">
<p>
<span class="connector-float-left d-block d-md-none">{{ vout.scriptpubkey_address|slice:"0:12" }}…{{ vout.scriptpubkey_address|slice:"-"|slice:"-12:" }}</span>
<span class="connector-float-left d-none d-md-block d-lg-none">{{ vout.scriptpubkey_address|slice:"0:4" }}…{{ vout.scriptpubkey_address|slice:"-"|slice:"-4:" }}</span>
<span class="connector-float-left d-none d-lg-block">{{ vout.scriptpubkey_address|slice:"0:12" }}…{{ vout.scriptpubkey_address|slice:"-"|slice:"-6:" }}</span>
<button class="btn btn-outline-primary btn-sm connector-float-right">New "addr" Label</button>
<br>
<br>
<span class="connector-float-left d-block d-md-none">{{ form.instance.ref|slice:"0:12" }}…{{ form.instance.ref|slice:"-"|slice:"-12:" }}:{{ forloop.counter0 }} <small><i>#{{ forloop.counter }}</i></small></span>
<span class="connector-float-left d-none d-md-block d-lg-none">{{ form.instance.ref|slice:"0:4" }}…{{ form.instance.ref|slice:"-"|slice:"-4:" }}:{{ forloop.counter0 }} <small><i>#{{ forloop.counter }}</i></small></span>
<span class="connector-float-left d-none d-lg-block">{{ form.instance.ref|slice:"0:12" }}…{{ form.instance.ref|slice:"-"|slice:"-6:" }}:{{ forloop.counter0 }} <small><i>#{{ forloop.counter }}</i></small></span>
<button class="btn btn-outline-primary btn-sm connector-float-right">New "output" Label</button>
<br>
<small><i>{{ vout.value }} sats</i></small>
</p>
<hr>
</div>
{% endfor %}
</div>
</div>
<script>
{% addtoblock "js" %}
$(document).ready(function() {
$('.open-modal').click(function() {
var label = $(this).data('label');
var type = $(this).data('type');
var ref = $(this).data('ref');
$('#id_label').val(label);
$('#id_type').val(type);
$('#id_ref').val(ref);
$('#addLabelModal').modal('show');
$('#id_type').change() // update readonly fields based on type
});
});
{% endaddtoblock %}
</script>
{% endif %}
{% endif %}
{% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "label_edit.html" %}
{% load bootstrap %}
{% load i18n %}
{% block label_edit_content %}
<!--
{{  res_tx|safe }}
-->
{% if action == "output-details" %}
{% if form.instance.type == "output" %}
<br>
<pre>
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 }}
</pre>
{% endif %}
{% endif %}
{% endblock %}

View file

@ -19,8 +19,8 @@
<tbody>
<tr >
<td style="width:15%;"><b>Fiat Finances</b></td>
<td style="width:80%;"><small>Enable or disable fiat currency parsing and its associated functions.</small></td>
<td style="width:21%;"><b>Fiat Finances</b></td>
<td style="width:75%;"><small>Enable or disable fiat currency parsing and its associated functions.</small></td>
<td>
<div class="form-check form-switch">
<input class="form-check-input user-setting" type="checkbox" {% if request.user.profile.use_fiatfinances %}checked="checked"{% endif %} id="use_fiatfinances">
@ -28,8 +28,8 @@
</td>
</tr>
<tr >
<td style="width:15%;"><b>Hashtags</b></td>
<td style="width:80%;"><small>Enable or disable hashtag parsing and its associated functions.</small></td>
<td style="width:21%;"><b>Hashtags</b></td>
<td style="width:75%;"><small>Enable or disable hashtag parsing and its associated functions.</small></td>
<td>
<div class="form-check form-switch">
<input class="form-check-input user-setting" type="checkbox" {% if request.user.profile.use_hashtags %}checked="checked"{% endif %} id="use_hashtags">
@ -37,8 +37,8 @@
</td>
</tr>
<tr >
<td style="width:15%;"><b>Tree Map</b></td>
<td style="width:80%;"><small>Enable or disable Tree Map.</small></td>
<td style="width:21%;"><b>Tree Map</b></td>
<td style="width:75%;"><small>Enable or disable Tree Map.</small></td>
<td>
<div class="form-check form-switch">
<input class="form-check-input user-setting" type="checkbox" {% if request.user.profile.use_treemap %}checked="checked"{% endif %} id="use_treemap">
@ -52,8 +52,8 @@
<table class="table">
<tbody>
<tr>
<td style="width:15%;"<b>Sentry</b></td>
<td style="width:80%;"<small>Enable or disable anonymized error tracking.</small></td>
<td style="width:21%;"><b>Sentry</b></td>
<td style="width:75%;"><small>Enable or disable anonymized error tracking.</small></td>
<td>
<div class="form-check form-switch">
<input class="form-check-input user-setting" type="checkbox" {% if request.user.profile.use_sentry %}checked="checked"{% endif %} id="use_sentry">
@ -68,8 +68,8 @@
<table class="table">
<tbody>
<tr>
<td><b>Update spent Outputs</b></td>
<td>
<td style="width:21%;"><b>Update spent Outputs</b></td>
<td style="width:75%;">
<small>Check and update all unspent outputs using <a href="/account/userprofile-electrum/">Electrum</a>.</small></td>
<td>
<td>

View file

@ -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:

View file

@ -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'@'%';