aether-hub 1.2.6 → 1.2.7

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.
@@ -14,11 +14,10 @@
14
14
  * aether-cli network --rpc <url> # Query a specific RPC endpoint
15
15
  * aether-cli network --peers # Detailed peer list
16
16
  * aether-cli network --epoch # Current epoch and consensus info
17
+ *
18
+ * Uses @jellylegsai/aether-sdk for real blockchain RPC calls to http://127.0.0.1:8899
17
19
  */
18
20
 
19
- const http = require('http');
20
- const https = require('https');
21
-
22
21
  // ANSI colours
23
22
  const C = {
24
23
  reset: '\x1b[0m',
@@ -33,85 +32,12 @@ const C = {
33
32
  white: '\x1b[37m',
34
33
  };
35
34
 
36
- const DEFAULT_RPC = process.env.AETHER_RPC || 'http://127.0.0.1:8899';
37
-
38
- // ---------------------------------------------------------------------------
39
- // HTTP helpers
40
- // ---------------------------------------------------------------------------
41
-
42
- function httpRequest(rpcUrl, path, options = {}) {
43
- return new Promise((resolve, reject) => {
44
- const url = new URL(path, rpcUrl);
45
- const isHttps = url.protocol === 'https:';
46
- const lib = isHttps ? https : http;
47
-
48
- const reqOptions = {
49
- hostname: url.hostname,
50
- port: url.port || (isHttps ? 443 : 80),
51
- path: url.pathname + url.search,
52
- method: 'GET',
53
- timeout: 5000,
54
- headers: { 'Content-Type': 'application/json' },
55
- };
56
-
57
- const req = lib.request(reqOptions, (res) => {
58
- let data = '';
59
- res.on('data', (chunk) => (data += chunk));
60
- res.on('end', () => {
61
- try {
62
- resolve(JSON.parse(data));
63
- } catch {
64
- resolve({ raw: data });
65
- }
66
- });
67
- });
68
-
69
- req.on('error', reject);
70
- req.on('timeout', () => {
71
- req.destroy();
72
- reject(new Error('Request timeout'));
73
- });
74
-
75
- req.end();
76
- });
77
- }
35
+ // Import SDK for real blockchain RPC calls
36
+ const path = require('path');
37
+ const sdkPath = path.join(__dirname, '..', 'sdk', 'index.js');
38
+ const aether = require(sdkPath);
78
39
 
79
- function httpPost(rpcUrl, path, body) {
80
- return new Promise((resolve, reject) => {
81
- const url = new URL(path, rpcUrl);
82
- const isHttps = url.protocol === 'https:';
83
- const lib = isHttps ? https : http;
84
- const bodyStr = JSON.stringify(body);
85
-
86
- const req = lib.request({
87
- hostname: url.hostname,
88
- port: url.port || (isHttps ? 443 : 80),
89
- path: url.pathname + url.search,
90
- method: 'POST',
91
- timeout: 5000,
92
- headers: {
93
- 'Content-Type': 'application/json',
94
- 'Content-Length': Buffer.byteLength(bodyStr),
95
- },
96
- }, (res) => {
97
- let data = '';
98
- res.on('data', (chunk) => (data += chunk));
99
- res.on('end', () => {
100
- try { resolve(JSON.parse(data)); }
101
- catch { resolve(data); }
102
- });
103
- });
104
-
105
- req.on('error', reject);
106
- req.on('timeout', () => {
107
- req.destroy();
108
- reject(new Error('Request timeout'));
109
- });
110
-
111
- req.write(bodyStr);
112
- req.end();
113
- });
114
- }
40
+ const DEFAULT_RPC = process.env.AETHER_RPC || aether.DEFAULT_RPC_URL || 'http://127.0.0.1:8899';
115
41
 
116
42
  // ---------------------------------------------------------------------------
117
43
  // Argument parsing
@@ -168,79 +94,79 @@ ${C.bright}Examples:${C.reset}
168
94
  }
169
95
 
170
96
  // ---------------------------------------------------------------------------
171
- // Network data fetchers
97
+ // Network data fetchers using SDK (real blockchain RPC calls)
172
98
  // ---------------------------------------------------------------------------
173
99
 
174
- /** GET /v1/slot current network slot */
100
+ /** Create SDK client for custom RPC */
101
+ function createClient(rpc) {
102
+ return new aether.AetherClient({ rpcUrl: rpc });
103
+ }
104
+
105
+ /** GET /v1/slot — current network slot (via SDK) */
175
106
  async function getSlot(rpc) {
176
107
  try {
177
- const res = await httpRequest(rpc, '/v1/slot');
178
- return res.slot ?? res.root_slot ?? null;
108
+ const client = createClient(rpc);
109
+ return await client.getSlot();
179
110
  } catch {
180
111
  return null;
181
112
  }
182
113
  }
183
114
 
184
- /** GET /v1/block_height — current network block height */
115
+ /** GET /v1/blockheight — current network block height (via SDK) */
185
116
  async function getBlockHeight(rpc) {
186
117
  try {
187
- const res = await httpRequest(rpc, '/v1/block_height');
188
- return res.block_height ?? null;
118
+ const client = createClient(rpc);
119
+ return await client.getBlockHeight();
189
120
  } catch {
190
121
  return null;
191
122
  }
192
123
  }
193
124
 
194
- /** GET /v1/validators — list of validators / peers */
125
+ /** GET /v1/validators — list of validators / peers (via SDK) */
195
126
  async function getValidators(rpc) {
196
127
  try {
197
- const res = await httpRequest(rpc, '/v1/validators');
198
- if (res.validators && Array.isArray(res.validators)) {
199
- return res.validators;
200
- }
201
- if (Array.isArray(res)) return res;
202
- return [];
128
+ const client = createClient(rpc);
129
+ return await client.getValidators();
203
130
  } catch {
204
131
  return [];
205
132
  }
206
133
  }
207
134
 
208
- /** GET /v1/epoch — current epoch and consensus info */
135
+ /** GET /v1/epoch — current epoch and consensus info (via SDK) */
209
136
  async function getEpoch(rpc) {
210
137
  try {
211
- const res = await httpRequest(rpc, '/v1/epoch');
212
- return res;
138
+ const client = createClient(rpc);
139
+ return await client.getEpochInfo();
213
140
  } catch {
214
141
  return null;
215
142
  }
216
143
  }
217
144
 
218
- /** POST /v1/slot_production — slot production stats */
145
+ /** POST /v1/slot_production — slot production stats (via SDK) */
219
146
  async function getSlotProduction(rpc) {
220
147
  try {
221
- // Try slot production endpoint
222
- const res = await httpPost(rpc, '/v1/slot_production', {});
223
- return res;
148
+ const client = createClient(rpc);
149
+ return await client.getSlotProduction();
224
150
  } catch {
225
151
  return null;
226
152
  }
227
153
  }
228
154
 
229
- /** GET /v1/tps — TPS estimate from network */
155
+ /** GET /v1/tps — TPS estimate from network (via SDK) */
230
156
  async function getTPS(rpc) {
231
157
  try {
232
- const res = await httpRequest(rpc, '/v1/tps');
233
- return res.tps ?? res.tps_avg ?? res.transactions_per_second ?? null;
158
+ const client = createClient(rpc);
159
+ return await client.getTPS();
234
160
  } catch {
235
161
  return null;
236
162
  }
237
163
  }
238
164
 
239
- /** GET /v1/supply — token supply info */
165
+ /** GET /v1/supply — token supply info (via SDK) */
240
166
  async function getSupply(rpc) {
241
167
  try {
242
- const res = await httpRequest(rpc, '/v1/supply');
243
- return res;
168
+ const client = createClient(rpc);
169
+ return await client.getSupply();
244
170
  } catch {
245
171
  return null;
246
172
  }
package/commands/ping.js CHANGED
@@ -5,6 +5,8 @@
5
5
  * Quick RPC health check — measures latency, verifies connectivity,
6
6
  * and reports node version and slot info.
7
7
  *
8
+ * Uses @jellylegsai/aether-sdk for REAL HTTP RPC calls.
9
+ *
8
10
  * Usage:
9
11
  * aether ping Ping default RPC (AETHER_RPC or localhost:8899)
10
12
  * aether ping --rpc <url> Ping a specific RPC endpoint
@@ -17,8 +19,9 @@
17
19
  * aether ping --count 5 --json # 5 pings, JSON output for alerting
18
20
  */
19
21
 
20
- const http = require('http');
21
- const https = require('https');
22
+ const path = require('path');
23
+ const sdkPath = path.join(__dirname, '..', 'sdk', 'index.js');
24
+ const aether = require(sdkPath);
22
25
 
23
26
  // ANSI colours
24
27
  const C = {
@@ -38,82 +41,25 @@ const CLI_VERSION = '1.0.6';
38
41
  // ---------------------------------------------------------------------------
39
42
 
40
43
  function getDefaultRpc() {
41
- return process.env.AETHER_RPC || 'http://127.0.0.1:8899';
42
- }
43
-
44
- function httpRequest(rpcUrl, pathStr, timeoutMs = 8000) {
45
- return new Promise((resolve, reject) => {
46
- const url = new URL(pathStr, rpcUrl);
47
- const lib = url.protocol === 'https:' ? https : http;
48
- const req = lib.request({
49
- hostname: url.hostname,
50
- port: url.port || (url.protocol === 'https:' ? 443 : 80),
51
- path: url.pathname + url.search,
52
- method: 'GET',
53
- timeout: timeoutMs,
54
- headers: { 'Content-Type': 'application/json' },
55
- }, (res) => {
56
- let data = '';
57
- res.on('data', (chunk) => data += chunk);
58
- res.on('end', () => {
59
- try { resolve(JSON.parse(data)); }
60
- catch { resolve({ raw: data }); }
61
- });
62
- });
63
- req.on('error', reject);
64
- req.on('timeout', () => { req.destroy(); reject(new Error('Request timeout')); });
65
- req.end();
66
- });
67
- }
68
-
69
- function httpPost(rpcUrl, pathStr, body, timeoutMs = 8000) {
70
- return new Promise((resolve, reject) => {
71
- const url = new URL(pathStr, rpcUrl);
72
- const lib = url.protocol === 'https:' ? https : http;
73
- const bodyStr = JSON.stringify(body);
74
- const req = lib.request({
75
- hostname: url.hostname,
76
- port: url.port || (url.protocol === 'https:' ? 443 : 80),
77
- path: url.pathname + url.search,
78
- method: 'POST',
79
- timeout: timeoutMs,
80
- headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(bodyStr) },
81
- }, (res) => {
82
- let data = '';
83
- res.on('data', (chunk) => data += chunk);
84
- res.on('end', () => {
85
- try { resolve(JSON.parse(data)); }
86
- catch { resolve({ raw: data }); }
87
- });
88
- });
89
- req.on('error', reject);
90
- req.on('timeout', () => { req.destroy(); reject(new Error('Request timeout')); });
91
- req.write(bodyStr);
92
- req.end();
93
- });
44
+ return process.env.AETHER_RPC || aether.DEFAULT_RPC_URL || 'http://127.0.0.1:8899';
94
45
  }
95
46
 
96
47
  // ---------------------------------------------------------------------------
97
- // Single ping: measure latency to /v1/slot
48
+ // Single ping: measure latency to /v1/slot using SDK
98
49
  // ---------------------------------------------------------------------------
99
50
 
100
51
  async function pingOnce(rpcUrl) {
52
+ const client = new aether.AetherClient({ rpcUrl });
101
53
  const start = Date.now();
102
54
  let slot = null;
103
55
  let error = null;
104
56
  let latencyMs = null;
105
57
 
106
58
  try {
107
- // Use POST to /v1/slot (some nodes only support POST)
108
- const result = await httpPost(rpcUrl, '/v1/slot', {}, 8000);
59
+ // Real RPC call via SDK: POST /v1/slot
60
+ const result = await client.getSlot();
109
61
  latencyMs = Date.now() - start;
110
-
111
- if (result && result.error) {
112
- error = result.error;
113
- } else {
114
- slot = result.slot ?? result;
115
- if (typeof slot === 'object') slot = slot.slot;
116
- }
62
+ slot = result;
117
63
  } catch (err) {
118
64
  latencyMs = Date.now() - start;
119
65
  error = err.message;