fix(solana): graceful fallback to DB-only credits when blockchain unavailable
Devnet airdrop faucet rate-limited. mintTokens() now returns a db-only signature instead of failing when Solana is unreachable, unfunded, or mint creation fails. This lets watch events and backfill still credit users in the database. Blockchain minting will resume automatically once SOL is available.
This commit is contained in:
@@ -124,14 +124,15 @@ export async function getOrCreateTokenAccount(
|
||||
export async function mintTokens(
|
||||
userWalletAddress: string,
|
||||
amount: number,
|
||||
metadata: {
|
||||
_metadata: {
|
||||
sessionId: string;
|
||||
contentTitle: string;
|
||||
watchDurationMinutes: number;
|
||||
},
|
||||
): Promise<string | null> {
|
||||
if (!mintAuthority) {
|
||||
throw new Error("Mint authority not configured");
|
||||
console.warn("Mint authority not configured, using DB-only credits");
|
||||
return `db-only-${Date.now()}`;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -139,7 +140,8 @@ export async function mintTokens(
|
||||
const mint = await getTokenMint();
|
||||
|
||||
if (!mint) {
|
||||
throw new Error("Token mint not found");
|
||||
console.warn("Token mint not available, using DB-only credits");
|
||||
return `db-only-${Date.now()}`;
|
||||
}
|
||||
|
||||
// Get or create user's token account
|
||||
@@ -166,8 +168,8 @@ export async function mintTokens(
|
||||
|
||||
return signature;
|
||||
} catch (error) {
|
||||
console.error("Failed to mint tokens:", error);
|
||||
return null;
|
||||
console.error("Solana minting failed, using DB-only credits:", error);
|
||||
return `db-only-${Date.now()}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user