@neuraiproject/neurai-rpc 0.4.2 → 0.4.3
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/README.md +1 -0
- package/dist/index.cjs +192 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +192 -172
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/docs.json +1 -0
- package/docs.ts +1231 -517
- package/package.json +1 -1
- package/test-getpubkey.js +149 -0
- package/neurai_methods.md +0 -4580
package/package.json
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Test real connection to local Neurai node and getpubkey RPC method
|
|
2
|
+
|
|
3
|
+
import { methods, getRPC } from './dist/index.mjs';
|
|
4
|
+
|
|
5
|
+
console.log('=== Testing getpubkey RPC Method ===\n');
|
|
6
|
+
|
|
7
|
+
// Configuration for local node
|
|
8
|
+
const username = '123';
|
|
9
|
+
const password = '123';
|
|
10
|
+
const url = 'http://127.0.0.1:19001';
|
|
11
|
+
|
|
12
|
+
// Get address from command line argument
|
|
13
|
+
const testAddress = process.argv[2];
|
|
14
|
+
|
|
15
|
+
console.log('Connecting to:', url);
|
|
16
|
+
console.log('Username:', username);
|
|
17
|
+
console.log('');
|
|
18
|
+
|
|
19
|
+
// Initialize RPC connection
|
|
20
|
+
const rpc = getRPC(username, password, url);
|
|
21
|
+
|
|
22
|
+
// First, test basic connection with getblockcount
|
|
23
|
+
console.log('1. Testing basic connection with getblockcount...');
|
|
24
|
+
try {
|
|
25
|
+
const blockCount = await rpc('getblockcount', []);
|
|
26
|
+
console.log('✓ Connection successful!');
|
|
27
|
+
console.log(' Current block count:', blockCount);
|
|
28
|
+
console.log('');
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.log('✗ Connection failed!');
|
|
31
|
+
console.log(' Error:', error.error ? error.error.message : error.message);
|
|
32
|
+
console.log('');
|
|
33
|
+
console.log('Please verify:');
|
|
34
|
+
console.log(' 1. Neurai node is running');
|
|
35
|
+
console.log(' 2. RPC server is enabled');
|
|
36
|
+
console.log(' 3. Username and password are correct in neurai.conf');
|
|
37
|
+
console.log(' 4. rpcallowip is configured (e.g., rpcallowip=127.0.0.1)');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Test getpubkey method
|
|
42
|
+
console.log('2. Testing getpubkey method...');
|
|
43
|
+
console.log('');
|
|
44
|
+
|
|
45
|
+
if (testAddress) {
|
|
46
|
+
// Test with provided address
|
|
47
|
+
console.log(` Testing address: ${testAddress}`);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const result = await rpc('getpubkey', [testAddress]);
|
|
51
|
+
|
|
52
|
+
console.log(' ✓ Success!');
|
|
53
|
+
console.log(' - Address:', result.address);
|
|
54
|
+
console.log(' - Revealed:', result.revealed);
|
|
55
|
+
|
|
56
|
+
if (result.revealed) {
|
|
57
|
+
console.log(' - Public Key:', result.pubkey);
|
|
58
|
+
console.log(' - Height:', result.height);
|
|
59
|
+
console.log(' - TxID:', result.txid);
|
|
60
|
+
} else {
|
|
61
|
+
console.log(' - Note: This address has not spent funds yet');
|
|
62
|
+
console.log(' Public key will be revealed after first spend');
|
|
63
|
+
}
|
|
64
|
+
console.log('');
|
|
65
|
+
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error.error && error.error.message) {
|
|
68
|
+
if (error.error.message.includes('Pubkey index not enabled')) {
|
|
69
|
+
console.log(' ✗ Error: Pubkey index not enabled');
|
|
70
|
+
console.log(' Add "pubkeyindex=1" to your neurai.conf and restart the node');
|
|
71
|
+
console.log(' Then reindex with: neurai-cli -reindex');
|
|
72
|
+
} else if (error.error.message.includes('Invalid address')) {
|
|
73
|
+
console.log(' ✗ Error: Invalid address');
|
|
74
|
+
console.log(' Please provide a valid Neurai address');
|
|
75
|
+
} else {
|
|
76
|
+
console.log(' ✗ Error:', error.error.message);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
console.log(' ✗ Error:', error.message || error);
|
|
80
|
+
}
|
|
81
|
+
console.log('');
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
// Test with addresses from wallet
|
|
85
|
+
console.log(' No address provided, checking wallet addresses...');
|
|
86
|
+
console.log('');
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const addresses = await rpc('listreceivedbyaddress', [0, true]);
|
|
90
|
+
|
|
91
|
+
if (addresses.length === 0) {
|
|
92
|
+
console.log(' No addresses found in wallet.');
|
|
93
|
+
console.log(' Generate a new address with: neurai-cli getnewaddress');
|
|
94
|
+
console.log(' Or provide an address: node test-getpubkey.js <address>');
|
|
95
|
+
console.log('');
|
|
96
|
+
} else {
|
|
97
|
+
console.log(` Found ${addresses.length} addresses in wallet`);
|
|
98
|
+
console.log(' Testing first 3 addresses...');
|
|
99
|
+
console.log('');
|
|
100
|
+
|
|
101
|
+
const testAddresses = addresses.slice(0, 3);
|
|
102
|
+
|
|
103
|
+
for (const addrInfo of testAddresses) {
|
|
104
|
+
const address = addrInfo.address;
|
|
105
|
+
console.log(` Testing address: ${address}`);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const result = await rpc('getpubkey', [address]);
|
|
109
|
+
|
|
110
|
+
console.log(' ✓ Success!');
|
|
111
|
+
console.log(' - Revealed:', result.revealed);
|
|
112
|
+
|
|
113
|
+
if (result.revealed) {
|
|
114
|
+
console.log(' - Public Key:', result.pubkey);
|
|
115
|
+
console.log(' - Height:', result.height);
|
|
116
|
+
console.log(' - TxID:', result.txid);
|
|
117
|
+
} else {
|
|
118
|
+
console.log(' - Note: This address has not spent funds yet');
|
|
119
|
+
console.log(' Public key will be revealed after first spend');
|
|
120
|
+
}
|
|
121
|
+
console.log('');
|
|
122
|
+
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (error.error && error.error.message) {
|
|
125
|
+
if (error.error.message.includes('Pubkey index not enabled')) {
|
|
126
|
+
console.log(' ✗ Error: Pubkey index not enabled');
|
|
127
|
+
console.log(' Add "pubkeyindex=1" to your neurai.conf and restart the node');
|
|
128
|
+
console.log(' Then reindex with: neurai-cli -reindex');
|
|
129
|
+
break;
|
|
130
|
+
} else {
|
|
131
|
+
console.log(' ✗ Error:', error.error.message);
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
console.log(' ✗ Error:', error.message || error);
|
|
135
|
+
}
|
|
136
|
+
console.log('');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.log(' Error getting addresses:', error.error ? error.error.message : error.message);
|
|
142
|
+
console.log('');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('=== Test Complete ===');
|
|
147
|
+
console.log('');
|
|
148
|
+
console.log('Usage: node test-getpubkey.js [address]');
|
|
149
|
+
console.log('Example: node test-getpubkey.js NTVDv81nvwEKpCqhrNwjypTEKMYdpiDKKV');
|