decharge-scout 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +52 -18
- package/package.json +1 -1
- package/src/energy-data.js +9 -1
package/index.js
CHANGED
|
@@ -46,7 +46,8 @@ const __dirname = dirname(__filename);
|
|
|
46
46
|
// Configuration
|
|
47
47
|
const STAKE_AMOUNT = parseFloat(process.env.STAKE_AMOUNT || '0.01');
|
|
48
48
|
const CYCLE_INTERVAL_MS = 15 * 60 * 1000; // 15 minutes
|
|
49
|
-
|
|
49
|
+
// Use current working directory for wallet by default (not package installation dir)
|
|
50
|
+
const DEFAULT_WALLET_PATH = path.join(process.cwd(), 'wallet.json');
|
|
50
51
|
|
|
51
52
|
// Global state
|
|
52
53
|
let isRunning = true;
|
|
@@ -74,16 +75,35 @@ function generateAgentName() {
|
|
|
74
75
|
*/
|
|
75
76
|
function findExistingWallets() {
|
|
76
77
|
const wallets = [];
|
|
78
|
+
const homeDir = os.homedir();
|
|
79
|
+
const cwd = process.cwd();
|
|
80
|
+
|
|
77
81
|
const searchPaths = [
|
|
78
|
-
// Current directory
|
|
79
|
-
path.join(
|
|
80
|
-
path.join(
|
|
82
|
+
// Current directory - most common
|
|
83
|
+
path.join(cwd, 'wallet.json'),
|
|
84
|
+
path.join(cwd, 'id.json'),
|
|
85
|
+
path.join(cwd, 'keypair.json'),
|
|
86
|
+
path.join(cwd, 'solana-wallet.json'),
|
|
87
|
+
path.join(cwd, 'my-wallet.json'),
|
|
88
|
+
|
|
89
|
+
// Package directory (for global installations)
|
|
90
|
+
path.join(__dirname, 'wallet.json'),
|
|
91
|
+
path.join(__dirname, 'id.json'),
|
|
92
|
+
|
|
93
|
+
// Solana CLI default locations
|
|
94
|
+
path.join(homeDir, '.config', 'solana', 'id.json'),
|
|
95
|
+
path.join(homeDir, '.solana', 'id.json'),
|
|
96
|
+
path.join(homeDir, '.solana', 'devnet.json'),
|
|
97
|
+
path.join(homeDir, '.solana', 'testnet.json'),
|
|
98
|
+
|
|
81
99
|
// Home directory
|
|
82
|
-
path.join(
|
|
83
|
-
path.join(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
path.join(
|
|
100
|
+
path.join(homeDir, 'wallet.json'),
|
|
101
|
+
path.join(homeDir, 'solana-wallet.json'),
|
|
102
|
+
|
|
103
|
+
// Downloads (users often save here)
|
|
104
|
+
path.join(homeDir, 'Downloads', 'wallet.json'),
|
|
105
|
+
path.join(homeDir, 'Downloads', 'solana-wallet.json'),
|
|
106
|
+
path.join(homeDir, 'Downloads', 'keypair.json'),
|
|
87
107
|
];
|
|
88
108
|
|
|
89
109
|
for (const walletPath of searchPaths) {
|
|
@@ -119,10 +139,11 @@ async function ensureWallet(walletPath) {
|
|
|
119
139
|
console.log(chalk.yellow(`\n⚠️ No wallet found at ${walletPath}`));
|
|
120
140
|
|
|
121
141
|
// Search for existing wallets
|
|
142
|
+
console.log(chalk.blue('🔍 Searching for existing Solana wallets...'));
|
|
122
143
|
const existingWallets = findExistingWallets();
|
|
123
144
|
|
|
124
145
|
if (existingWallets.length > 0) {
|
|
125
|
-
console.log(chalk.green(`\n
|
|
146
|
+
console.log(chalk.green(`\n✓ Found ${existingWallets.length} existing wallet(s):\n`));
|
|
126
147
|
|
|
127
148
|
existingWallets.forEach((wallet, index) => {
|
|
128
149
|
console.log(chalk.cyan(` ${index + 1}. ${wallet.name}`));
|
|
@@ -142,6 +163,9 @@ async function ensureWallet(walletPath) {
|
|
|
142
163
|
console.log(chalk.yellow('Invalid selection, creating new wallet...'));
|
|
143
164
|
}
|
|
144
165
|
}
|
|
166
|
+
} else {
|
|
167
|
+
console.log(chalk.yellow('⚠️ No existing wallets found in common locations.'));
|
|
168
|
+
console.log(chalk.gray(' Searched: ~/.solana/id.json, ./wallet.json, ./id.json, etc.\n'));
|
|
145
169
|
}
|
|
146
170
|
|
|
147
171
|
const answer = await question('Create a new wallet? (Y/n): ');
|
|
@@ -177,6 +201,7 @@ async function ensureWallet(walletPath) {
|
|
|
177
201
|
writeFileSync(walletPath, JSON.stringify(privateKey));
|
|
178
202
|
|
|
179
203
|
console.log(chalk.green(`✓ Wallet imported: ${keypair.publicKey.toBase58()}`));
|
|
204
|
+
console.log(chalk.blue(`📁 Wallet saved to: ${walletPath}`));
|
|
180
205
|
return walletPath;
|
|
181
206
|
} catch (error) {
|
|
182
207
|
console.log(chalk.red(`\n❌ Invalid private key: ${error.message}`));
|
|
@@ -193,6 +218,7 @@ async function ensureWallet(walletPath) {
|
|
|
193
218
|
writeFileSync(walletPath, JSON.stringify(secretKey));
|
|
194
219
|
|
|
195
220
|
console.log(chalk.green(`✓ Wallet created: ${keypair.publicKey.toBase58()}`));
|
|
221
|
+
console.log(chalk.blue(`📁 Wallet saved to: ${walletPath}`));
|
|
196
222
|
console.log(chalk.yellow('⚠️ IMPORTANT: Backup this wallet file!'));
|
|
197
223
|
console.log(chalk.blue(`\nYou need devnet SOL. Get it from:`));
|
|
198
224
|
console.log(chalk.gray(' solana airdrop 1 ' + keypair.publicKey.toBase58() + ' --url devnet'));
|
|
@@ -281,25 +307,33 @@ async function main(options) {
|
|
|
281
307
|
// Ask user to confirm or override (with timeout)
|
|
282
308
|
console.log(chalk.blue('\nYou can use this location or enter a custom one.'));
|
|
283
309
|
console.log(chalk.gray('(Press Enter to use detected location, or type custom location)'));
|
|
310
|
+
console.log(chalk.gray('You have 30 seconds to respond...'));
|
|
284
311
|
|
|
285
312
|
try {
|
|
286
|
-
// Create a promise that auto-resolves after
|
|
313
|
+
// Create a promise that auto-resolves after 30 seconds
|
|
287
314
|
const timeoutPromise = new Promise((resolve) => {
|
|
288
315
|
setTimeout(() => {
|
|
289
|
-
console.log(chalk.yellow('\n⏱️
|
|
290
|
-
resolve('');
|
|
291
|
-
},
|
|
316
|
+
console.log(chalk.yellow('\n⏱️ Timeout - using detected location...'));
|
|
317
|
+
resolve('__TIMEOUT__');
|
|
318
|
+
}, 30000);
|
|
292
319
|
});
|
|
293
320
|
|
|
294
321
|
const questionPromise = question('Enter custom location (or press Enter): ');
|
|
295
322
|
|
|
296
323
|
const customLocation = await Promise.race([questionPromise, timeoutPromise]);
|
|
297
|
-
location = customLocation.trim() || detectedLocation;
|
|
298
324
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
325
|
+
// If timeout occurred, use detected location
|
|
326
|
+
if (customLocation === '__TIMEOUT__') {
|
|
327
|
+
location = detectedLocation;
|
|
302
328
|
console.log(chalk.green(`✓ Using detected location: ${location}`));
|
|
329
|
+
} else {
|
|
330
|
+
// Use custom location if provided, otherwise use detected
|
|
331
|
+
location = customLocation.trim() || detectedLocation;
|
|
332
|
+
if (customLocation.trim()) {
|
|
333
|
+
console.log(chalk.green(`✓ Using custom location: ${location}`));
|
|
334
|
+
} else {
|
|
335
|
+
console.log(chalk.green(`✓ Using detected location: ${location}`));
|
|
336
|
+
}
|
|
303
337
|
}
|
|
304
338
|
} catch (error) {
|
|
305
339
|
console.log(chalk.yellow(`\n⚠️ Prompt error, using detected location: ${detectedLocation}`));
|
package/package.json
CHANGED
package/src/energy-data.js
CHANGED
|
@@ -6,8 +6,16 @@
|
|
|
6
6
|
|
|
7
7
|
import fetch from 'node-fetch';
|
|
8
8
|
import dotenv from 'dotenv';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import { dirname } from 'path';
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
// Get the directory of this module
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
|
|
17
|
+
// Load .env from project root (one level up from src/)
|
|
18
|
+
dotenv.config({ path: path.join(__dirname, '..', '.env') });
|
|
11
19
|
|
|
12
20
|
const EIA_API_KEY = process.env.EIA_API_KEY;
|
|
13
21
|
const EIA_BASE_URL = 'https://api.eia.gov/v2';
|