Files
Pay2Gateway/test_sweep_native.ts

34 lines
1.4 KiB
TypeScript

import { CryptoEngine } from './lib/crypto-engine';
import { db } from './lib/db';
async function testSweep() {
console.log("Starting test for specific TX...");
const result = await db.query("SELECT * FROM transactions WHERE id = $1", ["5fda5442-23ea-4130-8646-d0a882ed2517"]);
if(result.rows.length === 0) return console.log("TX not found");
const tx = result.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;
const verification = await cryptoEngine.verifyPayment(depositAddress, "0.164824", "SOL");
console.log("Verify:", verification);
const { Connection, PublicKey } = require('@solana/web3.js');
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
const b = await connection.getBalance(new PublicKey(depositAddress));
console.log("Direct Balance check:", b / 1e9);
if(verification.success) {
console.log("Sweeping...");
const res = await cryptoEngine.sweepFunds(depositPrivateKey, "Ajr4nKieZJVu9q2d1eVF9pQPRCLoZ6v4tapB3iQn2SyQ", "SOL");
console.log("Result:", res);
}
}
testSweep().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });