decharge-scout 2.5.0 → 2.5.4
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/package.json +1 -1
- package/src/oracle.js +36 -11
package/package.json
CHANGED
package/src/oracle.js
CHANGED
|
@@ -19,10 +19,27 @@ import crypto from 'crypto';
|
|
|
19
19
|
*/
|
|
20
20
|
export async function submitToOracle(wallet, submissionData) {
|
|
21
21
|
try {
|
|
22
|
+
console.log(`[DEBUG] submitToOracle called with wallet type: ${typeof wallet}, value: ${wallet}`);
|
|
23
|
+
|
|
22
24
|
const connection = getConnection();
|
|
23
25
|
|
|
26
|
+
// Handle both wallet object and wallet address string
|
|
27
|
+
let publicKey;
|
|
28
|
+
if (typeof wallet === 'string') {
|
|
29
|
+
// wallet is a base58 address string
|
|
30
|
+
console.log(`[DEBUG] Converting string address to PublicKey: ${wallet}`);
|
|
31
|
+
publicKey = new PublicKey(wallet);
|
|
32
|
+
console.log(`[DEBUG] PublicKey created successfully: ${publicKey ? publicKey.toBase58() : 'UNDEFINED'}`);
|
|
33
|
+
} else if (wallet?.publicKey) {
|
|
34
|
+
// wallet is a Keypair or wallet object
|
|
35
|
+
publicKey = wallet.publicKey;
|
|
36
|
+
console.log(`[DEBUG] Using wallet.publicKey: ${publicKey ? publicKey.toBase58() : 'UNDEFINED'}`);
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error(`Invalid wallet parameter: expected string address or wallet object, got ${typeof wallet}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
24
41
|
// Check wallet balance first
|
|
25
|
-
const balance = await connection.getBalance(
|
|
42
|
+
const balance = await connection.getBalance(publicKey);
|
|
26
43
|
const balanceSOL = balance / 1000000000; // Convert lamports to SOL
|
|
27
44
|
|
|
28
45
|
// Minimum balance needed: 0.01 SOL for transaction + fees
|
|
@@ -32,9 +49,9 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
32
49
|
console.warn(`\n⚠️ Insufficient funds for oracle submission`);
|
|
33
50
|
console.warn(` Current balance: ${balanceSOL.toFixed(4)} SOL`);
|
|
34
51
|
console.warn(` Required: ${minRequired} SOL`);
|
|
35
|
-
console.warn(` Wallet: ${
|
|
52
|
+
console.warn(` Wallet: ${publicKey.toBase58()}`);
|
|
36
53
|
console.warn(`\n💡 To get devnet SOL:`);
|
|
37
|
-
console.warn(` 1. solana airdrop 1 ${
|
|
54
|
+
console.warn(` 1. solana airdrop 1 ${publicKey.toBase58()} --url devnet`);
|
|
38
55
|
console.warn(` 2. Or visit: https://faucet.solana.com/`);
|
|
39
56
|
console.warn(`\n📝 Using mock signature for demo purposes...\n`);
|
|
40
57
|
return 'MOCK_ORACLE_TX_' + Date.now() + '_' + crypto.randomBytes(16).toString('hex');
|
|
@@ -45,7 +62,18 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
45
62
|
|
|
46
63
|
// Create instruction data (serialize as JSON then to buffer)
|
|
47
64
|
const dataJSON = JSON.stringify(anonymizedData);
|
|
48
|
-
|
|
65
|
+
|
|
66
|
+
// Log for verification
|
|
67
|
+
console.log(`Oracle submission data: ${dataJSON.slice(0, 200)}...`);
|
|
68
|
+
|
|
69
|
+
// If using browser wallet (wallet is a string), we can't sign server-side
|
|
70
|
+
// In production, this would be sent to browser for signing via WebSocket
|
|
71
|
+
if (typeof wallet === 'string') {
|
|
72
|
+
console.log(`\n📝 Browser wallet detected - creating mock submission...`);
|
|
73
|
+
console.log(` Wallet: ${publicKey.toBase58()}`);
|
|
74
|
+
console.log(` Data: ${dataJSON.length} bytes`);
|
|
75
|
+
return 'MOCK_ORACLE_TX_' + Date.now() + '_' + crypto.randomBytes(16).toString('hex');
|
|
76
|
+
}
|
|
49
77
|
|
|
50
78
|
// For demo, we'll send just a memo transaction (no transfer needed)
|
|
51
79
|
// In production, this would call a custom Solana program
|
|
@@ -55,9 +83,9 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
55
83
|
|
|
56
84
|
// Add memo instruction with our data (truncate if needed for tx size limits)
|
|
57
85
|
const MAX_MEMO_SIZE = 566; // Solana memo size limit
|
|
58
|
-
const memoData =
|
|
59
|
-
?
|
|
60
|
-
:
|
|
86
|
+
const memoData = Buffer.from(dataJSON).length > MAX_MEMO_SIZE
|
|
87
|
+
? Buffer.from(dataJSON).slice(0, MAX_MEMO_SIZE)
|
|
88
|
+
: Buffer.from(dataJSON);
|
|
61
89
|
|
|
62
90
|
// Create simple memo instruction
|
|
63
91
|
const memoInstruction = new TransactionInstruction({
|
|
@@ -68,7 +96,7 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
68
96
|
|
|
69
97
|
transaction.add(memoInstruction);
|
|
70
98
|
|
|
71
|
-
// Send transaction
|
|
99
|
+
// Send transaction (only works with keypair wallet, not browser wallet)
|
|
72
100
|
const signature = await sendAndConfirmTransaction(
|
|
73
101
|
connection,
|
|
74
102
|
transaction,
|
|
@@ -79,9 +107,6 @@ export async function submitToOracle(wallet, submissionData) {
|
|
|
79
107
|
}
|
|
80
108
|
);
|
|
81
109
|
|
|
82
|
-
// Log for verification
|
|
83
|
-
console.log(`Oracle submission data: ${dataJSON.slice(0, 200)}...`);
|
|
84
|
-
|
|
85
110
|
return signature;
|
|
86
111
|
} catch (error) {
|
|
87
112
|
// If transaction fails (e.g., insufficient funds), create mock signature
|