1515 * - API_BASE_URL: Base URL for the API (default: http://localhost:3000)
1616 * - SNAPSHOT_AUTH_TOKEN: Authentication token for API requests
1717 * - BATCH_SIZE: Number of wallets per batch (default: 10)
18- * - DELAY_BETWEEN_BATCHES: Delay between batches in seconds (default: 5 )
18+ * - DELAY_BETWEEN_BATCHES: Delay between batches in seconds (default: 10 )
1919 * - MAX_RETRIES: Maximum retries for failed batches (default: 3)
2020 */
2121
@@ -24,8 +24,18 @@ interface BatchProgress {
2424 walletsInBatch: number ;
2525 failedInBatch: number ;
2626 snapshotsStored: number ;
27- totalAdaBalance: number ;
2827 totalBatches: number ;
28+ // Network-specific data
29+ mainnetWallets: number ;
30+ testnetWallets: number ;
31+ mainnetAdaBalance: number ;
32+ testnetAdaBalance: number ;
33+ // Failure details
34+ failures: Array < {
35+ walletId : string ;
36+ errorType: string ;
37+ errorMessage: string ;
38+ } > ;
2939}
3040
3141interface BatchResponse {
@@ -40,9 +50,21 @@ interface BatchResults {
4050 failedBatches: number ;
4151 totalWalletsProcessed: number ;
4252 totalWalletsFailed: number ;
43- totalAdaBalance: number ;
4453 totalSnapshotsStored: number ;
4554 executionTime: number ;
55+ // Network-specific data
56+ totalMainnetWallets: number ;
57+ totalTestnetWallets: number ;
58+ totalMainnetAdaBalance: number ;
59+ totalTestnetAdaBalance: number ;
60+ // Failure tracking
61+ allFailures: Array < {
62+ walletId : string ;
63+ errorType: string ;
64+ errorMessage: string ;
65+ batchNumber: number ;
66+ } > ;
67+ failureSummary: Record < string , number > ;
4668}
4769
4870interface BatchConfig {
@@ -70,9 +92,16 @@ class BatchSnapshotOrchestrator {
7092 failedBatches : 0 ,
7193 totalWalletsProcessed : 0 ,
7294 totalWalletsFailed : 0 ,
73- totalAdaBalance : 0 ,
7495 totalSnapshotsStored : 0 ,
7596 executionTime : 0 ,
97+ // Network-specific data
98+ totalMainnetWallets : 0 ,
99+ totalTestnetWallets : 0 ,
100+ totalMainnetAdaBalance : 0 ,
101+ totalTestnetAdaBalance : 0 ,
102+ // Failure tracking
103+ allFailures : [ ] ,
104+ failureSummary : { } ,
76105 } ;
77106 }
78107
@@ -88,7 +117,7 @@ class BatchSnapshotOrchestrator {
88117 apiBaseUrl,
89118 authToken,
90119 batchSize : parseInt ( process . env . BATCH_SIZE || '10' ) ,
91- delayBetweenBatches : parseInt ( process . env . DELAY_BETWEEN_BATCHES || '5 ' ) ,
120+ delayBetweenBatches : parseInt ( process . env . DELAY_BETWEEN_BATCHES || '10 ' ) ,
92121 maxRetries : parseInt ( process . env . MAX_RETRIES || '3' ) ,
93122 } ;
94123 }
@@ -129,6 +158,17 @@ class BatchSnapshotOrchestrator {
129158 return new Promise ( resolve => setTimeout ( resolve , seconds * 1000 ) ) ;
130159 }
131160
161+ private getFriendlyErrorName ( errorType : string ) : string {
162+ const errorMap : Record < string , string > = {
163+ 'wallet_build_failed' : 'Wallet Build Failed' ,
164+ 'utxo_fetch_failed' : 'UTxO Fetch Failed' ,
165+ 'address_generation_failed' : 'Address Generation Failed' ,
166+ 'balance_calculation_failed' : 'Balance Calculation Failed' ,
167+ 'processing_failed' : 'General Processing Failed' ,
168+ } ;
169+ return errorMap [ errorType ] || errorType ;
170+ }
171+
132172 private async processBatch ( batchNumber : number , batchId : string ) : Promise < BatchProgress | null > {
133173 console . log ( `📦 Processing batch ${ batchNumber } ...` ) ;
134174
@@ -148,7 +188,16 @@ class BatchSnapshotOrchestrator {
148188 console . log ( ` • Processed: ${ data . progress . processedInBatch } /${ data . progress . walletsInBatch } wallets` ) ;
149189 console . log ( ` • Failed: ${ data . progress . failedInBatch } ` ) ;
150190 console . log ( ` • Snapshots stored: ${ data . progress . snapshotsStored } ` ) ;
151- console . log ( ` • Batch ADA balance: ${ Math . round ( data . progress . totalAdaBalance * 100 ) / 100 } ADA` ) ;
191+ console . log ( ` • Mainnet: ${ data . progress . mainnetWallets } wallets, ${ Math . round ( data . progress . mainnetAdaBalance * 100 ) / 100 } ADA` ) ;
192+ console . log ( ` • Testnet: ${ data . progress . testnetWallets } wallets, ${ Math . round ( data . progress . testnetAdaBalance * 100 ) / 100 } ADA` ) ;
193+
194+ // Show failures for this batch
195+ if ( data . progress . failures . length > 0 ) {
196+ console . log ( ` ❌ Failures in this batch:` ) ;
197+ data . progress . failures . forEach ( ( failure , index ) => {
198+ console . log ( ` ${ index + 1 } . ${ failure . walletId } ... - ${ failure . errorMessage } ` ) ;
199+ } ) ;
200+ }
152201
153202 return data . progress ;
154203 } else {
@@ -193,8 +242,22 @@ class BatchSnapshotOrchestrator {
193242 this . results . completedBatches = 1 ;
194243 this . results . totalWalletsProcessed += firstBatch . processedInBatch ;
195244 this . results . totalWalletsFailed += firstBatch . failedInBatch ;
196- this . results . totalAdaBalance += firstBatch . totalAdaBalance ;
197245 this . results . totalSnapshotsStored += firstBatch . snapshotsStored ;
246+
247+ // Accumulate network-specific data
248+ this . results . totalMainnetWallets += firstBatch . mainnetWallets ;
249+ this . results . totalTestnetWallets += firstBatch . testnetWallets ;
250+ this . results . totalMainnetAdaBalance += firstBatch . mainnetAdaBalance ;
251+ this . results . totalTestnetAdaBalance += firstBatch . testnetAdaBalance ;
252+
253+ // Accumulate failures
254+ firstBatch . failures . forEach ( failure => {
255+ this . results . allFailures . push ( {
256+ ...failure ,
257+ batchNumber : 1
258+ } ) ;
259+ this . results . failureSummary [ failure . errorType ] = ( this . results . failureSummary [ failure . errorType ] || 0 ) + 1 ;
260+ } ) ;
198261
199262 console . log ( `📊 Total batches to process: ${ this . results . totalBatches } ` ) ;
200263
@@ -210,8 +273,22 @@ class BatchSnapshotOrchestrator {
210273 this . results . completedBatches ++ ;
211274 this . results . totalWalletsProcessed += batchProgress . processedInBatch ;
212275 this . results . totalWalletsFailed += batchProgress . failedInBatch ;
213- this . results . totalAdaBalance += batchProgress . totalAdaBalance ;
214276 this . results . totalSnapshotsStored += batchProgress . snapshotsStored ;
277+
278+ // Accumulate network-specific data
279+ this . results . totalMainnetWallets += batchProgress . mainnetWallets ;
280+ this . results . totalTestnetWallets += batchProgress . testnetWallets ;
281+ this . results . totalMainnetAdaBalance += batchProgress . mainnetAdaBalance ;
282+ this . results . totalTestnetAdaBalance += batchProgress . testnetAdaBalance ;
283+
284+ // Accumulate failures
285+ batchProgress . failures . forEach ( failure => {
286+ this . results . allFailures . push ( {
287+ ...failure ,
288+ batchNumber
289+ } ) ;
290+ this . results . failureSummary [ failure . errorType ] = ( this . results . failureSummary [ failure . errorType ] || 0 ) + 1 ;
291+ } ) ;
215292 } else {
216293 this . results . failedBatches ++ ;
217294 console . error ( `❌ Batch ${ batchNumber } failed completely` ) ;
@@ -234,11 +311,31 @@ class BatchSnapshotOrchestrator {
234311 console . log ( ` • Wallets processed: ${ this . results . totalWalletsProcessed } ` ) ;
235312 console . log ( ` • Wallets failed: ${ this . results . totalWalletsFailed } ` ) ;
236313 console . log ( ` • Snapshots stored: ${ this . results . totalSnapshotsStored } ` ) ;
237- console . log ( ` • Total TVL: ${ Math . round ( this . results . totalAdaBalance * 100 ) / 100 } ADA` ) ;
238314 console . log ( ` • Execution time: ${ this . results . executionTime } s` ) ;
315+
316+ // Network-specific breakdown
317+ console . log ( `\n🌐 Network Breakdown:` ) ;
318+ console . log ( ` 📈 Mainnet:` ) ;
319+ console . log ( ` • Wallets: ${ this . results . totalMainnetWallets } ` ) ;
320+ console . log ( ` • TVL: ${ Math . round ( this . results . totalMainnetAdaBalance * 100 ) / 100 } ADA` ) ;
321+ console . log ( ` 🧪 Testnet:` ) ;
322+ console . log ( ` • Wallets: ${ this . results . totalTestnetWallets } ` ) ;
323+ console . log ( ` • TVL: ${ Math . round ( this . results . totalTestnetAdaBalance * 100 ) / 100 } ADA` ) ;
324+
325+ // Failure analysis
326+ if ( this . results . totalWalletsFailed > 0 ) {
327+ console . log ( `\n❌ Failure Summary:` ) ;
328+ console . log ( ` • Total failed wallets: ${ this . results . totalWalletsFailed } ` ) ;
329+
330+ // Show failure summary by type
331+ Object . entries ( this . results . failureSummary ) . forEach ( ( [ errorType , count ] ) => {
332+ const friendlyName = this . getFriendlyErrorName ( errorType ) ;
333+ console . log ( ` • ${ friendlyName } : ${ count } wallets` ) ;
334+ } ) ;
335+ }
239336
240337 if ( this . results . failedBatches > 0 ) {
241- console . log ( `⚠️ Warning: ${ this . results . failedBatches } batches failed. You may need to retry those batches manually.` ) ;
338+ console . log ( `\n ⚠️ Warning: ${ this . results . failedBatches } batches failed. You may need to retry those batches manually.` ) ;
242339 }
243340
244341 return this . results ;
0 commit comments