1+ const TopupService = require ( './src/topup-service' ) ;
2+ const NotificationService = require ( './src/notification' ) ;
3+ const { ParameterParser, Logger, TelegramHelper } = require ( './src/utils' ) ;
4+
5+ async function main ( ) {
6+ try {
7+ // Parse arguments
8+ const args = process . argv . slice ( 2 ) ;
9+
10+ // Special command to get chat ID
11+ if ( args . includes ( '--get-chat-id' ) ) {
12+ const tokenIndex = args . indexOf ( '--telegram-bot-token' ) ;
13+ if ( tokenIndex === - 1 || ! args [ tokenIndex + 1 ] ) {
14+ Logger . error ( '--telegram-bot-token is required with --get-chat-id' ) ;
15+ process . exit ( 1 ) ;
16+ }
17+
18+ const botToken = args [ tokenIndex + 1 ] ;
19+ await TelegramHelper . getChatId ( botToken ) ;
20+ process . exit ( 0 ) ;
21+ }
22+
23+ const params = ParameterParser . extractParameters ( args ) ;
24+
25+ if ( ! params . success ) {
26+ if ( params . errors ) {
27+ params . errors . forEach ( error => Logger . error ( error ) ) ;
28+ }
29+ ParameterParser . showUsage ( ) ;
30+ process . exit ( 1 ) ;
31+ }
32+
33+ // Initialize services
34+ const topupService = new TopupService ( ) ;
35+ const notificationService = new NotificationService ( ) ;
36+
37+ if ( params . telegramEnabled ) {
38+ notificationService . initialize ( params . telegramBotToken , params . telegramUsername ) ;
39+ }
40+
41+ // Execute topup
42+ Logger . info ( `Starting ARIO top-up: ${ params . amount } from ${ params . walletPath } ` ) ;
43+ const result = await topupService . executeTopup ( params . walletPath , params . amount ) ;
44+
45+ // Log success
46+ Logger . success ( `Top-up completed! Status: ${ result . status } , TX: ${ result . transactionId } ` ) ;
47+ Logger . info ( `Used: ${ result . topupAmount } ARIO, Remaining: ${ result . remainingBalance . toFixed ( 6 ) } ARIO` ) ;
48+
49+ // Send notification
50+ if ( params . telegramEnabled ) {
51+ await notificationService . notifySuccess (
52+ result . publicKey ,
53+ result . topupAmount ,
54+ result . status ,
55+ result . transactionId ,
56+ result . remainingBalance
57+ ) ;
58+ }
59+
60+ } catch ( error ) {
61+ Logger . error ( `Failed: ${ error . message } ` ) ;
62+
63+ // Send error notification if telegram is enabled
64+ const args = process . argv . slice ( 2 ) ;
65+ const params = ParameterParser . extractParameters ( args ) ;
66+
67+ if ( params . success && params . telegramEnabled ) {
68+ const notificationService = new NotificationService ( ) ;
69+ await notificationService . initialize ( params . telegramBotToken , params . telegramUsername ) ;
70+
71+ const publicKey = params . walletPath ?
72+ require ( 'path' ) . basename ( params . walletPath , '.json' ) : 'Unknown' ;
73+
74+ await notificationService . notifyError ( publicKey , error . message , params . amount ) ;
75+ }
76+
77+ process . exit ( 1 ) ;
78+ }
79+ }
80+
81+ main ( ) ;
0 commit comments