diff --git a/README.md b/README.md index 725355a..0073736 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ The extension creates several tables: ├── config.json # Extension configuration ├── manifest.json # Extension manifest ├── templates/ -│ └── satmachineadmin/ +│ └── satmachineclient/ │ └── index.html # Main UI template └── static/ └── js/ diff --git a/__init__.py b/__init__.py index 8c16954..147ed62 100644 --- a/__init__.py +++ b/__init__.py @@ -6,30 +6,30 @@ from loguru import logger from .crud import db from .tasks import wait_for_paid_invoices, hourly_transaction_polling -from .views import satmachineadmin_generic_router -from .views_api import satmachineadmin_api_router +from .views import satmachineclient_generic_router +from .views_api import satmachineclient_api_router logger.debug( - "This logged message is from satmachineadmin/__init__.py, you can debug in your " + "This logged message is from satmachineclient/__init__.py, you can debug in your " "extension using 'import logger from loguru' and 'logger.debug()'." ) -satmachineadmin_ext: APIRouter = APIRouter(prefix="/satmachineadmin", tags=["DCA Admin"]) -satmachineadmin_ext.include_router(satmachineadmin_generic_router) -satmachineadmin_ext.include_router(satmachineadmin_api_router) +satmachineclient_ext: APIRouter = APIRouter(prefix="/satmachineclient", tags=["DCA Admin"]) +satmachineclient_ext.include_router(satmachineclient_generic_router) +satmachineclient_ext.include_router(satmachineclient_api_router) -satmachineadmin_static_files = [ +satmachineclient_static_files = [ { - "path": "/satmachineadmin/static", - "name": "satmachineadmin_static", + "path": "/satmachineclient/static", + "name": "satmachineclient_static", } ] scheduled_tasks: list[asyncio.Task] = [] -def satmachineadmin_stop(): +def satmachineclient_stop(): for task in scheduled_tasks: try: task.cancel() @@ -37,20 +37,20 @@ def satmachineadmin_stop(): logger.warning(ex) -def satmachineadmin_start(): +def satmachineclient_start(): # Start invoice listener task - invoice_task = create_permanent_unique_task("ext_satmachineadmin", wait_for_paid_invoices) + invoice_task = create_permanent_unique_task("ext_satmachineclient", wait_for_paid_invoices) scheduled_tasks.append(invoice_task) # Start hourly transaction polling task - polling_task = create_permanent_unique_task("ext_satmachineadmin_polling", hourly_transaction_polling) + polling_task = create_permanent_unique_task("ext_satmachineclient_polling", hourly_transaction_polling) scheduled_tasks.append(polling_task) __all__ = [ "db", - "satmachineadmin_ext", - "satmachineadmin_static_files", - "satmachineadmin_start", - "satmachineadmin_stop", + "satmachineclient_ext", + "satmachineclient_static_files", + "satmachineclient_start", + "satmachineclient_stop", ] diff --git a/config.json b/config.json index 8c1f39e..b709fe6 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "name": "DCA Admin", "short_description": "Dollar Cost Averaging administration for Lamassu ATM integration", - "tile": "/satmachineadmin/static/image/aio.png", + "tile": "/satmachineclient/static/image/aio.png", "min_lnbits_version": "1.0.0", "contributors": [ { @@ -26,7 +26,7 @@ } ], "images": [], - "description_md": "/satmachineadmin/description.md", - "terms_and_conditions_md": "/satmachineadmin/toc.md", + "description_md": "/satmachineclient/description.md", + "terms_and_conditions_md": "/satmachineclient/toc.md", "license": "MIT" } diff --git a/crud.py b/crud.py index 27781a6..8ab9d16 100644 --- a/crud.py +++ b/crud.py @@ -15,7 +15,7 @@ from .models import ( CreateLamassuTransactionData, StoredLamassuTransaction ) -db = Database("ext_satmachineadmin") +db = Database("ext_satmachineclient") # DCA Client CRUD Operations @@ -23,7 +23,7 @@ async def create_dca_client(data: CreateDcaClientData) -> DcaClient: client_id = urlsafe_short_hash() await db.execute( """ - INSERT INTO satmachineadmin.dca_clients + INSERT INTO satmachineclient.dca_clients (id, user_id, wallet_id, username, dca_mode, fixed_mode_daily_limit, status, created_at, updated_at) VALUES (:id, :user_id, :wallet_id, :username, :dca_mode, :fixed_mode_daily_limit, :status, :created_at, :updated_at) """, @@ -44,7 +44,7 @@ async def create_dca_client(data: CreateDcaClientData) -> DcaClient: async def get_dca_client(client_id: str) -> Optional[DcaClient]: return await db.fetchone( - "SELECT * FROM satmachineadmin.dca_clients WHERE id = :id", + "SELECT * FROM satmachineclient.dca_clients WHERE id = :id", {"id": client_id}, DcaClient, ) @@ -52,14 +52,14 @@ async def get_dca_client(client_id: str) -> Optional[DcaClient]: async def get_dca_clients() -> List[DcaClient]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_clients ORDER BY created_at DESC", + "SELECT * FROM satmachineclient.dca_clients ORDER BY created_at DESC", model=DcaClient, ) async def get_dca_client_by_user(user_id: str) -> Optional[DcaClient]: return await db.fetchone( - "SELECT * FROM satmachineadmin.dca_clients WHERE user_id = :user_id", + "SELECT * FROM satmachineclient.dca_clients WHERE user_id = :user_id", {"user_id": user_id}, DcaClient, ) @@ -75,7 +75,7 @@ async def update_dca_client(client_id: str, data: UpdateDcaClientData) -> Option update_data["id"] = client_id await db.execute( - f"UPDATE satmachineadmin.dca_clients SET {set_clause} WHERE id = :id", + f"UPDATE satmachineclient.dca_clients SET {set_clause} WHERE id = :id", update_data ) return await get_dca_client(client_id) @@ -83,7 +83,7 @@ async def update_dca_client(client_id: str, data: UpdateDcaClientData) -> Option async def delete_dca_client(client_id: str) -> None: await db.execute( - "DELETE FROM satmachineadmin.dca_clients WHERE id = :id", + "DELETE FROM satmachineclient.dca_clients WHERE id = :id", {"id": client_id} ) @@ -93,7 +93,7 @@ async def create_deposit(data: CreateDepositData) -> DcaDeposit: deposit_id = urlsafe_short_hash() await db.execute( """ - INSERT INTO satmachineadmin.dca_deposits + INSERT INTO satmachineclient.dca_deposits (id, client_id, amount, currency, status, notes, created_at) VALUES (:id, :client_id, :amount, :currency, :status, :notes, :created_at) """, @@ -112,7 +112,7 @@ async def create_deposit(data: CreateDepositData) -> DcaDeposit: async def get_deposit(deposit_id: str) -> Optional[DcaDeposit]: return await db.fetchone( - "SELECT * FROM satmachineadmin.dca_deposits WHERE id = :id", + "SELECT * FROM satmachineclient.dca_deposits WHERE id = :id", {"id": deposit_id}, DcaDeposit, ) @@ -120,7 +120,7 @@ async def get_deposit(deposit_id: str) -> Optional[DcaDeposit]: async def get_deposits_by_client(client_id: str) -> List[DcaDeposit]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_deposits WHERE client_id = :client_id ORDER BY created_at DESC", + "SELECT * FROM satmachineclient.dca_deposits WHERE client_id = :client_id ORDER BY created_at DESC", {"client_id": client_id}, DcaDeposit, ) @@ -128,7 +128,7 @@ async def get_deposits_by_client(client_id: str) -> List[DcaDeposit]: async def get_all_deposits() -> List[DcaDeposit]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_deposits ORDER BY created_at DESC", + "SELECT * FROM satmachineclient.dca_deposits ORDER BY created_at DESC", model=DcaDeposit, ) @@ -147,7 +147,7 @@ async def update_deposit_status(deposit_id: str, data: UpdateDepositStatusData) filtered_data["id"] = deposit_id await db.execute( - f"UPDATE satmachineadmin.dca_deposits SET {set_clause} WHERE id = :id", + f"UPDATE satmachineclient.dca_deposits SET {set_clause} WHERE id = :id", filtered_data ) return await get_deposit(deposit_id) @@ -158,7 +158,7 @@ async def create_dca_payment(data: CreateDcaPaymentData) -> DcaPayment: payment_id = urlsafe_short_hash() await db.execute( """ - INSERT INTO satmachineadmin.dca_payments + INSERT INTO satmachineclient.dca_payments (id, client_id, amount_sats, amount_fiat, exchange_rate, transaction_type, lamassu_transaction_id, payment_hash, status, created_at) VALUES (:id, :client_id, :amount_sats, :amount_fiat, :exchange_rate, :transaction_type, @@ -182,7 +182,7 @@ async def create_dca_payment(data: CreateDcaPaymentData) -> DcaPayment: async def get_dca_payment(payment_id: str) -> Optional[DcaPayment]: return await db.fetchone( - "SELECT * FROM satmachineadmin.dca_payments WHERE id = :id", + "SELECT * FROM satmachineclient.dca_payments WHERE id = :id", {"id": payment_id}, DcaPayment, ) @@ -190,7 +190,7 @@ async def get_dca_payment(payment_id: str) -> Optional[DcaPayment]: async def get_payments_by_client(client_id: str) -> List[DcaPayment]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_payments WHERE client_id = :client_id ORDER BY created_at DESC", + "SELECT * FROM satmachineclient.dca_payments WHERE client_id = :client_id ORDER BY created_at DESC", {"client_id": client_id}, DcaPayment, ) @@ -198,7 +198,7 @@ async def get_payments_by_client(client_id: str) -> List[DcaPayment]: async def get_all_payments() -> List[DcaPayment]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_payments ORDER BY created_at DESC", + "SELECT * FROM satmachineclient.dca_payments ORDER BY created_at DESC", model=DcaPayment, ) @@ -206,14 +206,14 @@ async def get_all_payments() -> List[DcaPayment]: async def update_dca_payment_status(payment_id: str, status: str) -> None: """Update the status of a DCA payment""" await db.execute( - "UPDATE satmachineadmin.dca_payments SET status = :status WHERE id = :id", + "UPDATE satmachineclient.dca_payments SET status = :status WHERE id = :id", {"status": status, "id": payment_id} ) async def get_payments_by_lamassu_transaction(lamassu_transaction_id: str) -> List[DcaPayment]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_payments WHERE lamassu_transaction_id = :transaction_id", + "SELECT * FROM satmachineclient.dca_payments WHERE lamassu_transaction_id = :transaction_id", {"transaction_id": lamassu_transaction_id}, DcaPayment, ) @@ -225,7 +225,7 @@ async def get_client_balance_summary(client_id: str) -> ClientBalanceSummary: total_deposits_result = await db.fetchone( """ SELECT COALESCE(SUM(amount), 0) as total, currency - FROM satmachineadmin.dca_deposits + FROM satmachineclient.dca_deposits WHERE client_id = :client_id AND status = 'confirmed' GROUP BY currency """, @@ -236,7 +236,7 @@ async def get_client_balance_summary(client_id: str) -> ClientBalanceSummary: total_payments_result = await db.fetchone( """ SELECT COALESCE(SUM(amount_fiat), 0) as total - FROM satmachineadmin.dca_payments + FROM satmachineclient.dca_payments WHERE client_id = :client_id AND status = 'confirmed' """, {"client_id": client_id} @@ -257,14 +257,14 @@ async def get_client_balance_summary(client_id: str) -> ClientBalanceSummary: async def get_flow_mode_clients() -> List[DcaClient]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_clients WHERE dca_mode = 'flow' AND status = 'active'", + "SELECT * FROM satmachineclient.dca_clients WHERE dca_mode = 'flow' AND status = 'active'", model=DcaClient, ) async def get_fixed_mode_clients() -> List[DcaClient]: return await db.fetchall( - "SELECT * FROM satmachineadmin.dca_clients WHERE dca_mode = 'fixed' AND status = 'active'", + "SELECT * FROM satmachineclient.dca_clients WHERE dca_mode = 'fixed' AND status = 'active'", model=DcaClient, ) @@ -275,13 +275,13 @@ async def create_lamassu_config(data: CreateLamassuConfigData) -> LamassuConfig: # Deactivate any existing configs first (only one active config allowed) await db.execute( - "UPDATE satmachineadmin.lamassu_config SET is_active = false, updated_at = :updated_at", + "UPDATE satmachineclient.lamassu_config SET is_active = false, updated_at = :updated_at", {"updated_at": datetime.now()} ) await db.execute( """ - INSERT INTO satmachineadmin.lamassu_config + INSERT INTO satmachineclient.lamassu_config (id, host, port, database_name, username, password, source_wallet_id, commission_wallet_id, is_active, created_at, updated_at, use_ssh_tunnel, ssh_host, ssh_port, ssh_username, ssh_password, ssh_private_key) VALUES (:id, :host, :port, :database_name, :username, :password, :source_wallet_id, :commission_wallet_id, :is_active, :created_at, :updated_at, @@ -312,7 +312,7 @@ async def create_lamassu_config(data: CreateLamassuConfigData) -> LamassuConfig: async def get_lamassu_config(config_id: str) -> Optional[LamassuConfig]: return await db.fetchone( - "SELECT * FROM satmachineadmin.lamassu_config WHERE id = :id", + "SELECT * FROM satmachineclient.lamassu_config WHERE id = :id", {"id": config_id}, LamassuConfig, ) @@ -320,14 +320,14 @@ async def get_lamassu_config(config_id: str) -> Optional[LamassuConfig]: async def get_active_lamassu_config() -> Optional[LamassuConfig]: return await db.fetchone( - "SELECT * FROM satmachineadmin.lamassu_config WHERE is_active = true ORDER BY created_at DESC LIMIT 1", + "SELECT * FROM satmachineclient.lamassu_config WHERE is_active = true ORDER BY created_at DESC LIMIT 1", model=LamassuConfig, ) async def get_all_lamassu_configs() -> List[LamassuConfig]: return await db.fetchall( - "SELECT * FROM satmachineadmin.lamassu_config ORDER BY created_at DESC", + "SELECT * FROM satmachineclient.lamassu_config ORDER BY created_at DESC", model=LamassuConfig, ) @@ -342,7 +342,7 @@ async def update_lamassu_config(config_id: str, data: UpdateLamassuConfigData) - update_data["id"] = config_id await db.execute( - f"UPDATE satmachineadmin.lamassu_config SET {set_clause} WHERE id = :id", + f"UPDATE satmachineclient.lamassu_config SET {set_clause} WHERE id = :id", update_data ) return await get_lamassu_config(config_id) @@ -352,7 +352,7 @@ async def update_config_test_result(config_id: str, success: bool) -> None: utc_now = datetime.now(timezone.utc) await db.execute( """ - UPDATE satmachineadmin.lamassu_config + UPDATE satmachineclient.lamassu_config SET test_connection_last = :test_time, test_connection_success = :success, updated_at = :updated_at WHERE id = :id """, @@ -367,7 +367,7 @@ async def update_config_test_result(config_id: str, success: bool) -> None: async def delete_lamassu_config(config_id: str) -> None: await db.execute( - "DELETE FROM satmachineadmin.lamassu_config WHERE id = :id", + "DELETE FROM satmachineclient.lamassu_config WHERE id = :id", {"id": config_id} ) @@ -377,7 +377,7 @@ async def update_poll_start_time(config_id: str) -> None: utc_now = datetime.now(timezone.utc) await db.execute( """ - UPDATE satmachineadmin.lamassu_config + UPDATE satmachineclient.lamassu_config SET last_poll_time = :poll_time, updated_at = :updated_at WHERE id = :id """, @@ -394,7 +394,7 @@ async def update_poll_success_time(config_id: str) -> None: utc_now = datetime.now(timezone.utc) await db.execute( """ - UPDATE satmachineadmin.lamassu_config + UPDATE satmachineclient.lamassu_config SET last_successful_poll = :poll_time, updated_at = :updated_at WHERE id = :id """, @@ -412,7 +412,7 @@ async def create_lamassu_transaction(data: CreateLamassuTransactionData) -> Stor transaction_id = urlsafe_short_hash() await db.execute( """ - INSERT INTO satmachineadmin.lamassu_transactions + INSERT INTO satmachineclient.lamassu_transactions (id, lamassu_transaction_id, fiat_amount, crypto_amount, commission_percentage, discount, effective_commission, commission_amount_sats, base_amount_sats, exchange_rate, crypto_code, fiat_code, device_id, transaction_time, processed_at, @@ -448,7 +448,7 @@ async def create_lamassu_transaction(data: CreateLamassuTransactionData) -> Stor async def get_lamassu_transaction(transaction_id: str) -> Optional[StoredLamassuTransaction]: """Get a stored Lamassu transaction by ID""" return await db.fetchone( - "SELECT * FROM satmachineadmin.lamassu_transactions WHERE id = :id", + "SELECT * FROM satmachineclient.lamassu_transactions WHERE id = :id", {"id": transaction_id}, StoredLamassuTransaction, ) @@ -457,7 +457,7 @@ async def get_lamassu_transaction(transaction_id: str) -> Optional[StoredLamassu async def get_lamassu_transaction_by_lamassu_id(lamassu_transaction_id: str) -> Optional[StoredLamassuTransaction]: """Get a stored Lamassu transaction by Lamassu transaction ID""" return await db.fetchone( - "SELECT * FROM satmachineadmin.lamassu_transactions WHERE lamassu_transaction_id = :lamassu_id", + "SELECT * FROM satmachineclient.lamassu_transactions WHERE lamassu_transaction_id = :lamassu_id", {"lamassu_id": lamassu_transaction_id}, StoredLamassuTransaction, ) @@ -466,7 +466,7 @@ async def get_lamassu_transaction_by_lamassu_id(lamassu_transaction_id: str) -> async def get_all_lamassu_transactions() -> List[StoredLamassuTransaction]: """Get all stored Lamassu transactions""" return await db.fetchall( - "SELECT * FROM satmachineadmin.lamassu_transactions ORDER BY transaction_time DESC", + "SELECT * FROM satmachineclient.lamassu_transactions ORDER BY transaction_time DESC", model=StoredLamassuTransaction, ) @@ -479,7 +479,7 @@ async def update_lamassu_transaction_distribution_stats( """Update distribution statistics for a Lamassu transaction""" await db.execute( """ - UPDATE satmachineadmin.lamassu_transactions + UPDATE satmachineclient.lamassu_transactions SET clients_count = :clients_count, distributions_total_sats = :distributions_total_sats WHERE id = :id """, diff --git a/description.md b/description.md index a748691..edbc976 100644 --- a/description.md +++ b/description.md @@ -1,4 +1,4 @@ -SatMachineAdmin can be used as a template for building new extensions, it includes a bunch of functions that can be edited/deleted as you need them. +SatMachineClient can be used as a template for building new extensions, it includes a bunch of functions that can be edited/deleted as you need them. This is a longform description that will be used in the advanced description when users click on the "more" button on the extension cards. diff --git a/migrations.py b/migrations.py index 0e1cafa..0251de1 100644 --- a/migrations.py +++ b/migrations.py @@ -10,7 +10,7 @@ async def m001_initial_dca_schema(db): # DCA Clients table await db.execute( f""" - CREATE TABLE satmachineadmin.dca_clients ( + CREATE TABLE satmachineclient.dca_clients ( id TEXT PRIMARY KEY NOT NULL, user_id TEXT NOT NULL, wallet_id TEXT NOT NULL, @@ -27,7 +27,7 @@ async def m001_initial_dca_schema(db): # DCA Deposits table await db.execute( f""" - CREATE TABLE satmachineadmin.dca_deposits ( + CREATE TABLE satmachineclient.dca_deposits ( id TEXT PRIMARY KEY NOT NULL, client_id TEXT NOT NULL, amount INTEGER NOT NULL, @@ -43,7 +43,7 @@ async def m001_initial_dca_schema(db): # DCA Payments table await db.execute( f""" - CREATE TABLE satmachineadmin.dca_payments ( + CREATE TABLE satmachineclient.dca_payments ( id TEXT PRIMARY KEY NOT NULL, client_id TEXT NOT NULL, amount_sats INTEGER NOT NULL, @@ -61,7 +61,7 @@ async def m001_initial_dca_schema(db): # Lamassu Configuration table await db.execute( f""" - CREATE TABLE satmachineadmin.lamassu_config ( + CREATE TABLE satmachineclient.lamassu_config ( id TEXT PRIMARY KEY NOT NULL, host TEXT NOT NULL, port INTEGER NOT NULL DEFAULT 5432, @@ -90,7 +90,7 @@ async def m001_initial_dca_schema(db): # Lamassu Transactions table (for audit trail) await db.execute( f""" - CREATE TABLE satmachineadmin.lamassu_transactions ( + CREATE TABLE satmachineclient.lamassu_transactions ( id TEXT PRIMARY KEY NOT NULL, lamassu_transaction_id TEXT NOT NULL UNIQUE, fiat_amount INTEGER NOT NULL, diff --git a/pyproject.toml b/pyproject.toml index c5c417d..4ddef8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [tool.poetry] -name = "satmachineadmin" -version = "0.0.0" -description = "Eightball is a simple API that allows you to create a random number generator." -authors = ["benarc", "dni "] +name = "Satoshi Machine Client" +version = "0.0.1" +description = "This acts as a dashboard for Satoshi Machine Lamassu ATM Liquidity Providers" +authors = ["padreug "] [tool.poetry.dependencies] python = "^3.10 | ^3.9" diff --git a/replaceStuff.sh b/replaceStuff.sh deleted file mode 100755 index 7ef780a..0000000 --- a/replaceStuff.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -# Usage: ./rename-plugin.sh oldname newname -# Example: ./rename-plugin.sh example mysuperplugin - -set -euo pipefail - -OLD_NAME="$1" -NEW_NAME="$2" - -# 1. Rename files with OLD_NAME in the filename -find . -type f -name "*${OLD_NAME}*" | while read -r file; do - dir=$(dirname "$file") - base=$(basename "$file") - new_base="${base//$OLD_NAME/$NEW_NAME}" - new_path="$dir/$new_base" - mv "$file" "$new_path" - echo "Renamed file: $file -> $new_path" -done - -# 2. Replace occurrences of OLD_NAME in file content -echo "Replacing content inside files..." -find . -type f -print0 | xargs -0 sed -i "s/${OLD_NAME}/${NEW_NAME}/g" - -# 3. Rename directories with OLD_NAME in the path (from deepest up) -echo "Renaming directories..." -find . -depth -type d -name "*${OLD_NAME}*" | while read -r dir; do - parent=$(dirname "$dir") - base=$(basename "$dir") - new_base="${base//$OLD_NAME/$NEW_NAME}" - new_path="$parent/$new_base" - mv "$dir" "$new_path" - echo "Renamed directory: $dir -> $new_path" -done - -echo "✅ All done." diff --git a/static/js/index.js b/static/js/index.js index c5d105b..9c5bc74 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -165,7 +165,7 @@ window.app = Vue.createApp({ try { const {data} = await LNbits.api.request( 'GET', - '/satmachineadmin/api/v1/dca/config', + '/satmachineclient/api/v1/dca/config', this.g.user.wallets[0].inkey ) this.lamassuConfig = data @@ -210,7 +210,7 @@ window.app = Vue.createApp({ const {data: config} = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/config', + '/satmachineclient/api/v1/dca/config', this.g.user.wallets[0].adminkey, data ) @@ -253,7 +253,7 @@ window.app = Vue.createApp({ try { const { data } = await LNbits.api.request( 'GET', - '/satmachineadmin/api/v1/dca/clients', + '/satmachineclient/api/v1/dca/clients', this.g.user.wallets[0].inkey ) @@ -263,7 +263,7 @@ window.app = Vue.createApp({ try { const { data: balance } = await LNbits.api.request( 'GET', - `/satmachineadmin/api/v1/dca/clients/${client.id}/balance`, + `/satmachineclient/api/v1/dca/clients/${client.id}/balance`, this.g.user.wallets[0].inkey ) return { @@ -298,7 +298,7 @@ window.app = Vue.createApp({ const { data: newClient } = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/clients', + '/satmachineclient/api/v1/dca/clients', this.g.user.wallets[0].adminkey, testData ) @@ -327,7 +327,7 @@ window.app = Vue.createApp({ const { data: newDeposit } = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/deposits', + '/satmachineclient/api/v1/dca/deposits', this.g.user.wallets[0].adminkey, data ) @@ -355,7 +355,7 @@ window.app = Vue.createApp({ try { const { data: balance } = await LNbits.api.request( 'GET', - `/satmachineadmin/api/v1/dca/clients/${client.id}/balance`, + `/satmachineclient/api/v1/dca/clients/${client.id}/balance`, this.g.user.wallets[0].inkey ) this.clientDetailsDialog.data = client @@ -371,7 +371,7 @@ window.app = Vue.createApp({ try { const { data } = await LNbits.api.request( 'GET', - '/satmachineadmin/api/v1/dca/deposits', + '/satmachineclient/api/v1/dca/deposits', this.g.user.wallets[0].inkey ) this.deposits = data @@ -402,7 +402,7 @@ window.app = Vue.createApp({ // Update existing deposit (mainly for notes/status) const { data: updatedDeposit } = await LNbits.api.request( 'PUT', - `/satmachineadmin/api/v1/dca/deposits/${this.depositFormDialog.data.id}`, + `/satmachineclient/api/v1/dca/deposits/${this.depositFormDialog.data.id}`, this.g.user.wallets[0].adminkey, { status: this.depositFormDialog.data.status, notes: data.notes } ) @@ -414,7 +414,7 @@ window.app = Vue.createApp({ // Create new deposit const { data: newDeposit } = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/deposits', + '/satmachineclient/api/v1/dca/deposits', this.g.user.wallets[0].adminkey, data ) @@ -446,7 +446,7 @@ window.app = Vue.createApp({ .onOk(async () => { const { data: updatedDeposit } = await LNbits.api.request( 'PUT', - `/satmachineadmin/api/v1/dca/deposits/${deposit.id}/status`, + `/satmachineclient/api/v1/dca/deposits/${deposit.id}/status`, this.g.user.wallets[0].adminkey, { status: 'confirmed', notes: 'Confirmed by admin - money placed in machine' } ) @@ -489,7 +489,7 @@ window.app = Vue.createApp({ try { const {data} = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/test-connection', + '/satmachineclient/api/v1/dca/test-connection', this.g.user.wallets[0].adminkey ) @@ -535,7 +535,7 @@ window.app = Vue.createApp({ try { const {data} = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/manual-poll', + '/satmachineclient/api/v1/dca/manual-poll', this.g.user.wallets[0].adminkey ) @@ -563,7 +563,7 @@ window.app = Vue.createApp({ try { const {data} = await LNbits.api.request( 'POST', - '/satmachineadmin/api/v1/dca/test-transaction', + '/satmachineclient/api/v1/dca/test-transaction', this.g.user.wallets[0].adminkey ) @@ -616,7 +616,7 @@ window.app = Vue.createApp({ try { const { data } = await LNbits.api.request( 'GET', - '/satmachineadmin/api/v1/dca/transactions', + '/satmachineclient/api/v1/dca/transactions', this.g.user.wallets[0].inkey ) this.lamassuTransactions = data @@ -629,7 +629,7 @@ window.app = Vue.createApp({ try { const { data: distributions } = await LNbits.api.request( 'GET', - `/satmachineadmin/api/v1/dca/transactions/${transaction.id}/distributions`, + `/satmachineclient/api/v1/dca/transactions/${transaction.id}/distributions`, this.g.user.wallets[0].inkey ) diff --git a/tasks.py b/tasks.py index 0ed9efe..0d2582e 100644 --- a/tasks.py +++ b/tasks.py @@ -18,7 +18,7 @@ from .transaction_processor import poll_lamassu_transactions async def wait_for_paid_invoices(): """Invoice listener for DCA-related payments""" invoice_queue = asyncio.Queue() - register_invoice_listener(invoice_queue, "ext_satmachineadmin") + register_invoice_listener(invoice_queue, "ext_satmachineclient") while True: payment = await invoice_queue.get() await on_invoice_paid(payment) diff --git a/templates/satmachineadmin/_api_docs.html b/templates/satmachineclient/_api_docs.html similarity index 90% rename from templates/satmachineadmin/_api_docs.html rename to templates/satmachineclient/_api_docs.html index e9c9d17..89e1d68 100644 --- a/templates/satmachineadmin/_api_docs.html +++ b/templates/satmachineclient/_api_docs.html @@ -4,5 +4,5 @@ label="API info" :content-inset-level="0.5" > - + diff --git a/templates/satmachineadmin/index.html b/templates/satmachineclient/index.html similarity index 99% rename from templates/satmachineadmin/index.html rename to templates/satmachineclient/index.html index 297407b..3dbe2e8 100644 --- a/templates/satmachineadmin/index.html +++ b/templates/satmachineclient/index.html @@ -4,7 +4,7 @@ {% extends "base.html" %} {% from "macros.jinja" import window_vars with context %} {% block scripts %} {{ window_vars(user) }} - + {% endblock %} {% block page %}
@@ -367,7 +367,7 @@ - {% include "satmachineadmin/_api_docs.html" %} + {% include "satmachineclient/_api_docs.html" %} diff --git a/tests/test_init.py b/tests/test_init.py index e2fc116..d97704b 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,11 +1,11 @@ import pytest from fastapi import APIRouter -from .. import satmachineadmin_ext +from .. import satmachineclient_ext # just import router and add it to a test router @pytest.mark.asyncio async def test_router(): router = APIRouter() - router.include_router(satmachineadmin_ext) + router.include_router(satmachineclient_ext) diff --git a/views.py b/views.py index 28b93c9..3d69653 100644 --- a/views.py +++ b/views.py @@ -6,16 +6,16 @@ from lnbits.core.models import User from lnbits.decorators import check_user_exists from lnbits.helpers import template_renderer -satmachineadmin_generic_router = APIRouter() +satmachineclient_generic_router = APIRouter() -def satmachineadmin_renderer(): - return template_renderer(["satmachineadmin/templates"]) +def satmachineclient_renderer(): + return template_renderer(["satmachineclient/templates"]) # DCA Admin page -@satmachineadmin_generic_router.get("/", response_class=HTMLResponse) +@satmachineclient_generic_router.get("/", response_class=HTMLResponse) async def index(req: Request, user: User = Depends(check_user_exists)): - return satmachineadmin_renderer().TemplateResponse( - "satmachineadmin/index.html", {"request": req, "user": user.json()} + return satmachineclient_renderer().TemplateResponse( + "satmachineclient/index.html", {"request": req, "user": user.json()} ) diff --git a/views_api.py b/views_api.py index 3225239..31b6473 100644 --- a/views_api.py +++ b/views_api.py @@ -43,7 +43,7 @@ from .models import ( StoredLamassuTransaction ) -satmachineadmin_api_router = APIRouter() +satmachineclient_api_router = APIRouter() ################################################### @@ -52,7 +52,7 @@ satmachineadmin_api_router = APIRouter() # DCA Client Endpoints -@satmachineadmin_api_router.get("/api/v1/dca/clients") +@satmachineclient_api_router.get("/api/v1/dca/clients") async def api_get_dca_clients( wallet: WalletTypeInfo = Depends(require_invoice_key), ) -> list[DcaClient]: @@ -60,7 +60,7 @@ async def api_get_dca_clients( return await get_dca_clients() -@satmachineadmin_api_router.get("/api/v1/dca/clients/{client_id}") +@satmachineclient_api_router.get("/api/v1/dca/clients/{client_id}") async def api_get_dca_client( client_id: str, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -78,7 +78,7 @@ async def api_get_dca_client( # Admin extension only reads existing clients and manages their deposits # TEMPORARY: Test client creation endpoint (remove in production) -@satmachineadmin_api_router.post("/api/v1/dca/clients", status_code=HTTPStatus.CREATED) +@satmachineclient_api_router.post("/api/v1/dca/clients", status_code=HTTPStatus.CREATED) async def api_create_test_dca_client( data: CreateDcaClientData, wallet: WalletTypeInfo = Depends(require_admin_key), @@ -87,7 +87,7 @@ async def api_create_test_dca_client( return await create_dca_client(data) -@satmachineadmin_api_router.get("/api/v1/dca/clients/{client_id}/balance") +@satmachineclient_api_router.get("/api/v1/dca/clients/{client_id}/balance") async def api_get_client_balance( client_id: str, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -104,7 +104,7 @@ async def api_get_client_balance( # DCA Deposit Endpoints -@satmachineadmin_api_router.get("/api/v1/dca/deposits") +@satmachineclient_api_router.get("/api/v1/dca/deposits") async def api_get_deposits( wallet: WalletTypeInfo = Depends(require_invoice_key), ) -> list[DcaDeposit]: @@ -112,7 +112,7 @@ async def api_get_deposits( return await get_all_deposits() -@satmachineadmin_api_router.get("/api/v1/dca/deposits/{deposit_id}") +@satmachineclient_api_router.get("/api/v1/dca/deposits/{deposit_id}") async def api_get_deposit( deposit_id: str, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -126,7 +126,7 @@ async def api_get_deposit( return deposit -@satmachineadmin_api_router.post("/api/v1/dca/deposits", status_code=HTTPStatus.CREATED) +@satmachineclient_api_router.post("/api/v1/dca/deposits", status_code=HTTPStatus.CREATED) async def api_create_deposit( data: CreateDepositData, wallet: WalletTypeInfo = Depends(require_admin_key), @@ -142,7 +142,7 @@ async def api_create_deposit( return await create_deposit(data) -@satmachineadmin_api_router.put("/api/v1/dca/deposits/{deposit_id}/status") +@satmachineclient_api_router.put("/api/v1/dca/deposits/{deposit_id}/status") async def api_update_deposit_status( deposit_id: str, data: UpdateDepositStatusData, @@ -165,7 +165,7 @@ async def api_update_deposit_status( # Transaction Polling Endpoints -@satmachineadmin_api_router.post("/api/v1/dca/test-connection") +@satmachineclient_api_router.post("/api/v1/dca/test-connection") async def api_test_database_connection( wallet: WalletTypeInfo = Depends(require_admin_key), ): @@ -188,7 +188,7 @@ async def api_test_database_connection( } -@satmachineadmin_api_router.post("/api/v1/dca/manual-poll") +@satmachineclient_api_router.post("/api/v1/dca/manual-poll") async def api_manual_poll( wallet: WalletTypeInfo = Depends(require_admin_key), ): @@ -234,7 +234,7 @@ async def api_manual_poll( ) -@satmachineadmin_api_router.post("/api/v1/dca/test-transaction") +@satmachineclient_api_router.post("/api/v1/dca/test-transaction") async def api_test_transaction( wallet: WalletTypeInfo = Depends(require_admin_key), crypto_atoms: int = 103, @@ -296,7 +296,7 @@ async def api_test_transaction( # Lamassu Transaction Endpoints -@satmachineadmin_api_router.get("/api/v1/dca/transactions") +@satmachineclient_api_router.get("/api/v1/dca/transactions") async def api_get_lamassu_transactions( wallet: WalletTypeInfo = Depends(require_invoice_key), ) -> list[StoredLamassuTransaction]: @@ -304,7 +304,7 @@ async def api_get_lamassu_transactions( return await get_all_lamassu_transactions() -@satmachineadmin_api_router.get("/api/v1/dca/transactions/{transaction_id}") +@satmachineclient_api_router.get("/api/v1/dca/transactions/{transaction_id}") async def api_get_lamassu_transaction( transaction_id: str, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -318,7 +318,7 @@ async def api_get_lamassu_transaction( return transaction -@satmachineadmin_api_router.get("/api/v1/dca/transactions/{transaction_id}/distributions") +@satmachineclient_api_router.get("/api/v1/dca/transactions/{transaction_id}/distributions") async def api_get_transaction_distributions( transaction_id: str, wallet: WalletTypeInfo = Depends(require_invoice_key), @@ -356,7 +356,7 @@ async def api_get_transaction_distributions( # Lamassu Configuration Endpoints -@satmachineadmin_api_router.get("/api/v1/dca/config") +@satmachineclient_api_router.get("/api/v1/dca/config") async def api_get_lamassu_config( wallet: WalletTypeInfo = Depends(require_invoice_key), ) -> Optional[LamassuConfig]: @@ -364,7 +364,7 @@ async def api_get_lamassu_config( return await get_active_lamassu_config() -@satmachineadmin_api_router.post("/api/v1/dca/config", status_code=HTTPStatus.CREATED) +@satmachineclient_api_router.post("/api/v1/dca/config", status_code=HTTPStatus.CREATED) async def api_create_lamassu_config( data: CreateLamassuConfigData, wallet: WalletTypeInfo = Depends(require_admin_key), @@ -373,7 +373,7 @@ async def api_create_lamassu_config( return await create_lamassu_config(data) -@satmachineadmin_api_router.put("/api/v1/dca/config/{config_id}") +@satmachineclient_api_router.put("/api/v1/dca/config/{config_id}") async def api_update_lamassu_config( config_id: str, data: UpdateLamassuConfigData, @@ -394,7 +394,7 @@ async def api_update_lamassu_config( return updated_config -@satmachineadmin_api_router.delete("/api/v1/dca/config/{config_id}") +@satmachineclient_api_router.delete("/api/v1/dca/config/{config_id}") async def api_delete_lamassu_config( config_id: str, wallet: WalletTypeInfo = Depends(require_admin_key),