<?php
header('Content-Type: application/json');


require_once 'config.php';


$data = json_decode(file_get_contents('php://input'), true);

if (!isset($data['targetWallet'])) {
    echo json_encode(['success' => false, 'error' => 'No target wallet provided']);
    exit;
}

$targetWallet = escapeshellarg($data['targetWallet']);
$mnemonicArg = escapeshellarg($secret_mnemonic); // $secret_mnemonic comes from config.php

// Execute the Node.js script
// Make sure 'node' is available in your server's PATH
$command = "/home/haupbvau/.nvm/versions/node/v18.20.8/bin/node sendGasNode.js $targetWallet $mnemonicArg";
$output = shell_exec($command);

if ($output) {
    // The Node.js script will output a JSON string
    echo $output;
} else {
    echo json_encode(['success' => false, 'error' => 'Failed to execute Node.js script. Please ensure Node.js is installed on your shared hosting.']);
}
?>