decharge-scout 2.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/oracle.js +31 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decharge-scout",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "AI-powered energy grid data scout with Solana integration",
5
5
  "main": "index.js",
6
6
  "type": "module",
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(wallet.publicKey);
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: ${wallet.publicKey.toBase58()}`);
47
+ console.warn(` Wallet: ${publicKey.toBase58()}`);
36
48
  console.warn(`\n💡 To get devnet SOL:`);
37
- console.warn(` 1. solana airdrop 1 ${wallet.publicKey.toBase58()} --url devnet`);
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
- const dataBuffer = Buffer.from(dataJSON);
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 = dataBuffer.length > MAX_MEMO_SIZE
59
- ? dataBuffer.slice(0, MAX_MEMO_SIZE)
60
- : dataBuffer;
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