refactor: db-only credits and admin controls
Remove blockchain dependence from credit flow: - watch credits now DB-only - webhook earnings now DB-only - wallet balance now DB-only - admin bonus/adjustment routes operate on DB totals Add admin adjustment API for account control. Keep Solana service file unused for now; safe to delete later.
This commit is contained in:
+14
-24
@@ -3,7 +3,7 @@ import crypto from "crypto";
|
||||
import { Router } from "express";
|
||||
import jwt from "jsonwebtoken";
|
||||
import { asyncHandler } from "../middleware/errorHandler";
|
||||
import { createWallet, mintTokens } from "../services/solana";
|
||||
import { createWallet } from "../services/solana";
|
||||
import { prisma } from "../utils/prisma";
|
||||
|
||||
const ENCRYPTION_KEY =
|
||||
@@ -374,31 +374,21 @@ async function backfillUserHistory(user: {
|
||||
},
|
||||
});
|
||||
|
||||
// Mint tokens on Solana
|
||||
const signature = await mintTokens(user.walletAddress!, creditsEarned, {
|
||||
sessionId,
|
||||
contentTitle: item.title || item.full_title || "Unknown",
|
||||
watchDurationMinutes,
|
||||
// DB-only credit record
|
||||
await prisma.transaction.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
type: "EARN",
|
||||
amount: creditsEarned,
|
||||
watchEventId: watchEvent.id,
|
||||
description: `Watched ${item.title || item.full_title || "Unknown"}`,
|
||||
contentTitle: item.title || item.full_title || "Unknown",
|
||||
},
|
||||
});
|
||||
|
||||
if (signature) {
|
||||
// Create transaction record
|
||||
await prisma.transaction.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
type: "EARN",
|
||||
amount: creditsEarned,
|
||||
watchEventId: watchEvent.id,
|
||||
solanaSignature: signature,
|
||||
description: `Watched ${item.title || item.full_title || "Unknown"}`,
|
||||
contentTitle: item.title || item.full_title || "Unknown",
|
||||
},
|
||||
});
|
||||
|
||||
totalCredits += creditsEarned;
|
||||
totalMinutes += watchDurationMinutes;
|
||||
processedCount++;
|
||||
}
|
||||
totalCredits += creditsEarned;
|
||||
totalMinutes += watchDurationMinutes;
|
||||
processedCount++;
|
||||
}
|
||||
|
||||
// Update user stats
|
||||
|
||||
Reference in New Issue
Block a user