88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
|
|
const { Client } = require('pg');
|
|
const { Connection, PublicKey } = require('@solana/web3.js');
|
|
|
|
async function debugLatestPending() {
|
|
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
|
await client.connect();
|
|
|
|
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
|
|
|
|
// Get the most recent pending transaction
|
|
const res = await client.query(`
|
|
SELECT id, source_ref_id, amount, currency, metadata, created_at
|
|
FROM transactions
|
|
WHERE status IN ('pending', 'waiting')
|
|
ORDER BY created_at DESC
|
|
LIMIT 1
|
|
`);
|
|
|
|
if (res.rows.length === 0) {
|
|
console.log("No pending transactions found.");
|
|
await client.end();
|
|
return;
|
|
}
|
|
|
|
const tx = res.rows[0];
|
|
console.log(`\n--- Most Recent Pending TX: ${tx.source_ref_id} (${tx.id}) ---`);
|
|
console.log(`Created At: ${tx.created_at}`);
|
|
console.log(`Amount: ${tx.amount} ${tx.currency}`);
|
|
|
|
const solAddr = tx.metadata?.wallets?.SOLANA?.address;
|
|
|
|
if (!solAddr) {
|
|
console.log("❌ No Solana wallet found for this transaction.");
|
|
await client.end();
|
|
return;
|
|
}
|
|
console.log(`Wallet Address: ${solAddr}`);
|
|
|
|
// Try to calculate expected amount
|
|
let expectedSolAmount = "Unknown";
|
|
try {
|
|
const tryRes = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=USDTTRY`);
|
|
const tryData = await tryRes.json();
|
|
const usdTryPrice = parseFloat(tryData.price);
|
|
|
|
const solRes = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=SOLUSDT`);
|
|
const solData = await solRes.json();
|
|
const solUsdPrice = parseFloat(solData.price);
|
|
|
|
const priceInTry = solUsdPrice * usdTryPrice;
|
|
const rawExpected = parseFloat(tx.amount) / priceInTry;
|
|
expectedSolAmount = (rawExpected * 0.98).toFixed(6);
|
|
console.log(`Current SOL Price: ~${priceInTry.toFixed(2)} TRY`);
|
|
console.log(`Expected Min: ${expectedSolAmount} SOL`);
|
|
} catch (e) {
|
|
console.log("Price fetch failed");
|
|
}
|
|
|
|
// Check Actual Balance
|
|
try {
|
|
const pubKey = new PublicKey(solAddr);
|
|
const balance = await connection.getBalance(pubKey);
|
|
const actualSol = balance / 1e9;
|
|
console.log(`Actual Wallet Balance: ${actualSol} SOL`);
|
|
|
|
if (actualSol >= parseFloat(expectedSolAmount || "0")) {
|
|
console.log("✅ VERIFICATION SHOULD PASS!");
|
|
} else {
|
|
console.log("❌ VERIFICATION FAILED: Insufficient balance.");
|
|
}
|
|
|
|
// Find recent signatures to see if a payment was attempted
|
|
const signatures = await connection.getSignaturesForAddress(pubKey, { limit: 5 });
|
|
console.log(`Recent Signatures: ${signatures.length}`);
|
|
if(signatures.length > 0) {
|
|
console.log(signatures.map(s => s.signature).join('\n'));
|
|
}
|
|
|
|
} catch(e) {
|
|
console.error("Error checking Solana balance:", e);
|
|
}
|
|
|
|
await client.end();
|
|
}
|
|
|
|
debugLatestPending();
|