@@ -11,7 +11,6 @@ import {
1111 upsertTransaction ,
1212 getSimplifiedTransactions ,
1313 getSimplifiedTrasaction ,
14- connectAllTransactionsToPrices ,
1514 updateClientPaymentStatus ,
1615 getClientPayment
1716} from './transactionService'
@@ -28,7 +27,6 @@ import { OpReturnData, parseError, parseOpReturnData } from 'utils/validators'
2827import { executeAddressTriggers , executeTriggersBatch } from './triggerService'
2928import { appendTxsToFile } from 'prisma-local/seeds/transactions'
3029import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants'
31- import { syncPastDaysNewerPrices } from './priceService'
3230import { AddressType } from 'ecashaddrjs/dist/types'
3331import { DecimalJsLike } from '@prisma/client/runtime/library'
3432
@@ -957,25 +955,14 @@ class MultiBlockchainClient {
957955 console . log ( 'Initializing MultiBlockchainClient...' )
958956 this . initializing = true
959957 void ( async ( ) => {
960- if ( this . isRunningApp ( ) ) {
961- await syncPastDaysNewerPrices ( )
962- const asyncOperations : Array < Promise < void > > = [ ]
963- this . clients = {
964- ecash : this . instantiateChronikClient ( 'ecash' , asyncOperations ) ,
965- bitcoincash : this . instantiateChronikClient ( 'bitcoincash' , asyncOperations )
966- }
967- await Promise . all ( asyncOperations )
968- this . setInitialized ( )
969- await connectAllTransactionsToPrices ( )
970- } else if ( process . env . NODE_ENV === 'test' ) {
971- const asyncOperations : Array < Promise < void > > = [ ]
972- this . clients = {
973- ecash : this . instantiateChronikClient ( 'ecash' , asyncOperations ) ,
974- bitcoincash : this . instantiateChronikClient ( 'bitcoincash' , asyncOperations )
975- }
976- await Promise . all ( asyncOperations )
977- this . setInitialized ( )
958+ const asyncOperations : Array < Promise < void > > = [ ]
959+ this . clients = {
960+ ecash : this . instantiateChronikClient ( 'ecash' , asyncOperations ) ,
961+ bitcoincash : this . instantiateChronikClient ( 'bitcoincash' , asyncOperations )
978962 }
963+ await Promise . all ( asyncOperations )
964+ this . setInitialized ( )
965+ console . log ( 'Finished initializing MultiBlockchainClient.' )
979966 } ) ( )
980967 }
981968
@@ -1020,9 +1007,6 @@ class MultiBlockchainClient {
10201007 await newClient . waitForLatencyTest ( )
10211008 console . log ( `[CHRONIK — ${ networkSlug } ] Subscribing addresses in database...` )
10221009 await newClient . subscribeInitialAddresses ( )
1023- console . log ( `[CHRONIK — ${ networkSlug } ] Syncing missed transactions...` )
1024- await newClient . syncMissedTransactions ( )
1025- console . log ( `[CHRONIK — ${ networkSlug } ] Finished instantiating client.` )
10261010 } ) ( )
10271011 )
10281012 } else if ( process . env . NODE_ENV === 'test' ) {
@@ -1033,6 +1017,7 @@ class MultiBlockchainClient {
10331017 )
10341018 }
10351019
1020+ console . log ( `Finished instantiating ${ networkSlug } client.` )
10361021 return newClient
10371022 }
10381023
@@ -1090,10 +1075,31 @@ class MultiBlockchainClient {
10901075 return await this . clients [ networkSlug as MainNetworkSlugsType ] . getBalance ( address )
10911076 }
10921077
1078+ public async syncMissedTransactions ( ) : Promise < void > {
1079+ await this . waitForStart ( )
1080+ await Promise . all ( [
1081+ this . clients . ecash . syncMissedTransactions ( ) ,
1082+ this . clients . bitcoincash . syncMissedTransactions ( )
1083+ ] )
1084+ }
1085+
10931086 public async syncAndSubscribeAddresses ( addresses : Address [ ] ) : Promise < SyncAndSubscriptionReturn > {
10941087 await this . subscribeAddresses ( addresses )
10951088 return await this . syncAddresses ( addresses )
10961089 }
1090+
1091+ public async destroy ( ) : Promise < void > {
1092+ await Promise . all (
1093+ Object . values ( this . clients ) . map ( async ( c ) => {
1094+ try {
1095+ c . chronikWSEndpoint . close ( )
1096+ c . wsEndpoint . close ( )
1097+ } catch ( err : any ) {
1098+ console . error ( `Failed to close connections for client: ${ err . message as string } ` )
1099+ }
1100+ } )
1101+ )
1102+ }
10971103}
10981104
10991105export interface NodeJsGlobalMultiBlockchainClient extends NodeJS . Global {
0 commit comments