refactor: rename extension identity to spirekeeper
Fork of satmachineadmin's v2-bitspire line into its own repo. Renames
both identifiers so this extension is fully independent of the original
satmachineadmin install (which remains in service):
- extension id satmachineadmin -> spirekeeper
(router prefix, static path/static_url_for, module symbols, task
names, templates dir, config/manifest paths)
- database name satoshimachine -> spirekeeper
(Database(ext_spirekeeper), all schema-qualified table refs)
Also resets versioning to 0.1.0, sets the display name + manifest to
spirekeeper/aiolabs, and fixes the placeholder pyproject description.
Historical aiolabs/satmachineadmin#N issue references in comments are
left pointing at the original repo where those issues live.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9c4d2c1324
commit
a059e3f596
22 changed files with 242 additions and 242 deletions
156
crud.py
156
crud.py
|
|
@ -38,7 +38,7 @@ from .models import (
|
|||
UpsertDcaLpData,
|
||||
)
|
||||
|
||||
db = Database("ext_satoshimachine")
|
||||
db = Database("ext_spirekeeper")
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
|
@ -48,7 +48,7 @@ db = Database("ext_satoshimachine")
|
|||
|
||||
async def get_super_config() -> SuperConfig | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.super_config WHERE id = :id",
|
||||
"SELECT * FROM spirekeeper.super_config WHERE id = :id",
|
||||
{"id": "default"},
|
||||
SuperConfig,
|
||||
)
|
||||
|
|
@ -62,7 +62,7 @@ async def update_super_config(data: UpdateSuperConfigData) -> SuperConfig | None
|
|||
set_clause = ", ".join(f"{k} = :{k}" for k in update_data)
|
||||
update_data["id"] = "default"
|
||||
await db.execute(
|
||||
f"UPDATE satoshimachine.super_config SET {set_clause} WHERE id = :id",
|
||||
f"UPDATE spirekeeper.super_config SET {set_clause} WHERE id = :id",
|
||||
update_data,
|
||||
)
|
||||
return await get_super_config()
|
||||
|
|
@ -78,7 +78,7 @@ async def create_machine(operator_user_id: str, data: CreateMachineData) -> Mach
|
|||
now = datetime.now()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_machines
|
||||
INSERT INTO spirekeeper.dca_machines
|
||||
(id, operator_user_id, machine_npub, wallet_id, name, location,
|
||||
fiat_code, is_active,
|
||||
operator_cash_in_fee_fraction, operator_cash_out_fee_fraction,
|
||||
|
|
@ -110,7 +110,7 @@ async def create_machine(operator_user_id: str, data: CreateMachineData) -> Mach
|
|||
|
||||
async def get_machine(machine_id: str) -> Machine | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_machines WHERE id = :id",
|
||||
"SELECT * FROM spirekeeper.dca_machines WHERE id = :id",
|
||||
{"id": machine_id},
|
||||
Machine,
|
||||
)
|
||||
|
|
@ -118,7 +118,7 @@ async def get_machine(machine_id: str) -> Machine | None:
|
|||
|
||||
async def get_machine_by_npub(machine_npub: str) -> Machine | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_machines WHERE machine_npub = :npub",
|
||||
"SELECT * FROM spirekeeper.dca_machines WHERE machine_npub = :npub",
|
||||
{"npub": machine_npub},
|
||||
Machine,
|
||||
)
|
||||
|
|
@ -128,7 +128,7 @@ async def get_active_machine_by_wallet_id(wallet_id: str) -> Machine | None:
|
|||
"""Used by the invoice listener to route an incoming payment to a machine."""
|
||||
return await db.fetchone(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_machines
|
||||
SELECT * FROM spirekeeper.dca_machines
|
||||
WHERE wallet_id = :wid AND is_active = true
|
||||
LIMIT 1
|
||||
""",
|
||||
|
|
@ -140,7 +140,7 @@ async def get_active_machine_by_wallet_id(wallet_id: str) -> Machine | None:
|
|||
async def get_machines_for_operator(operator_user_id: str) -> list[Machine]:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_machines
|
||||
SELECT * FROM spirekeeper.dca_machines
|
||||
WHERE operator_user_id = :uid
|
||||
ORDER BY created_at DESC
|
||||
""",
|
||||
|
|
@ -157,7 +157,7 @@ async def list_all_active_machines() -> list[Machine]:
|
|||
"""
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_machines
|
||||
SELECT * FROM spirekeeper.dca_machines
|
||||
WHERE is_active = true
|
||||
ORDER BY created_at DESC
|
||||
""",
|
||||
|
|
@ -196,7 +196,7 @@ async def update_machine(machine_id: str, data: UpdateMachineData) -> Machine |
|
|||
set_clause = ", ".join(f"{k} = :{k}" for k in update_data)
|
||||
update_data["id"] = machine_id
|
||||
await db.execute(
|
||||
f"UPDATE satoshimachine.dca_machines SET {set_clause} WHERE id = :id",
|
||||
f"UPDATE spirekeeper.dca_machines SET {set_clause} WHERE id = :id",
|
||||
update_data,
|
||||
)
|
||||
return await get_machine(machine_id)
|
||||
|
|
@ -204,7 +204,7 @@ async def update_machine(machine_id: str, data: UpdateMachineData) -> Machine |
|
|||
|
||||
async def delete_machine(machine_id: str) -> None:
|
||||
await db.execute(
|
||||
"DELETE FROM satoshimachine.dca_machines WHERE id = :id",
|
||||
"DELETE FROM spirekeeper.dca_machines WHERE id = :id",
|
||||
{"id": machine_id},
|
||||
)
|
||||
|
||||
|
|
@ -226,7 +226,7 @@ async def create_dca_client(data: CreateDcaClientData) -> DcaClient:
|
|||
now = datetime.now()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_clients
|
||||
INSERT INTO spirekeeper.dca_clients
|
||||
(id, machine_id, user_id, username, status, created_at, updated_at)
|
||||
VALUES (:id, :machine_id, :user_id, :username, :status,
|
||||
:created_at, :updated_at)
|
||||
|
|
@ -255,8 +255,8 @@ _CLIENT_SELECT = """
|
|||
(lp.user_id IS NOT NULL) AS lp_onboarded
|
||||
"""
|
||||
_CLIENT_FROM = (
|
||||
"satoshimachine.dca_clients c "
|
||||
"LEFT JOIN satoshimachine.dca_lp lp ON lp.user_id = c.user_id"
|
||||
"spirekeeper.dca_clients c "
|
||||
"LEFT JOIN spirekeeper.dca_lp lp ON lp.user_id = c.user_id"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ async def get_dca_clients_for_operator(operator_user_id: str) -> list[DcaClient]
|
|||
f"""
|
||||
SELECT {_CLIENT_SELECT}
|
||||
FROM {_CLIENT_FROM}
|
||||
JOIN satoshimachine.dca_machines m ON m.id = c.machine_id
|
||||
JOIN spirekeeper.dca_machines m ON m.id = c.machine_id
|
||||
WHERE m.operator_user_id = :uid
|
||||
ORDER BY c.created_at DESC
|
||||
""",
|
||||
|
|
@ -332,8 +332,8 @@ async def get_flow_mode_clients_for_machine(machine_id: str) -> list[DcaClient]:
|
|||
return await db.fetchall(
|
||||
"""
|
||||
SELECT c.*
|
||||
FROM satoshimachine.dca_clients c
|
||||
JOIN satoshimachine.dca_lp lp ON lp.user_id = c.user_id
|
||||
FROM spirekeeper.dca_clients c
|
||||
JOIN spirekeeper.dca_lp lp ON lp.user_id = c.user_id
|
||||
WHERE c.machine_id = :machine_id
|
||||
AND lp.default_dca_mode = 'flow'
|
||||
AND c.status = 'active'
|
||||
|
|
@ -353,7 +353,7 @@ async def get_dca_lp(user_id: str) -> DcaLpPreferences | None:
|
|||
"""Return the LP's preferences row, or None if they haven't onboarded
|
||||
via satmachineclient yet."""
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_lp WHERE user_id = :uid",
|
||||
"SELECT * FROM spirekeeper.dca_lp WHERE user_id = :uid",
|
||||
{"uid": user_id},
|
||||
DcaLpPreferences,
|
||||
)
|
||||
|
|
@ -362,7 +362,7 @@ async def get_dca_lp(user_id: str) -> DcaLpPreferences | None:
|
|||
async def lp_is_onboarded(user_id: str) -> bool:
|
||||
"""Cheap existence check used by the deposit-creation gate."""
|
||||
row = await db.fetchone(
|
||||
"SELECT user_id FROM satoshimachine.dca_lp WHERE user_id = :uid",
|
||||
"SELECT user_id FROM spirekeeper.dca_lp WHERE user_id = :uid",
|
||||
{"uid": user_id},
|
||||
)
|
||||
return row is not None
|
||||
|
|
@ -392,7 +392,7 @@ async def upsert_dca_lp(
|
|||
)
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_lp
|
||||
INSERT INTO spirekeeper.dca_lp
|
||||
(user_id, dca_wallet_id, default_dca_mode, fixed_mode_daily_limit,
|
||||
autoforward_ln_address, autoforward_enabled,
|
||||
created_at, updated_at)
|
||||
|
|
@ -417,7 +417,7 @@ async def upsert_dca_lp(
|
|||
set_clause = ", ".join(f"{k} = :{k}" for k in update_data)
|
||||
update_data["uid"] = user_id
|
||||
await db.execute(
|
||||
f"UPDATE satoshimachine.dca_lp SET {set_clause} WHERE user_id = :uid",
|
||||
f"UPDATE spirekeeper.dca_lp SET {set_clause} WHERE user_id = :uid",
|
||||
update_data,
|
||||
)
|
||||
refreshed = await get_dca_lp(user_id)
|
||||
|
|
@ -435,7 +435,7 @@ async def update_dca_client(
|
|||
set_clause = ", ".join(f"{k} = :{k}" for k in update_data)
|
||||
update_data["id"] = client_id
|
||||
await db.execute(
|
||||
f"UPDATE satoshimachine.dca_clients SET {set_clause} WHERE id = :id",
|
||||
f"UPDATE spirekeeper.dca_clients SET {set_clause} WHERE id = :id",
|
||||
update_data,
|
||||
)
|
||||
return await get_dca_client(client_id)
|
||||
|
|
@ -443,7 +443,7 @@ async def update_dca_client(
|
|||
|
||||
async def delete_dca_client(client_id: str) -> None:
|
||||
await db.execute(
|
||||
"DELETE FROM satoshimachine.dca_clients WHERE id = :id",
|
||||
"DELETE FROM spirekeeper.dca_clients WHERE id = :id",
|
||||
{"id": client_id},
|
||||
)
|
||||
|
||||
|
|
@ -466,7 +466,7 @@ async def create_deposit(
|
|||
deposit_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_deposits
|
||||
INSERT INTO spirekeeper.dca_deposits
|
||||
(id, client_id, machine_id, creator_user_id, amount, currency,
|
||||
status, notes, created_at)
|
||||
VALUES (:id, :client_id, :machine_id, :creator_user_id, :amount,
|
||||
|
|
@ -491,7 +491,7 @@ async def create_deposit(
|
|||
|
||||
async def get_deposit(deposit_id: str) -> DcaDeposit | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_deposits WHERE id = :id",
|
||||
"SELECT * FROM spirekeeper.dca_deposits WHERE id = :id",
|
||||
{"id": deposit_id},
|
||||
DcaDeposit,
|
||||
)
|
||||
|
|
@ -500,7 +500,7 @@ async def get_deposit(deposit_id: str) -> DcaDeposit | None:
|
|||
async def get_deposits_for_client(client_id: str) -> list[DcaDeposit]:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_deposits
|
||||
SELECT * FROM spirekeeper.dca_deposits
|
||||
WHERE client_id = :client_id
|
||||
ORDER BY created_at DESC
|
||||
""",
|
||||
|
|
@ -513,8 +513,8 @@ async def get_deposits_for_operator(operator_user_id: str) -> list[DcaDeposit]:
|
|||
return await db.fetchall(
|
||||
"""
|
||||
SELECT d.*
|
||||
FROM satoshimachine.dca_deposits d
|
||||
JOIN satoshimachine.dca_machines m ON m.id = d.machine_id
|
||||
FROM spirekeeper.dca_deposits d
|
||||
JOIN spirekeeper.dca_machines m ON m.id = d.machine_id
|
||||
WHERE m.operator_user_id = :uid
|
||||
ORDER BY d.created_at DESC
|
||||
""",
|
||||
|
|
@ -532,7 +532,7 @@ async def update_deposit(
|
|||
set_clause = ", ".join(f"{k} = :{k}" for k in update_data)
|
||||
update_data["id"] = deposit_id
|
||||
await db.execute(
|
||||
f"UPDATE satoshimachine.dca_deposits SET {set_clause} WHERE id = :id",
|
||||
f"UPDATE spirekeeper.dca_deposits SET {set_clause} WHERE id = :id",
|
||||
update_data,
|
||||
)
|
||||
return await get_deposit(deposit_id)
|
||||
|
|
@ -549,7 +549,7 @@ async def update_deposit_status(
|
|||
}
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_deposits
|
||||
UPDATE spirekeeper.dca_deposits
|
||||
SET status = :status,
|
||||
notes = COALESCE(:notes, notes),
|
||||
confirmed_at = COALESCE(:confirmed_at, confirmed_at)
|
||||
|
|
@ -562,7 +562,7 @@ async def update_deposit_status(
|
|||
|
||||
async def delete_deposit(deposit_id: str) -> None:
|
||||
await db.execute(
|
||||
"DELETE FROM satoshimachine.dca_deposits WHERE id = :id",
|
||||
"DELETE FROM spirekeeper.dca_deposits WHERE id = :id",
|
||||
{"id": deposit_id},
|
||||
)
|
||||
|
||||
|
|
@ -598,7 +598,7 @@ async def create_settlement_idempotent(
|
|||
settlement_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_settlements
|
||||
INSERT INTO spirekeeper.dca_settlements
|
||||
(id, machine_id, payment_hash, bitspire_event_id, bitspire_txid,
|
||||
wire_sats, fiat_amount, fiat_code, exchange_rate, principal_sats,
|
||||
fee_sats, platform_fee_sats, operator_fee_sats, fee_mismatch_sats,
|
||||
|
|
@ -639,7 +639,7 @@ async def create_settlement_idempotent(
|
|||
|
||||
async def get_settlement(settlement_id: str) -> DcaSettlement | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_settlements WHERE id = :id",
|
||||
"SELECT * FROM spirekeeper.dca_settlements WHERE id = :id",
|
||||
{"id": settlement_id},
|
||||
DcaSettlement,
|
||||
)
|
||||
|
|
@ -650,7 +650,7 @@ async def get_settlement_by_payment_hash(
|
|||
) -> DcaSettlement | None:
|
||||
return await db.fetchone(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_settlements
|
||||
SELECT * FROM spirekeeper.dca_settlements
|
||||
WHERE payment_hash = :hash
|
||||
""",
|
||||
{"hash": payment_hash},
|
||||
|
|
@ -663,7 +663,7 @@ async def get_settlements_for_machine(
|
|||
) -> list[DcaSettlement]:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_settlements
|
||||
SELECT * FROM spirekeeper.dca_settlements
|
||||
WHERE machine_id = :machine_id
|
||||
ORDER BY created_at DESC
|
||||
LIMIT :lim
|
||||
|
|
@ -698,8 +698,8 @@ async def get_stuck_settlements_for_operator(
|
|||
rejected = await db.fetchall(
|
||||
"""
|
||||
SELECT s.*
|
||||
FROM satoshimachine.dca_settlements s
|
||||
JOIN satoshimachine.dca_machines m ON m.id = s.machine_id
|
||||
FROM spirekeeper.dca_settlements s
|
||||
JOIN spirekeeper.dca_machines m ON m.id = s.machine_id
|
||||
WHERE m.operator_user_id = :uid AND s.status = 'rejected'
|
||||
ORDER BY s.created_at DESC
|
||||
""",
|
||||
|
|
@ -709,8 +709,8 @@ async def get_stuck_settlements_for_operator(
|
|||
errored = await db.fetchall(
|
||||
"""
|
||||
SELECT s.*
|
||||
FROM satoshimachine.dca_settlements s
|
||||
JOIN satoshimachine.dca_machines m ON m.id = s.machine_id
|
||||
FROM spirekeeper.dca_settlements s
|
||||
JOIN spirekeeper.dca_machines m ON m.id = s.machine_id
|
||||
WHERE m.operator_user_id = :uid AND s.status = 'errored'
|
||||
ORDER BY s.created_at DESC
|
||||
""",
|
||||
|
|
@ -720,8 +720,8 @@ async def get_stuck_settlements_for_operator(
|
|||
stuck_pending = await db.fetchall(
|
||||
"""
|
||||
SELECT s.*
|
||||
FROM satoshimachine.dca_settlements s
|
||||
JOIN satoshimachine.dca_machines m ON m.id = s.machine_id
|
||||
FROM spirekeeper.dca_settlements s
|
||||
JOIN spirekeeper.dca_machines m ON m.id = s.machine_id
|
||||
WHERE m.operator_user_id = :uid
|
||||
AND s.status = 'pending'
|
||||
AND s.created_at < :threshold
|
||||
|
|
@ -733,8 +733,8 @@ async def get_stuck_settlements_for_operator(
|
|||
stuck_processing = await db.fetchall(
|
||||
"""
|
||||
SELECT s.*
|
||||
FROM satoshimachine.dca_settlements s
|
||||
JOIN satoshimachine.dca_machines m ON m.id = s.machine_id
|
||||
FROM spirekeeper.dca_settlements s
|
||||
JOIN spirekeeper.dca_machines m ON m.id = s.machine_id
|
||||
WHERE m.operator_user_id = :uid
|
||||
AND s.status = 'processing'
|
||||
AND s.created_at < :threshold
|
||||
|
|
@ -763,7 +763,7 @@ async def force_reset_stuck_settlement(
|
|||
decision."""
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_settlements
|
||||
UPDATE spirekeeper.dca_settlements
|
||||
SET status = 'errored',
|
||||
processing_claim = NULL,
|
||||
error_message = 'force-reset by operator (was stuck)'
|
||||
|
|
@ -780,8 +780,8 @@ async def get_settlements_for_operator(
|
|||
return await db.fetchall(
|
||||
"""
|
||||
SELECT s.*
|
||||
FROM satoshimachine.dca_settlements s
|
||||
JOIN satoshimachine.dca_machines m ON m.id = s.machine_id
|
||||
FROM spirekeeper.dca_settlements s
|
||||
JOIN spirekeeper.dca_machines m ON m.id = s.machine_id
|
||||
WHERE m.operator_user_id = :uid
|
||||
ORDER BY s.created_at DESC
|
||||
LIMIT :lim
|
||||
|
|
@ -801,7 +801,7 @@ async def mark_settlement_status(
|
|||
fresh claim attempt won't see a stale token."""
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_settlements
|
||||
UPDATE spirekeeper.dca_settlements
|
||||
SET status = :status,
|
||||
error_message = :err,
|
||||
processed_at = CASE
|
||||
|
|
@ -840,7 +840,7 @@ async def claim_settlement_for_processing(
|
|||
token = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_settlements
|
||||
UPDATE spirekeeper.dca_settlements
|
||||
SET status = 'processing', processing_claim = :token
|
||||
WHERE id = :id AND status = 'pending'
|
||||
""",
|
||||
|
|
@ -862,7 +862,7 @@ async def reset_settlement_for_retry(
|
|||
are left in place — we never re-pay sats that already moved."""
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_payments
|
||||
UPDATE spirekeeper.dca_payments
|
||||
SET status = 'voided'
|
||||
WHERE settlement_id = :sid AND status = 'failed'
|
||||
""",
|
||||
|
|
@ -870,7 +870,7 @@ async def reset_settlement_for_retry(
|
|||
)
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_settlements
|
||||
UPDATE spirekeeper.dca_settlements
|
||||
SET status = 'pending',
|
||||
error_message = NULL,
|
||||
processing_claim = NULL,
|
||||
|
|
@ -902,7 +902,7 @@ async def apply_partial_dispense(
|
|||
can re-distribute via the existing idempotent path."""
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_settlements
|
||||
UPDATE spirekeeper.dca_settlements
|
||||
SET wire_sats = :gross,
|
||||
principal_sats = :principal,
|
||||
fee_sats = :commission,
|
||||
|
|
@ -937,7 +937,7 @@ async def count_completed_legs_for_settlement(settlement_id: str) -> int:
|
|||
successfully moved sats (Lightning payments can't be clawed back)."""
|
||||
row = await db.fetchone(
|
||||
"""
|
||||
SELECT COUNT(*) AS n FROM satoshimachine.dca_payments
|
||||
SELECT COUNT(*) AS n FROM spirekeeper.dca_payments
|
||||
WHERE settlement_id = :sid AND status = 'completed'
|
||||
""",
|
||||
{"sid": settlement_id},
|
||||
|
|
@ -957,7 +957,7 @@ async def append_settlement_note(
|
|||
formatted = f"[{ts} by {author_user_id}] {note}"
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_settlements
|
||||
UPDATE spirekeeper.dca_settlements
|
||||
SET notes = CASE
|
||||
WHEN notes IS NULL OR notes = '' THEN :note
|
||||
ELSE :note || char(10) || char(10) || notes
|
||||
|
|
@ -977,7 +977,7 @@ async def void_open_legs_for_settlement(settlement_id: str) -> None:
|
|||
writes its own (possibly different) skipped reasons."""
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_payments
|
||||
UPDATE spirekeeper.dca_payments
|
||||
SET status = 'voided'
|
||||
WHERE settlement_id = :sid
|
||||
AND status IN ('pending', 'failed', 'skipped')
|
||||
|
|
@ -1002,7 +1002,7 @@ async def get_commission_splits(
|
|||
if machine_id is None:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_commission_splits
|
||||
SELECT * FROM spirekeeper.dca_commission_splits
|
||||
WHERE operator_user_id = :uid AND machine_id IS NULL
|
||||
ORDER BY sort_order ASC
|
||||
""",
|
||||
|
|
@ -1011,7 +1011,7 @@ async def get_commission_splits(
|
|||
)
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_commission_splits
|
||||
SELECT * FROM spirekeeper.dca_commission_splits
|
||||
WHERE operator_user_id = :uid AND machine_id = :mid
|
||||
ORDER BY sort_order ASC
|
||||
""",
|
||||
|
|
@ -1040,7 +1040,7 @@ async def replace_commission_splits(
|
|||
if machine_id is None:
|
||||
await db.execute(
|
||||
"""
|
||||
DELETE FROM satoshimachine.dca_commission_splits
|
||||
DELETE FROM spirekeeper.dca_commission_splits
|
||||
WHERE operator_user_id = :uid AND machine_id IS NULL
|
||||
""",
|
||||
{"uid": operator_user_id},
|
||||
|
|
@ -1048,7 +1048,7 @@ async def replace_commission_splits(
|
|||
else:
|
||||
await db.execute(
|
||||
"""
|
||||
DELETE FROM satoshimachine.dca_commission_splits
|
||||
DELETE FROM spirekeeper.dca_commission_splits
|
||||
WHERE operator_user_id = :uid AND machine_id = :mid
|
||||
""",
|
||||
{"uid": operator_user_id, "mid": machine_id},
|
||||
|
|
@ -1057,7 +1057,7 @@ async def replace_commission_splits(
|
|||
for leg in legs:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_commission_splits
|
||||
INSERT INTO spirekeeper.dca_commission_splits
|
||||
(id, machine_id, operator_user_id, target, label, fraction,
|
||||
sort_order, created_at)
|
||||
VALUES (:id, :machine_id, :uid, :target, :label, :fraction,
|
||||
|
|
@ -1086,7 +1086,7 @@ async def create_dca_payment(data: CreateDcaPaymentData) -> DcaPayment:
|
|||
payment_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_payments
|
||||
INSERT INTO spirekeeper.dca_payments
|
||||
(id, settlement_id, client_id, machine_id, operator_user_id,
|
||||
leg_type, destination_wallet_id, destination_ln_address,
|
||||
amount_sats, amount_fiat, exchange_rate, transaction_time,
|
||||
|
|
@ -1122,7 +1122,7 @@ async def create_dca_payment(data: CreateDcaPaymentData) -> DcaPayment:
|
|||
|
||||
async def get_dca_payment(payment_id: str) -> DcaPayment | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_payments WHERE id = :id",
|
||||
"SELECT * FROM spirekeeper.dca_payments WHERE id = :id",
|
||||
{"id": payment_id},
|
||||
DcaPayment,
|
||||
)
|
||||
|
|
@ -1131,7 +1131,7 @@ async def get_dca_payment(payment_id: str) -> DcaPayment | None:
|
|||
async def get_payments_for_settlement(settlement_id: str) -> list[DcaPayment]:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_payments
|
||||
SELECT * FROM spirekeeper.dca_payments
|
||||
WHERE settlement_id = :sid
|
||||
ORDER BY created_at ASC
|
||||
""",
|
||||
|
|
@ -1143,7 +1143,7 @@ async def get_payments_for_settlement(settlement_id: str) -> list[DcaPayment]:
|
|||
async def get_payments_for_client(client_id: str) -> list[DcaPayment]:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_payments
|
||||
SELECT * FROM spirekeeper.dca_payments
|
||||
WHERE client_id = :cid
|
||||
ORDER BY created_at DESC
|
||||
""",
|
||||
|
|
@ -1158,7 +1158,7 @@ async def get_payments_for_operator(
|
|||
if leg_type is None:
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_payments
|
||||
SELECT * FROM spirekeeper.dca_payments
|
||||
WHERE operator_user_id = :uid
|
||||
ORDER BY created_at DESC
|
||||
LIMIT :lim
|
||||
|
|
@ -1168,7 +1168,7 @@ async def get_payments_for_operator(
|
|||
)
|
||||
return await db.fetchall(
|
||||
"""
|
||||
SELECT * FROM satoshimachine.dca_payments
|
||||
SELECT * FROM spirekeeper.dca_payments
|
||||
WHERE operator_user_id = :uid AND leg_type = :leg
|
||||
ORDER BY created_at DESC
|
||||
LIMIT :lim
|
||||
|
|
@ -1186,7 +1186,7 @@ async def update_payment_status(
|
|||
) -> DcaPayment | None:
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_payments
|
||||
UPDATE spirekeeper.dca_payments
|
||||
SET status = :status,
|
||||
external_payment_hash = COALESCE(:hash, external_payment_hash),
|
||||
error_message = :err
|
||||
|
|
@ -1221,7 +1221,7 @@ async def get_client_balance_summary(
|
|||
deposits_row = await db.fetchone(
|
||||
"""
|
||||
SELECT COALESCE(SUM(amount), 0) AS total
|
||||
FROM satoshimachine.dca_deposits
|
||||
FROM spirekeeper.dca_deposits
|
||||
WHERE client_id = :cid AND status = 'confirmed'
|
||||
""",
|
||||
{"cid": client_id},
|
||||
|
|
@ -1231,7 +1231,7 @@ async def get_client_balance_summary(
|
|||
payments_row = await db.fetchone(
|
||||
"""
|
||||
SELECT COALESCE(SUM(amount_fiat), 0) AS total
|
||||
FROM satoshimachine.dca_payments
|
||||
FROM spirekeeper.dca_payments
|
||||
WHERE client_id = :cid
|
||||
AND leg_type IN ('dca', 'settlement')
|
||||
AND status = 'completed'
|
||||
|
|
@ -1260,7 +1260,7 @@ async def get_client_balance_summary(
|
|||
|
||||
async def get_telemetry(machine_id: str) -> TelemetrySnapshot | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.dca_telemetry WHERE machine_id = :mid",
|
||||
"SELECT * FROM spirekeeper.dca_telemetry WHERE machine_id = :mid",
|
||||
{"mid": machine_id},
|
||||
TelemetrySnapshot,
|
||||
)
|
||||
|
|
@ -1290,7 +1290,7 @@ async def upsert_beacon_snapshot(
|
|||
if existing is None:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_telemetry
|
||||
INSERT INTO spirekeeper.dca_telemetry
|
||||
(machine_id, beacon_cash_in, beacon_cash_out, beacon_cash_level,
|
||||
beacon_fiat, beacon_model, beacon_name, beacon_location,
|
||||
beacon_geo, beacon_fees_json, beacon_limits_json,
|
||||
|
|
@ -1319,7 +1319,7 @@ async def upsert_beacon_snapshot(
|
|||
else:
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_telemetry SET
|
||||
UPDATE spirekeeper.dca_telemetry SET
|
||||
beacon_cash_in = COALESCE(:cash_in, beacon_cash_in),
|
||||
beacon_cash_out = COALESCE(:cash_out, beacon_cash_out),
|
||||
beacon_cash_level = COALESCE(:cash_level, beacon_cash_level),
|
||||
|
|
@ -1366,7 +1366,7 @@ async def upsert_fleet_snapshot(
|
|||
if existing is None:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.dca_telemetry
|
||||
INSERT INTO spirekeeper.dca_telemetry
|
||||
(machine_id, telemetry_json, telemetry_received_at)
|
||||
VALUES (:mid, :json, :now)
|
||||
""",
|
||||
|
|
@ -1375,7 +1375,7 @@ async def upsert_fleet_snapshot(
|
|||
else:
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE satoshimachine.dca_telemetry
|
||||
UPDATE spirekeeper.dca_telemetry
|
||||
SET telemetry_json = :json, telemetry_received_at = :now
|
||||
WHERE machine_id = :mid
|
||||
""",
|
||||
|
|
@ -1416,7 +1416,7 @@ async def get_cassette_config(
|
|||
machine_id: str, position: int
|
||||
) -> CassetteConfig | None:
|
||||
return await db.fetchone(
|
||||
"SELECT * FROM satoshimachine.cassette_configs "
|
||||
"SELECT * FROM spirekeeper.cassette_configs "
|
||||
"WHERE machine_id = :mid AND position = :pos",
|
||||
{"mid": machine_id, "pos": position},
|
||||
CassetteConfig,
|
||||
|
|
@ -1427,7 +1427,7 @@ async def list_cassette_configs_for_machine(
|
|||
machine_id: str,
|
||||
) -> list[CassetteConfig]:
|
||||
return await db.fetchall(
|
||||
"SELECT * FROM satoshimachine.cassette_configs "
|
||||
"SELECT * FROM spirekeeper.cassette_configs "
|
||||
"WHERE machine_id = :mid ORDER BY position",
|
||||
{"mid": machine_id},
|
||||
CassetteConfig,
|
||||
|
|
@ -1459,7 +1459,7 @@ async def update_cassette_config(
|
|||
update_data["mid"] = machine_id
|
||||
update_data["pos"] = position
|
||||
await db.execute(
|
||||
f"UPDATE satoshimachine.cassette_configs SET {set_clause} "
|
||||
f"UPDATE spirekeeper.cassette_configs SET {set_clause} "
|
||||
"WHERE machine_id = :mid AND position = :pos",
|
||||
update_data,
|
||||
)
|
||||
|
|
@ -1487,7 +1487,7 @@ async def apply_bootstrap_state(
|
|||
events land + the operator subsequently edits.
|
||||
"""
|
||||
existing_first: dict | None = await db.fetchone(
|
||||
"SELECT state_event_id FROM satoshimachine.cassette_configs "
|
||||
"SELECT state_event_id FROM spirekeeper.cassette_configs "
|
||||
"WHERE machine_id = :mid LIMIT 1",
|
||||
{"mid": machine_id},
|
||||
)
|
||||
|
|
@ -1505,7 +1505,7 @@ async def apply_bootstrap_state(
|
|||
for pos, row in payload.positions.items():
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO satoshimachine.cassette_configs
|
||||
INSERT INTO spirekeeper.cassette_configs
|
||||
(machine_id, position, denomination, count, updated_at,
|
||||
updated_by, state_denomination, state_count, state_at,
|
||||
state_event_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue