decharge-scout 2.3.0 → 2.5.1
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 +18 -5
- package/package.json +1 -1
- package/src/oracle.js +31 -11
package/index.js
CHANGED
|
@@ -175,15 +175,28 @@ async function main(options) {
|
|
|
175
175
|
console.log(chalk.gray('You have 30 seconds to respond...'));
|
|
176
176
|
|
|
177
177
|
try {
|
|
178
|
+
let timeoutId;
|
|
179
|
+
let hasResolved = false;
|
|
180
|
+
|
|
178
181
|
// Create a promise that auto-resolves after 30 seconds
|
|
179
182
|
const timeoutPromise = new Promise((resolve) => {
|
|
180
|
-
setTimeout(() => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
timeoutId = setTimeout(() => {
|
|
184
|
+
if (!hasResolved) {
|
|
185
|
+
hasResolved = true;
|
|
186
|
+
console.log(chalk.yellow('\n⏱️ Timeout - using detected location...'));
|
|
187
|
+
resolve('__TIMEOUT__');
|
|
188
|
+
}
|
|
183
189
|
}, 30000);
|
|
184
190
|
});
|
|
185
191
|
|
|
186
|
-
const questionPromise = question('Enter custom location (or press Enter): ')
|
|
192
|
+
const questionPromise = question('Enter custom location (or press Enter): ').then(answer => {
|
|
193
|
+
if (!hasResolved) {
|
|
194
|
+
hasResolved = true;
|
|
195
|
+
clearTimeout(timeoutId);
|
|
196
|
+
return answer;
|
|
197
|
+
}
|
|
198
|
+
return '__TIMEOUT__'; // If timeout already occurred, ignore this answer
|
|
199
|
+
});
|
|
187
200
|
|
|
188
201
|
const customLocation = await Promise.race([questionPromise, timeoutPromise]);
|
|
189
202
|
|
|
@@ -246,7 +259,7 @@ async function main(options) {
|
|
|
246
259
|
});
|
|
247
260
|
|
|
248
261
|
// Main query cycle
|
|
249
|
-
await runQueryCycle(
|
|
262
|
+
await runQueryCycle(walletAddress, agentName, location, options);
|
|
250
263
|
|
|
251
264
|
} catch (error) {
|
|
252
265
|
console.error(chalk.red(`\n❌ Error: ${error.message}`));
|
package/package.json
CHANGED
package/src/oracle.js
CHANGED
|
@@ -21,8 +21,20 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
21
21
|
try {
|
|
22
22
|
const connection = getConnection();
|
|
23
23
|
|
|
24
|
+
// Handle both wallet object and wallet address string
|
|
25
|
+
let publicKey;
|
|
26
|
+
if (typeof wallet === 'string') {
|
|
27
|
+
// wallet is a base58 address string
|
|
28
|
+
publicKey = new PublicKey(wallet);
|
|
29
|
+
} else if (wallet?.publicKey) {
|
|
30
|
+
// wallet is a Keypair or wallet object
|
|
31
|
+
publicKey = wallet.publicKey;
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error('Invalid wallet parameter: expected string address or wallet object');
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
// Check wallet balance first
|
|
25
|
-
const balance = await connection.getBalance(
|
|
37
|
+
const balance = await connection.getBalance(publicKey);
|
|
26
38
|
const balanceSOL = balance / 1000000000; // Convert lamports to SOL
|
|
27
39
|
|
|
28
40
|
// Minimum balance needed: 0.01 SOL for transaction + fees
|
|
@@ -32,9 +44,9 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
32
44
|
console.warn(`\n⚠️ Insufficient funds for oracle submission`);
|
|
33
45
|
console.warn(` Current balance: ${balanceSOL.toFixed(4)} SOL`);
|
|
34
46
|
console.warn(` Required: ${minRequired} SOL`);
|
|
35
|
-
console.warn(` Wallet: ${
|
|
47
|
+
console.warn(` Wallet: ${publicKey.toBase58()}`);
|
|
36
48
|
console.warn(`\n💡 To get devnet SOL:`);
|
|
37
|
-
console.warn(` 1. solana airdrop 1 ${
|
|
49
|
+
console.warn(` 1. solana airdrop 1 ${publicKey.toBase58()} --url devnet`);
|
|
38
50
|
console.warn(` 2. Or visit: https://faucet.solana.com/`);
|
|
39
51
|
console.warn(`\n📝 Using mock signature for demo purposes...\n`);
|
|
40
52
|
return 'MOCK_ORACLE_TX_' + Date.now() + '_' + crypto.randomBytes(16).toString('hex');
|
|
@@ -45,7 +57,18 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
45
57
|
|
|
46
58
|
// Create instruction data (serialize as JSON then to buffer)
|
|
47
59
|
const dataJSON = JSON.stringify(anonymizedData);
|
|
48
|
-
|
|
60
|
+
|
|
61
|
+
// Log for verification
|
|
62
|
+
console.log(`Oracle submission data: ${dataJSON.slice(0, 200)}...`);
|
|
63
|
+
|
|
64
|
+
// If using browser wallet (wallet is a string), we can't sign server-side
|
|
65
|
+
// In production, this would be sent to browser for signing via WebSocket
|
|
66
|
+
if (typeof wallet === 'string') {
|
|
67
|
+
console.log(`\n📝 Browser wallet detected - creating mock submission...`);
|
|
68
|
+
console.log(` Wallet: ${publicKey.toBase58()}`);
|
|
69
|
+
console.log(` Data: ${dataJSON.length} bytes`);
|
|
70
|
+
return 'MOCK_ORACLE_TX_' + Date.now() + '_' + crypto.randomBytes(16).toString('hex');
|
|
71
|
+
}
|
|
49
72
|
|
|
50
73
|
// For demo, we'll send just a memo transaction (no transfer needed)
|
|
51
74
|
// In production, this would call a custom Solana program
|
|
@@ -55,9 +78,9 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
55
78
|
|
|
56
79
|
// Add memo instruction with our data (truncate if needed for tx size limits)
|
|
57
80
|
const MAX_MEMO_SIZE = 566; // Solana memo size limit
|
|
58
|
-
const memoData =
|
|
59
|
-
?
|
|
60
|
-
:
|
|
81
|
+
const memoData = Buffer.from(dataJSON).length > MAX_MEMO_SIZE
|
|
82
|
+
? Buffer.from(dataJSON).slice(0, MAX_MEMO_SIZE)
|
|
83
|
+
: Buffer.from(dataJSON);
|
|
61
84
|
|
|
62
85
|
// Create simple memo instruction
|
|
63
86
|
const memoInstruction = new TransactionInstruction({
|
|
@@ -68,7 +91,7 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
68
91
|
|
|
69
92
|
transaction.add(memoInstruction);
|
|
70
93
|
|
|
71
|
-
// Send transaction
|
|
94
|
+
// Send transaction (only works with keypair wallet, not browser wallet)
|
|
72
95
|
const signature = await sendAndConfirmTransaction(
|
|
73
96
|
connection,
|
|
74
97
|
transaction,
|
|
@@ -79,9 +102,6 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
79
102
|
}
|
|
80
103
|
);
|
|
81
104
|
|
|
82
|
-
// Log for verification
|
|
83
|
-
console.log(`Oracle submission data: ${dataJSON.slice(0, 200)}...`);
|
|
84
|
-
|
|
85
105
|
return signature;
|
|
86
106
|
} catch (error) {
|
|
87
107
|
// If transaction fails (e.g., insufficient funds), create mock signature
|