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(
|
export async function mintTokens(
|
||||||
userWalletAddress: string,
|
userWalletAddress: string,
|
||||||
amount: number,
|
amount: number,
|
||||||
metadata: {
|
_metadata: {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
contentTitle: string;
|
contentTitle: string;
|
||||||
watchDurationMinutes: number;
|
watchDurationMinutes: number;
|
||||||
},
|
},
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
if (!mintAuthority) {
|
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 {
|
try {
|
||||||
@@ -139,7 +140,8 @@ export async function mintTokens(
|
|||||||
const mint = await getTokenMint();
|
const mint = await getTokenMint();
|
||||||
|
|
||||||
if (!mint) {
|
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
|
// Get or create user's token account
|
||||||
@@ -166,8 +168,8 @@ export async function mintTokens(
|
|||||||
|
|
||||||
return signature;
|
return signature;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to mint tokens:", error);
|
console.error("Solana minting failed, using DB-only credits:", error);
|
||||||
return null;
|
return `db-only-${Date.now()}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user