feat: payments schema + deps for Lightning ranked fights

Add payments and wallet_connections tables, new columns on fights (mode,
pot_sats, payout_status) and bots (sats_won, sats_wagered, has_wallet).
Install nostr-tools and @cashu/cashu-ts for NWC + ecash support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 01:17:15 +00:00
co-authored by Claude Opus 4.6
parent 6b139a076a
commit e92f483e66
4 changed files with 157 additions and 1 deletions
+34
View File
@@ -20,6 +20,9 @@ export const bots = sqliteTable('bots', {
consecutiveErrors: integer('consecutive_errors').notNull().default(0),
lastErrorAt: text('last_error_at'),
customization: text('customization'),
satsWon: integer('sats_won').notNull().default(0),
satsWagered: integer('sats_wagered').notNull().default(0),
hasWallet: integer('has_wallet', { mode: 'boolean' }).notNull().default(false),
createdAt: text('created_at').notNull(),
})
@@ -36,6 +39,9 @@ export const fights = sqliteTable('fights', {
scheduledAt: text('scheduled_at'),
startedAt: text('started_at'),
endedAt: text('ended_at'),
mode: text('mode', { enum: ['free', 'ranked'] }).notNull().default('free'),
potSats: integer('pot_sats').notNull().default(0),
payoutStatus: text('payout_status', { enum: ['pending', 'paid', 'failed'] }),
createdAt: text('created_at').notNull(),
})
@@ -56,6 +62,34 @@ export const rounds = sqliteTable('rounds', {
createdAt: text('created_at').notNull(),
})
export const payments = sqliteTable('payments', {
id: text('id').primaryKey(),
fightId: text('fight_id').references(() => fights.id),
botId: text('bot_id').notNull().references(() => bots.id),
direction: text('direction', { enum: ['in', 'out'] }).notNull(),
amountSats: integer('amount_sats').notNull(),
method: text('method', { enum: ['lightning', 'cashu'] }).notNull(),
status: text('status', {
enum: ['pending', 'confirmed', 'failed', 'refunded'],
}).notNull().default('pending'),
invoice: text('invoice'),
preimage: text('preimage'),
cashuToken: text('cashu_token'),
errorReason: text('error_reason'),
createdAt: text('created_at').notNull(),
confirmedAt: text('confirmed_at'),
refundedAt: text('refunded_at'),
})
export const walletConnections = sqliteTable('wallet_connections', {
id: text('id').primaryKey(),
botId: text('bot_id').notNull().unique().references(() => bots.id),
method: text('method', { enum: ['nwc', 'lnaddress', 'cashu_mint'] }).notNull(),
connectionData: text('connection_data').notNull(),
createdAt: text('created_at').notNull(),
lastUsedAt: text('last_used_at'),
})
export const bets = sqliteTable('bets', {
id: text('id').primaryKey(),
fightId: text('fight_id').notNull().references(() => fights.id),
+36
View File
@@ -58,6 +58,34 @@ export function runMigrations() {
);
`)
sqlite.exec(`
CREATE TABLE IF NOT EXISTS payments (
id TEXT PRIMARY KEY,
fight_id TEXT REFERENCES fights(id),
bot_id TEXT NOT NULL REFERENCES bots(id),
direction TEXT NOT NULL,
amount_sats INTEGER NOT NULL,
method TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
invoice TEXT,
preimage TEXT,
cashu_token TEXT,
error_reason TEXT,
created_at TEXT NOT NULL,
confirmed_at TEXT,
refunded_at TEXT
);
CREATE TABLE IF NOT EXISTS wallet_connections (
id TEXT PRIMARY KEY,
bot_id TEXT NOT NULL UNIQUE REFERENCES bots(id),
method TEXT NOT NULL,
connection_data TEXT NOT NULL,
created_at TEXT NOT NULL,
last_used_at TEXT
);
`)
// Column migrations for existing databases
const migrations = [
"ALTER TABLE bots ADD COLUMN archetype TEXT NOT NULL DEFAULT 'standard'",
@@ -66,6 +94,14 @@ export function runMigrations() {
"ALTER TABLE bots ADD COLUMN consecutive_errors INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE bots ADD COLUMN last_error_at TEXT",
"ALTER TABLE bots ADD COLUMN customization TEXT",
// Ranked fights columns
"ALTER TABLE fights ADD COLUMN mode TEXT NOT NULL DEFAULT 'free'",
"ALTER TABLE fights ADD COLUMN pot_sats INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE fights ADD COLUMN payout_status TEXT",
// Bot sats tracking
"ALTER TABLE bots ADD COLUMN sats_won INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE bots ADD COLUMN sats_wagered INTEGER NOT NULL DEFAULT 0",
"ALTER TABLE bots ADD COLUMN has_wallet INTEGER NOT NULL DEFAULT 0",
]
for (const sql of migrations) {