aether-hub 1.2.7 → 1.2.8

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.
@@ -1,462 +1,346 @@
1
- #!/usr/bin/env node
2
- /**
3
- * aether-cli tx-history
4
- *
5
- * Fetch and display transaction history for an Aether wallet address.
6
- * Shows recent transactions with type, amount, timestamp, fee, and status.
7
- *
8
- * Usage:
9
- * aether tx history --address <addr> [--limit <n>] [--json] [--rpc <url>]
10
- * aether history --address <addr> [--limit <n>] [--json]
11
- *
12
- * Examples:
13
- * aether tx history --address ATHxxx
14
- * aether tx history --address ATHxxx --limit 50 --json
15
- * aether history --address ATHxxx --rpc https://rpc.aether.io
16
- */
17
-
18
- const path = require('path');
19
-
20
- // Import SDK for real blockchain RPC calls
21
- const sdkPath = path.join(__dirname, '..', 'sdk', 'index.js');
22
- const aether = require(sdkPath);
23
-
24
- // ANSI colours
25
- const C = {
26
- reset: '\x1b[0m',
27
- bright: '\x1b[1m',
28
- dim: '\x1b[2m',
29
- red: '\x1b[31m',
30
- green: '\x1b[32m',
31
- yellow: '\x1b[33m',
32
- cyan: '\x1b[36m',
33
- magenta: '\x1b[35m',
34
- };
35
-
36
- const CLI_VERSION = '1.0.0';
37
-
38
- // ---------------------------------------------------------------------------
39
- // SDK helpers - Real blockchain RPC calls via Aether SDK
40
- // ---------------------------------------------------------------------------
41
-
42
- function getDefaultRpc() {
43
- return process.env.AETHER_RPC || aether.DEFAULT_RPC_URL || 'http://127.0.0.1:8899';
44
- }
45
-
46
- function createClient(rpcUrl) {
47
- return new aether.AetherClient({ rpcUrl });
48
- }
49
-
50
- // ---------------------------------------------------------------------------
51
- // Argument parsing
52
- // ---------------------------------------------------------------------------
53
-
54
- function parseArgs() {
55
- const args = process.argv.slice(2);
56
- const result = { address: null, limit: 20, json: false, rpc: null };
57
-
58
- for (let i = 0; i < args.length; i++) {
59
- const arg = args[i];
60
- if ((arg === '--address' || arg === '-a') && args[i + 1] && !args[i + 1].startsWith('-')) {
61
- result.address = args[i + 1];
62
- i++;
63
- } else if ((arg === '--limit' || arg === '-l') && args[i + 1] && !args[i + 1].startsWith('-')) {
64
- result.limit = parseInt(args[i + 1], 10);
65
- i++;
66
- } else if (arg === '--json' || arg === '--json-output') {
67
- result.json = true;
68
- } else if (arg === '--rpc' && args[i + 1] && !args[i + 1].startsWith('-')) {
69
- result.rpc = args[i + 1];
70
- i++;
71
- } else if (arg === '--help' || arg === '-h') {
72
- result.help = true;
73
- }
74
- }
75
-
76
- return result;
77
- }
78
-
79
- // ---------------------------------------------------------------------------
80
- // Formatting helpers
81
- // ---------------------------------------------------------------------------
82
-
83
- function formatAether(lamports) {
84
- if (lamports == null) return '—';
85
- const aeth = lamports / 1e9;
86
- if (aeth === 0) return '0 AETH';
87
- return aeth.toFixed(4).replace(/\.?0+$/, '') + ' AETH';
88
- }
89
-
90
- function formatTimestamp(slot, blockTime) {
91
- if (!blockTime) return '—';
92
- try {
93
- const d = new Date(blockTime * 1000);
94
- return d.toISOString().replace('T', ' ').slice(0, 19);
95
- } catch {
96
- return String(blockTime);
97
- }
98
- }
99
-
100
- function shortAddress(addr) {
101
- if (!addr) return '—';
102
- if (addr.length <= 16) return addr;
103
- return addr.slice(0, 8) + '…' + addr.slice(-6);
104
- }
105
-
106
- function formatTxType(type) {
107
- const t = (type || 'unknown').toLowerCase();
108
- if (t.includes('transfer') || t.includes('send') || t.includes('payment')) return { label: 'TRANSFER', color: C.cyan };
109
- if (t.includes('stake') || t.includes('delegate')) return { label: 'STAKE', color: C.green };
110
- if (t.includes('unstake') || t.includes('deactivate')) return { label: 'UNSTAKE', color: C.yellow };
111
- if (t.includes('reward') || t.includes('mint')) return { label: 'REWARD', color: C.magenta };
112
- if (t.includes('vote')) return { label: 'VOTE', color: C.bright };
113
- if (t.includes('create') || t.includes('initialize')) return { label: 'CREATE', color: C.bright };
114
- if (t.includes('burn')) return { label: 'BURN', color: C.red };
115
- return { label: type ? type.toUpperCase().slice(0, 10) : 'TX', color: C.dim };
116
- }
117
-
118
- function formatStatus(status) {
119
- if (!status) return { label: '—', color: C.dim };
120
- const s = status.toLowerCase();
121
- if (s === 'success' || s === 'finalized' || s === 'confirmed') {
122
- return { label: '✓ OK', color: C.green };
123
- }
124
- if (s === 'pending' || s === 'processing') {
125
- return { label: '⏳', color: C.yellow };
126
- }
127
- if (s === 'failed') {
128
- return { label: '✗ FAIL', color: C.red };
129
- }
130
- return { label: status.slice(0, 8), color: C.dim };
131
- }
132
-
133
- // ---------------------------------------------------------------------------
134
- // Core RPC calls
135
- // ---------------------------------------------------------------------------
136
-
137
- /**
138
- * Fetch confirmed transaction signatures for an address using getSignaturesForAddress.
139
- */
140
- async function fetchTxSignatures(rpcUrl, address, limit) {
141
- const body = {
142
- jsonrpc: '2.0',
143
- id: 1,
144
- method: 'getSignaturesForAddress',
145
- params: [
146
- address,
147
- { limit },
148
- ],
149
- };
150
- return httpPost(rpcUrl, '/', body);
151
- }
152
-
153
- /**
154
- * Fetch a specific confirmed transaction by signature.
155
- */
156
- async function fetchTx(rpcUrl, signature) {
157
- const body = {
158
- jsonrpc: '2.0',
159
- id: 1,
160
- method: 'getTransaction',
161
- params: [
162
- signature,
163
- { encoding: 'jsonParsed', maxSupportedTransactionVersion: 0 },
164
- ],
165
- };
166
- return httpPost(rpcUrl, '/', body);
167
- }
168
-
169
- /**
170
- * Parse a transaction result into a normalized display object.
171
- */
172
- function parseTransaction(txResult, sigInfo) {
173
- const blockTime = sigInfo.blockTime || txResult.blockTime;
174
- const slot = sigInfo.slot;
175
- const status = sigInfo.err ? 'failed' : (sigInfo.confirmationStatus || 'confirmed');
176
-
177
- let txType = 'unknown';
178
- let amount = 0;
179
- let fee = txResult.meta?.fee || 0;
180
- let fromAddr = null;
181
- let toAddr = null;
182
- let memo = null;
183
-
184
- try {
185
- const msg = txResult.transaction?.message;
186
- if (msg) {
187
- // Parse instructions for transfer/stake types
188
- const instructions = msg.instructions || [];
189
- for (const ix of instructions) {
190
- const programId = ix.programId || (ix.parsed && ix.parsed.info && ix.parsed.type);
191
- // Native transfer
192
- if (ix.parsed && ix.parsed.type === 'transfer') {
193
- txType = 'transfer';
194
- const info = ix.parsed.info;
195
- fromAddr = info.source || info.from;
196
- toAddr = info.destination || info.to;
197
- amount = info.lamports || info.amount || 0;
198
- } else if (ix.parsed && ix.parsed.type === 'stake') {
199
- txType = 'stake';
200
- const info = ix.parsed.info;
201
- fromAddr = info.from || info.funder;
202
- toAddr = info.validator;
203
- amount = info.lamports || info.amount || 0;
204
- } else if (ix.parsed && ix.parsed.type === 'withdrawStake') {
205
- txType = 'unstake';
206
- const info = ix.parsed.info;
207
- toAddr = info.destination || info.withdrawer;
208
- amount = info.lamports || info.amount || 0;
209
- } else if (ix.parsed && ix.parsed.type === 'vote') {
210
- txType = 'vote';
211
- } else if (ix.parsed && ix.parsed.type === 'initialize') {
212
- txType = 'initialize';
213
- } else if (ix.parsed && ix.parsed.type === 'createAccount') {
214
- txType = 'create';
215
- } else if (ix.parsed && ix.parsed.type === 'approve') {
216
- txType = 'stake';
217
- const info = ix.parsed.info || {};
218
- fromAddr = info.from || info.owner;
219
- toAddr = info.stake;
220
- amount = info.amount || info.lamports || 0;
221
- } else if (ix.parsed && ix.parsed.type === 'delegate') {
222
- txType = 'stake';
223
- const info = ix.parsed.info || {};
224
- fromAddr = info.stake || info.from;
225
- toAddr = info.validator;
226
- amount = info.lamports || 0;
227
- } else if (ix.parsed && ix.parsed.type === 'withdraw') {
228
- txType = 'unstake';
229
- const info = ix.parsed.info || {};
230
- toAddr = info.destination;
231
- amount = info.lamports || 0;
232
- }
233
- // Check memo
234
- if (ix.memo) memo = ix.memo;
235
- }
236
-
237
- // Fallback: try legacy instructions if no parsed instructions
238
- if (!instructions.length || instructions.every(ix => !ix.parsed)) {
239
- for (const ix of instructions) {
240
- if (ix.data === 'AAAA' || ix.data === '2ugJ4ELK3wW9qNXH' || !ix.data) {
241
- txType = 'transfer';
242
- }
243
- }
244
- }
245
-
246
- // Compute fee
247
- if (txResult.meta) {
248
- fee = txResult.meta.fee || 0;
249
- if (txResult.meta.postBalances && txResult.meta.preBalances) {
250
- // Try to detect native transfer from balance changes
251
- for (let i = 0; i < txResult.meta.postBalances.length; i++) {
252
- const diff = txResult.meta.postBalances[i] - txResult.meta.preBalances[i];
253
- if (diff < 0) {
254
- amount = Math.abs(diff);
255
- if (!fromAddr) fromAddr = msg.accountKeys?.[i];
256
- } else if (diff > 0 && amount === 0) {
257
- if (!toAddr) toAddr = msg.accountKeys?.[i];
258
- }
259
- }
260
- }
261
- }
262
- }
263
- } catch (e) {
264
- // Parsing failed — use defaults
265
- }
266
-
267
- return {
268
- signature: sigInfo.signature || sigInfo.signatures?.[0],
269
- slot,
270
- blockTime,
271
- status,
272
- type: txType,
273
- amount,
274
- fee,
275
- from: fromAddr,
276
- to: toAddr,
277
- memo,
278
- };
279
- }
280
-
281
- // ---------------------------------------------------------------------------
282
- // Display
283
- // ---------------------------------------------------------------------------
284
-
285
- function displayTxTable(txs) {
286
- // Header
287
- console.log(
288
- `\n${C.bright}${C.cyan} ╔══════════════════════════════════════════════════════════════════════════════════════════╗${C.reset}\n` +
289
- ` ║${C.bright} ${C.cyan}Transaction History${C.reset}${C.bright} ║${C.reset}\n` +
290
- ` ${C.cyan}╚══════════════════════════════════════════════════════════════════════════════════════════${C.reset}`
291
- );
292
-
293
- if (txs.length === 0) {
294
- console.log(`\n ${C.yellow}No transactions found for this address.${C.reset}\n`);
295
- return;
296
- }
297
-
298
- console.log(
299
- ` ${C.dim}┌────┬──────────────────────┬──────────┬───────────────┬────────────┬────────┬───────────┐${C.reset}\n` +
300
- ` ${C.dim}│ # │ ${C.reset}Timestamp ${C.dim}│ ${C.reset}Type ${C.dim}│ ${C.reset}Amount ${C.dim}│ ${C.reset}From ${C.dim}│ ${C.reset}To ${C.dim}│ ${C.reset}Status ${C.dim}│${C.reset}`
301
- );
302
-
303
- for (let i = 0; i < txs.length; i++) {
304
- const tx = txs[i];
305
- const num = String(i + 1).padStart(3);
306
- const time = formatTimestamp(tx.blockTime).slice(0, 19).padEnd(19);
307
- const typeInfo = formatTxType(tx.type);
308
- const type = typeInfo.label.padEnd(10);
309
- const amt = tx.amount > 0 ? formatAether(tx.amount).padEnd(13) : '—'.padEnd(13);
310
- const from = shortAddress(tx.from || '').padEnd(11);
311
- const to = shortAddress(tx.to || '').padEnd(11);
312
- const statusInfo = formatStatus(tx.status);
313
- const status = statusInfo.label;
314
-
315
- const bgAlt = (i % 2 === 0) ? '' : C.dim;
316
- const reset = C.reset + bgAlt;
317
-
318
- console.log(
319
- ` ${bgAlt}${C.dim}├────┼──────────────────────┼──────────┼───────────────┼────────────┼────────┼───────────┤${reset}`
320
- );
321
- console.log(
322
- ` ${bgAlt}${C.dim}│${reset} ${num} ${bgAlt}${C.dim}│ ${reset}${time} ${bgAlt}${C.dim}│ ${reset}${typeInfo.color}${type}${reset} ${bgAlt}${C.dim}│ ${reset}${amt} ${bgAlt}${C.dim}│ ${reset}${from} ${bgAlt}${C.dim}│ ${reset}${to} ${bgAlt}${C.dim}│ ${reset}${statusInfo.color}${status}${reset}${bgAlt} │${reset}`
323
- );
324
- }
325
-
326
- console.log(
327
- ` ${C.dim}└────┴──────────────────────┴──────────┴───────────────┴────────────┴────────┴───────────┘${C.reset}`
328
- );
329
-
330
- // Summary
331
- const totalVolume = txs.reduce((sum, tx) => sum + tx.amount, 0);
332
- const successCount = txs.filter(tx => tx.status !== 'failed').length;
333
- console.log(`\n ${C.dim} ${txs.length} transactions · Total volume: ${C.reset}${C.bright}${formatAether(totalVolume)}${C.reset} ${C.dim}· Success: ${C.reset}${C.green}${successCount}/${txs.length}${C.reset} ${C.dim}· Failed: ${C.reset}${C.red}${(txs.length - successCount)}${C.reset}\n`);
334
- }
335
-
336
- function displayJson(txs, meta) {
337
- console.log(JSON.stringify({
338
- address: meta.address,
339
- rpc: meta.rpc,
340
- limit: meta.limit,
341
- transaction_count: txs.length,
342
- total_volume_lamports: txs.reduce((sum, tx) => sum + tx.amount, 0),
343
- transactions: txs.map(tx => ({
344
- signature: tx.signature,
345
- slot: tx.slot,
346
- timestamp: tx.blockTime ? new Date(tx.blockTime * 1000).toISOString() : null,
347
- type: tx.type,
348
- amount_lamports: tx.amount,
349
- amount_aeth: (tx.amount / 1e9).toFixed(9),
350
- fee_lamports: tx.fee,
351
- from: tx.from,
352
- to: tx.to,
353
- memo: tx.memo,
354
- status: tx.status,
355
- })),
356
- }, null, 2));
357
- }
358
-
359
- // ---------------------------------------------------------------------------
360
- // Main
361
- // ---------------------------------------------------------------------------
362
-
363
- async function main() {
364
- const opts = parseArgs();
365
-
366
- if (opts.help) {
367
- console.log(`
368
- ${C.bright}${C.cyan}tx-history${C.reset} — Fetch and display transaction history for an Aether address
369
-
370
- ${C.bright}USAGE${C.reset}
371
- aether tx history --address <addr> [--limit <n>] [--json] [--rpc <url>]
372
- aether history --address <addr> [--limit <n>] [--json]
373
-
374
- ${C.bright}OPTIONS${C.reset}
375
- --address <addr> Aether wallet address (ATH...)
376
- --limit <n> Max transactions to fetch (default: 20, max: 100)
377
- --json Output raw JSON for scripting
378
- --rpc <url> RPC endpoint (default: AETHER_RPC or http://127.0.0.1:8899)
379
- --help Show this help
380
-
381
- ${C.bright}EXAMPLES${C.reset}
382
- aether tx history --address ATH3abc... --limit 50
383
- aether tx history --address ATH3abc... --json
384
- aether history --address ATH3abc... --rpc https://mainnet.aether.io
385
- `);
386
- return;
387
- }
388
-
389
- if (!opts.address) {
390
- console.log(` ${C.red}✗ Missing --address${C.reset}\n`);
391
- console.log(` Usage: aether tx history --address <addr> [--limit <n>] [--json]\n`);
392
- process.exit(1);
393
- }
394
-
395
- const rpcUrl = opts.rpc || getDefaultRpc();
396
- const limit = Math.min(Math.max(1, opts.limit || 20), 100);
397
-
398
- if (!opts.json) {
399
- console.log(`\n${C.bright}${C.cyan} Tx History${C.reset} · ${C.dim}address:${C.reset} ${opts.address} ${C.dim}· ${C.dim}limit:${C.reset} ${limit} ${C.dim}· ${C.dim}rpc:${C.reset} ${rpcUrl}\n`);
400
- }
401
-
402
- try {
403
- // Step 1: Get transaction signatures
404
- const sigsResult = await fetchTxSignatures(rpcUrl, opts.address, limit);
405
-
406
- if (sigsResult.error) {
407
- throw new Error(sigsResult.error.message || JSON.stringify(sigsResult.error));
408
- }
409
-
410
- const signatures = Array.isArray(sigsResult.result) ? sigsResult.result : [];
411
-
412
- if (signatures.length === 0) {
413
- if (!opts.json) {
414
- displayTxTable([]);
415
- } else {
416
- displayJson([], { address: opts.address, rpc: rpcUrl, limit });
417
- }
418
- return;
419
- }
420
-
421
- // Step 2: Fetch each transaction in parallel (up to 10 at a time)
422
- const txResults = [];
423
- const BATCH = 10;
424
-
425
- for (let i = 0; i < signatures.length; i += BATCH) {
426
- const batch = signatures.slice(i, i + BATCH);
427
- const batchPromises = batch.map(sig => fetchTx(rpcUrl, sig.signature).catch(err => ({ error: err.message })));
428
- const batchResults = await Promise.all(batchPromises);
429
- txResults.push(...batchResults);
430
- }
431
-
432
- // Step 3: Parse and normalize
433
- const txs = txResults
434
- .map((res, idx) => {
435
- if (res.error) return null;
436
- try {
437
- return parseTransaction(res.result || {}, signatures[idx] || {});
438
- } catch {
439
- return null;
440
- }
441
- })
442
- .filter(Boolean);
443
-
444
- if (opts.json) {
445
- displayJson(txs, { address: opts.address, rpc: rpcUrl, limit });
446
- } else {
447
- displayTxTable(txs);
448
- }
449
-
450
- } catch (err) {
451
- console.log(`\n ${C.red}✗ Failed to fetch transaction history:${C.reset} ${err.message}\n`);
452
- if (err.stack && !opts.json) {
453
- console.log(` ${C.dim}${err.stack.split('\n').slice(0, 3).join('\n ')}${C.reset}\n`);
454
- }
455
- process.exit(1);
456
- }
457
- }
458
-
459
- // Run if called directly
460
- if (require.main === module) {
461
- main();
462
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * aether-cli tx-history
4
+ *
5
+ * Fetch and display transaction history for an Aether wallet address.
6
+ * Shows recent transactions with type, amount, timestamp, fee, and status.
7
+ *
8
+ * Usage:
9
+ * aether tx history --address <addr> [--limit <n>] [--json] [--rpc <url>]
10
+ * aether history --address <addr> [--limit <n>] [--json]
11
+ *
12
+ * Examples:
13
+ * aether tx history --address ATHxxx
14
+ * aether tx history --address ATHxxx --limit 50 --json
15
+ * aether history --address ATHxxx --rpc https://rpc.aether.io
16
+ */
17
+
18
+ const path = require('path');
19
+
20
+ // Import SDK for real blockchain RPC calls
21
+ const sdkPath = path.join(__dirname, '..', 'sdk', 'index.js');
22
+ const aether = require(sdkPath);
23
+
24
+ // ANSI colours
25
+ const C = {
26
+ reset: '\x1b[0m',
27
+ bright: '\x1b[1m',
28
+ dim: '\x1b[2m',
29
+ red: '\x1b[31m',
30
+ green: '\x1b[32m',
31
+ yellow: '\x1b[33m',
32
+ cyan: '\x1b[36m',
33
+ magenta: '\x1b[35m',
34
+ };
35
+
36
+ const CLI_VERSION = '1.0.0';
37
+
38
+ // ---------------------------------------------------------------------------
39
+ // SDK helpers - Real blockchain RPC calls via Aether SDK
40
+ // ---------------------------------------------------------------------------
41
+
42
+ function getDefaultRpc() {
43
+ return process.env.AETHER_RPC || aether.DEFAULT_RPC_URL || 'http://127.0.0.1:8899';
44
+ }
45
+
46
+ function createClient(rpcUrl) {
47
+ return new aether.AetherClient({ rpcUrl });
48
+ }
49
+
50
+ // ---------------------------------------------------------------------------
51
+ // Argument parsing
52
+ // ---------------------------------------------------------------------------
53
+
54
+ function parseArgs() {
55
+ const args = process.argv.slice(2);
56
+ const result = { address: null, limit: 20, json: false, rpc: null };
57
+
58
+ for (let i = 0; i < args.length; i++) {
59
+ const arg = args[i];
60
+ if ((arg === '--address' || arg === '-a') && args[i + 1] && !args[i + 1].startsWith('-')) {
61
+ result.address = args[i + 1];
62
+ i++;
63
+ } else if ((arg === '--limit' || arg === '-l') && args[i + 1] && !args[i + 1].startsWith('-')) {
64
+ result.limit = parseInt(args[i + 1], 10);
65
+ i++;
66
+ } else if (arg === '--json' || arg === '--json-output') {
67
+ result.json = true;
68
+ } else if (arg === '--rpc' && args[i + 1] && !args[i + 1].startsWith('-')) {
69
+ result.rpc = args[i + 1];
70
+ i++;
71
+ } else if (arg === '--help' || arg === '-h') {
72
+ result.help = true;
73
+ }
74
+ }
75
+
76
+ return result;
77
+ }
78
+
79
+ // ---------------------------------------------------------------------------
80
+ // Formatting helpers
81
+ // ---------------------------------------------------------------------------
82
+
83
+ function formatAether(lamports) {
84
+ if (lamports == null) return '—';
85
+ const aeth = lamports / 1e9;
86
+ if (aeth === 0) return '0 AETH';
87
+ return aeth.toFixed(4).replace(/\.?0+$/, '') + ' AETH';
88
+ }
89
+
90
+ function formatTimestamp(slot, blockTime) {
91
+ if (!blockTime) return '—';
92
+ try {
93
+ const d = new Date(blockTime * 1000);
94
+ return d.toISOString().replace('T', ' ').slice(0, 19);
95
+ } catch {
96
+ return String(blockTime);
97
+ }
98
+ }
99
+
100
+ function shortAddress(addr) {
101
+ if (!addr) return '—';
102
+ if (addr.length <= 16) return addr;
103
+ return addr.slice(0, 8) + '…' + addr.slice(-6);
104
+ }
105
+
106
+ function formatTxType(type) {
107
+ const t = (type || 'unknown').toLowerCase();
108
+ if (t.includes('transfer') || t.includes('send') || t.includes('payment')) return { label: 'TRANSFER', color: C.cyan };
109
+ if (t.includes('stake') || t.includes('delegate')) return { label: 'STAKE', color: C.green };
110
+ if (t.includes('unstake') || t.includes('deactivate')) return { label: 'UNSTAKE', color: C.yellow };
111
+ if (t.includes('reward') || t.includes('mint')) return { label: 'REWARD', color: C.magenta };
112
+ if (t.includes('vote')) return { label: 'VOTE', color: C.bright };
113
+ if (t.includes('create') || t.includes('initialize')) return { label: 'CREATE', color: C.bright };
114
+ if (t.includes('burn')) return { label: 'BURN', color: C.red };
115
+ return { label: type ? type.toUpperCase().slice(0, 10) : 'TX', color: C.dim };
116
+ }
117
+
118
+ function formatStatus(status) {
119
+ if (!status) return { label: '—', color: C.dim };
120
+ const s = status.toLowerCase();
121
+ if (s === 'success' || s === 'finalized' || s === 'confirmed') {
122
+ return { label: '✓ OK', color: C.green };
123
+ }
124
+ if (s === 'pending' || s === 'processing') {
125
+ return { label: '⏳', color: C.yellow };
126
+ }
127
+ if (s === 'failed') {
128
+ return { label: '✗ FAIL', color: C.red };
129
+ }
130
+ return { label: status.slice(0, 8), color: C.dim };
131
+ }
132
+
133
+ // ---------------------------------------------------------------------------
134
+ // Parse a transaction result into a normalized display object
135
+ // ---------------------------------------------------------------------------
136
+
137
+ function parseTransaction(txResult) {
138
+ const blockTime = txResult.blockTime;
139
+ const slot = txResult.slot;
140
+ const status = txResult.status || 'confirmed';
141
+
142
+ let txType = txResult.tx_type || txResult.type || 'unknown';
143
+ let amount = 0;
144
+ let fee = txResult.fee || 0;
145
+ let fromAddr = txResult.signer || null;
146
+ let toAddr = null;
147
+ let memo = txResult.memo || null;
148
+
149
+ // Parse payload for details
150
+ if (txResult.payload) {
151
+ const payload = txResult.payload;
152
+ if (payload.amount !== undefined) {
153
+ amount = Number(payload.amount);
154
+ }
155
+ if (payload.recipient) {
156
+ toAddr = payload.recipient;
157
+ }
158
+ if (payload.validator) {
159
+ toAddr = payload.validator;
160
+ txType = 'stake';
161
+ }
162
+ if (payload.stake_account) {
163
+ fromAddr = payload.stake_account;
164
+ txType = 'unstake';
165
+ }
166
+ }
167
+
168
+ return {
169
+ signature: txResult.signature,
170
+ slot,
171
+ blockTime,
172
+ status,
173
+ type: txType,
174
+ amount,
175
+ fee,
176
+ from: fromAddr,
177
+ to: toAddr,
178
+ memo,
179
+ };
180
+ }
181
+
182
+ // ---------------------------------------------------------------------------
183
+ // Display
184
+ // ---------------------------------------------------------------------------
185
+
186
+ function displayTxTable(txs) {
187
+ // Header
188
+ console.log(
189
+ `\n${C.bright}${C.cyan} ╔══════════════════════════════════════════════════════════════════════════════════════════╗${C.reset}\n` +
190
+ ` ║${C.bright} ${C.cyan}Transaction History${C.reset}${C.bright} ║${C.reset}\n` +
191
+ ` ${C.cyan}╚══════════════════════════════════════════════════════════════════════════════════════════${C.reset}`
192
+ );
193
+
194
+ if (txs.length === 0) {
195
+ console.log(`\n ${C.yellow}No transactions found for this address.${C.reset}\n`);
196
+ return;
197
+ }
198
+
199
+ console.log(
200
+ ` ${C.dim}┌────┬──────────────────────┬──────────┬───────────────┬────────────┬────────┬───────────┐${C.reset}\n` +
201
+ ` ${C.dim}│ # │ ${C.reset}Timestamp ${C.dim}│ ${C.reset}Type ${C.dim}│ ${C.reset}Amount ${C.dim}│ ${C.reset}From ${C.dim}│ ${C.reset}To ${C.dim}│ ${C.reset}Status ${C.dim}│${C.reset}`
202
+ );
203
+
204
+ for (let i = 0; i < txs.length; i++) {
205
+ const tx = txs[i];
206
+ const num = String(i + 1).padStart(3);
207
+ const time = formatTimestamp(tx.blockTime).slice(0, 19).padEnd(19);
208
+ const typeInfo = formatTxType(tx.type);
209
+ const type = typeInfo.label.padEnd(10);
210
+ const amt = tx.amount > 0 ? formatAether(tx.amount).padEnd(13) : ''.padEnd(13);
211
+ const from = shortAddress(tx.from || '').padEnd(11);
212
+ const to = shortAddress(tx.to || '').padEnd(11);
213
+ const statusInfo = formatStatus(tx.status);
214
+ const status = statusInfo.label;
215
+
216
+ const bgAlt = (i % 2 === 0) ? '' : C.dim;
217
+ const reset = C.reset + bgAlt;
218
+
219
+ console.log(
220
+ ` ${bgAlt}${C.dim}├────┼──────────────────────┼──────────┼───────────────┼────────────┼────────┼───────────┤${reset}`
221
+ );
222
+ console.log(
223
+ ` ${bgAlt}${C.dim}│${reset} ${num} ${bgAlt}${C.dim}│ ${reset}${time} ${bgAlt}${C.dim}│ ${reset}${typeInfo.color}${type}${reset} ${bgAlt}${C.dim}│ ${reset}${amt} ${bgAlt}${C.dim}│ ${reset}${from} ${bgAlt}${C.dim}│ ${reset}${to} ${bgAlt}${C.dim}│ ${reset}${statusInfo.color}${status}${reset}${bgAlt} │${reset}`
224
+ );
225
+ }
226
+
227
+ console.log(
228
+ ` ${C.dim}└────┴──────────────────────┴──────────┴───────────────┴────────────┴────────┴───────────┘${C.reset}`
229
+ );
230
+
231
+ // Summary
232
+ const totalVolume = txs.reduce((sum, tx) => sum + tx.amount, 0);
233
+ const successCount = txs.filter(tx => tx.status !== 'failed').length;
234
+ console.log(`\n ${C.dim} ${txs.length} transactions · Total volume: ${C.reset}${C.bright}${formatAether(totalVolume)}${C.reset} ${C.dim}· Success: ${C.reset}${C.green}${successCount}/${txs.length}${C.reset} ${C.dim}· Failed: ${C.reset}${C.red}${(txs.length - successCount)}${C.reset}\n`);
235
+ }
236
+
237
+ function displayJson(txs, meta) {
238
+ console.log(JSON.stringify({
239
+ address: meta.address,
240
+ rpc: meta.rpc,
241
+ limit: meta.limit,
242
+ transaction_count: txs.length,
243
+ total_volume_lamports: txs.reduce((sum, tx) => sum + tx.amount, 0),
244
+ transactions: txs.map(tx => ({
245
+ signature: tx.signature,
246
+ slot: tx.slot,
247
+ timestamp: tx.blockTime ? new Date(tx.blockTime * 1000).toISOString() : null,
248
+ type: tx.type,
249
+ amount_lamports: tx.amount,
250
+ amount_aeth: (tx.amount / 1e9).toFixed(9),
251
+ fee_lamports: tx.fee,
252
+ from: tx.from,
253
+ to: tx.to,
254
+ memo: tx.memo,
255
+ status: tx.status,
256
+ })),
257
+ }, null, 2));
258
+ }
259
+
260
+ // ---------------------------------------------------------------------------
261
+ // Main
262
+ // ---------------------------------------------------------------------------
263
+
264
+ async function main() {
265
+ const opts = parseArgs();
266
+ // Shift args if this module was called via index.js (extra argument in argv)
267
+ // Detect by checking if first non-option arg after 'tx' is the command name
268
+ const args = process.argv.slice(2);
269
+ const txIdx = args.indexOf('tx');
270
+ const historyIdx = args.indexOf('history');
271
+ if (txIdx !== -1 && historyIdx !== -1) {
272
+ // Already parsed correctly above - no action needed
273
+ }
274
+
275
+ if (opts.help) {
276
+ console.log(`
277
+ ${C.bright}${C.cyan}tx-history${C.reset} — Fetch and display transaction history for an Aether address
278
+
279
+ ${C.bright}USAGE${C.reset}
280
+ aether tx history --address <addr> [--limit <n>] [--json] [--rpc <url>]
281
+ aether history --address <addr> [--limit <n>] [--json]
282
+
283
+ ${C.bright}OPTIONS${C.reset}
284
+ --address <addr> Aether wallet address (ATH...)
285
+ --limit <n> Max transactions to fetch (default: 20, max: 100)
286
+ --json Output raw JSON for scripting
287
+ --rpc <url> RPC endpoint (default: AETHER_RPC or http://127.0.0.1:8899)
288
+ --help Show this help
289
+
290
+ ${C.bright}EXAMPLES${C.reset}
291
+ aether tx history --address ATH3abc... --limit 50
292
+ aether tx history --address ATH3abc... --json
293
+ aether history --address ATH3abc... --rpc https://mainnet.aether.io
294
+ `);
295
+ return;
296
+ }
297
+
298
+ if (!opts.address) {
299
+ console.log(` ${C.red}✗ Missing --address${C.reset}\n`);
300
+ console.log(` Usage: aether tx history --address <addr> [--limit <n>] [--json]\n`);
301
+ process.exit(1);
302
+ }
303
+
304
+ const rpcUrl = opts.rpc || getDefaultRpc();
305
+ const limit = Math.min(Math.max(1, opts.limit || 20), 100);
306
+
307
+ if (!opts.json) {
308
+ console.log(`\n${C.bright}${C.cyan} Tx History${C.reset} · ${C.dim}address:${C.reset} ${opts.address} ${C.dim}· ${C.dim}limit:${C.reset} ${limit} ${C.dim}· ${C.dim}rpc:${C.reset} ${rpcUrl}\n`);
309
+ }
310
+
311
+ try {
312
+ // Use SDK for real blockchain RPC calls
313
+ const client = createClient(rpcUrl);
314
+ const history = await client.getTransactionHistory(opts.address, limit);
315
+
316
+ const txs = (history.transactions || []).map(tx => parseTransaction(tx));
317
+
318
+ if (opts.json) {
319
+ displayJson(txs, { address: opts.address, rpc: rpcUrl, limit });
320
+ } else {
321
+ displayTxTable(txs);
322
+ }
323
+
324
+ } catch (err) {
325
+ if (opts.json) {
326
+ console.log(JSON.stringify({
327
+ error: err.message,
328
+ address: opts.address,
329
+ rpc: rpcUrl,
330
+ }, null, 2));
331
+ } else {
332
+ console.log(`\n ${C.red}✗ Failed to fetch transaction history:${C.reset} ${err.message}\n`);
333
+ console.log(` ${C.dim} Is your validator running? RPC: ${rpcUrl}${C.reset}`);
334
+ console.log(` ${C.dim} Set custom RPC: AETHER_RPC=https://your-rpc-url${C.reset}\n`);
335
+ }
336
+ process.exit(1);
337
+ }
338
+ }
339
+
340
+ // Export for CLI integration
341
+ module.exports = { txHistoryCommand: main };
342
+
343
+ // Run if called directly
344
+ if (require.main === module) {
345
+ main();
346
+ }