40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
|
|
const { CryptoEngine } = require('./lib/crypto-engine');
|
|
const { Client } = require('pg');
|
|
|
|
async function testSweepAPI() {
|
|
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
|
await client.connect();
|
|
|
|
// Get the most recent pending tx
|
|
const res = await client.query("SELECT * FROM transactions WHERE status IN ('pending', 'waiting') ORDER BY created_at DESC LIMIT 1");
|
|
if(res.rows.length === 0) return console.log("No pending");
|
|
|
|
const tx = res.rows[0];
|
|
const wallets = tx.metadata?.wallets || {};
|
|
const solWallet = wallets['SOLANA'];
|
|
|
|
console.log("Found TX:", tx.id, "Address:", solWallet.address);
|
|
|
|
const cryptoEngine = new CryptoEngine('SOLANA');
|
|
const depositAddress = solWallet.address;
|
|
const depositPrivateKey = solWallet.privateKey;
|
|
|
|
// Check verify explicitly
|
|
const actualVerification = await cryptoEngine.verifyPayment(depositAddress, "0.295226", "SOL");
|
|
console.log("Verify result:", actualVerification);
|
|
|
|
if(actualVerification.success) {
|
|
console.log("Attempting sweep...");
|
|
try {
|
|
const platformAddress = "Ajr4nKieZJVu9q2d1eVF9pQPRCLoZ6v4tapB3iQn2SyQ";
|
|
const sweepResult = await cryptoEngine.sweepFunds(depositPrivateKey, platformAddress, "SOL");
|
|
console.log("Sweep result:", sweepResult);
|
|
} catch(e) {
|
|
console.error("Sweep threw error:", e);
|
|
}
|
|
}
|
|
await client.end();
|
|
}
|
|
testSweepAPI();
|