forked from BlackBeard085/x1console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setwithdrawer.js
39 lines (34 loc) · 1.21 KB
/
setwithdrawer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { exec } = require('child_process');
const path = require('path');
const os = require('os');
// Define the expected keypair path
const expectedKeypairPath = path.join(os.homedir(), '.config', 'solana', 'id.json');
// Function to execute a shell command
const runCommand = (command) => {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`Error executing command: ${stderr}`);
}
resolve(stdout);
});
});
};
const checkSolanaConfig = async () => {
try {
// Get the solana config
const configOutput = await runCommand('solana config get');
// Check if the output contains the expected keypair path
if (configOutput.includes(`Keypair Path:`) && configOutput.includes(expectedKeypairPath)) {
console.log('withdrawer is set');
} else {
console.log('setting to withdrawer');
await runCommand(`solana config set -k ${expectedKeypairPath}`);
console.log('Wallet has been set to withdrawer');
}
} catch (error) {
console.error(error);
}
};
// Run the check
checkSolanaConfig();