Add session mode for pre-funded request processing
Implement session-based API endpoints for creating, managing, and interacting with pre-funded sessions, including deposit and top-up invoice generation, macaroon authentication, and per-request debiting of compute costs. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 2dc3847e-7186-4a22-9c7e-16cd31bca8d9 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9f85e954-647c-46a5-90a7-396e495a805a/418bf6f8-212b-4bb0-a7a5-8231a061da4e/sPDHkg8 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
39
lib/db/migrations/0004_sessions.sql
Normal file
39
lib/db/migrations/0004_sessions.sql
Normal file
@@ -0,0 +1,39 @@
|
||||
-- Migration: Session balance mode (Mode 2)
|
||||
-- Users pre-fund a Lightning session; requests auto-debit actual costs.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL DEFAULT 'awaiting_payment',
|
||||
balance_sats INTEGER NOT NULL DEFAULT 0,
|
||||
deposit_amount_sats INTEGER NOT NULL,
|
||||
deposit_payment_hash TEXT NOT NULL,
|
||||
deposit_payment_request TEXT NOT NULL,
|
||||
deposit_paid BOOLEAN NOT NULL DEFAULT false,
|
||||
topup_amount_sats INTEGER,
|
||||
topup_payment_hash TEXT,
|
||||
topup_payment_request TEXT,
|
||||
topup_paid BOOLEAN,
|
||||
macaroon TEXT,
|
||||
expires_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS session_requests (
|
||||
id TEXT PRIMARY KEY,
|
||||
session_id TEXT NOT NULL REFERENCES sessions(id),
|
||||
request TEXT NOT NULL,
|
||||
state TEXT NOT NULL DEFAULT 'processing',
|
||||
result TEXT,
|
||||
reason TEXT,
|
||||
error_message TEXT,
|
||||
eval_input_tokens INTEGER,
|
||||
eval_output_tokens INTEGER,
|
||||
work_input_tokens INTEGER,
|
||||
work_output_tokens INTEGER,
|
||||
debited_sats INTEGER,
|
||||
balance_after_sats INTEGER,
|
||||
btc_price_usd REAL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
Reference in New Issue
Block a user