@@ -21,7 +21,7 @@ import {
2121 UtxoProvider ,
2222 createSlotEpochInfoCalc
2323} from '@cardano-sdk/core' ;
24- import { HexBlob , fromSerializableObject } from '@cardano-sdk/util' ;
24+ import { HexBlob , fromSerializableObject , toSerializableObject } from '@cardano-sdk/util' ;
2525import { Logger } from 'ts-log' ;
2626import { Observable , ReplaySubject , Subject , filter , firstValueFrom , merge } from 'rxjs' ;
2727import WebSocket from 'isomorphic-ws' ;
@@ -294,6 +294,8 @@ export class CardanoWsClient extends WsProvider {
294294
295295 private createNetworkInfoProviderMethod < M extends NetworkInfoMethods > ( method : M ) {
296296 return async ( ) : Promise < AsyncReturnType < NetworkInfoProvider [ M ] > > => {
297+ this . logger . debug ( `CardanoWsClient.${ method } called` ) ;
298+
297299 // Take the first value from the method's observable or the first not ok health check not due to the provider is still starting
298300 const value = await firstValueFrom (
299301 merge (
@@ -303,8 +305,13 @@ export class CardanoWsClient extends WsProvider {
303305 ) ;
304306
305307 // If the value was an error different from starting, throw it, otherwise it is a return value for the method
306- if ( 'ok' in value && 'reason' in value && value . ok === false )
308+ if ( 'ok' in value && 'reason' in value && value . ok === false ) {
309+ this . logger . error ( `CardanoWsClient.${ method } error` , value . reason ) ;
310+
307311 throw new ProviderError ( ProviderFailure . ConnectionFailure , undefined , value . reason ) ;
312+ }
313+
314+ this . logger . debug ( `CardanoWsClient.${ method } response:` , toSerializableObject ( value ) ) ;
308315
309316 return value as AsyncReturnType < NetworkInfoProvider [ M ] > ;
310317 } ;
@@ -337,6 +344,8 @@ export class CardanoWsClient extends WsProvider {
337344 deserializeMetadata ( tx ) ;
338345 this . transactions [ tx . id ] = tx ;
339346 delete this . utxos [ tx . id ] ;
347+
348+ this . logger . debug ( 'CardanoWsClient got tx' , tx . id , tx . blockHeader ) ;
340349 }
341350
342351 if ( utxos )
@@ -358,6 +367,8 @@ export class CardanoWsClient extends WsProvider {
358367
359368 // Emit ledgerTip as last one
360369 if ( ledgerTip ) {
370+ this . logger . debug ( 'CardanoWsClient got tip' , ledgerTip ) ;
371+
361372 removeRolledBackTxs ( this . transactions , ledgerTip . blockNo ) ;
362373 removeRolledBackTxs ( this . utxos , ledgerTip . blockNo ) ;
363374
@@ -375,6 +386,8 @@ export class CardanoWsClient extends WsProvider {
375386 if ( responseTo ) {
376387 const handler = this . handlers . get ( responseTo ) ;
377388
389+ this . logger . debug ( 'CardanoWsClient response' , responseTo ) ;
390+
378391 if ( handler ) {
379392 const { error } = message ;
380393
@@ -466,6 +479,7 @@ export class CardanoWsClient extends WsProvider {
466479 // ... otherwise add requestId
467480 request = { ...request , requestId : ++ this . requestId } ;
468481
482+ this . logger . debug ( 'CardanoWsClient request' , request ) ;
469483 this . ws . send ( JSON . stringify ( request ) ) ;
470484 this . heartbeat ( ) ;
471485
@@ -474,17 +488,22 @@ export class CardanoWsClient extends WsProvider {
474488 return true ;
475489 }
476490
477- private transactionsByAddresses ( { addresses, blockRange, pagination } : TransactionsByAddressesArgs ) {
491+ private transactionsByAddresses ( args : TransactionsByAddressesArgs ) {
492+ const { addresses, blockRange, pagination } = args ;
493+
478494 // eslint-disable-next-line sonarjs/cognitive-complexity
479495 return new Promise < Paginated < Cardano . HydratedTx > > ( ( resolve , reject ) => {
480496 const lower = blockRange ?. lowerBound || ( 0 as Cardano . BlockNo ) ;
481497 const upper = blockRange ?. upperBound || Number . POSITIVE_INFINITY ;
482498 const requestAddresses : Cardano . PaymentAddress [ ] = [ ] ;
483499 const request = { addresses : requestAddresses , lower } ;
484500
485- const complete = ( error ?: Error ) => {
501+ this . logger . debug ( 'CardanoWsClient.transactionsByAddresses called' , args ) ;
502+
503+ const complete = ( error ?: Error ) : void => {
486504 if ( error ) {
487505 for ( const address of requestAddresses ) delete this . addresses [ address ] ;
506+ this . logger . error ( 'CardanoWsClient.transactionsByAddresses error' , args , error ) ;
488507
489508 return reject ( error ) ;
490509 }
@@ -498,8 +517,11 @@ export class CardanoWsClient extends WsProvider {
498517 const last = first + ( pagination ?. limit || Number . POSITIVE_INFINITY ) ;
499518
500519 const pageResults = transactions . filter ( ( _ , i ) => first <= i && i < last ) ;
520+ const result = { pageResults, totalResultCount : transactions . length } ;
521+
522+ this . logger . debug ( 'CardanoWsClient.transactionsByAddresses response' , args , toSerializableObject ( result ) ) ;
501523
502- resolve ( { pageResults , totalResultCount : transactions . length } ) ;
524+ resolve ( result ) ;
503525 } ;
504526
505527 // Check which addresses require sync
@@ -566,14 +588,23 @@ export class CardanoWsClient extends WsProvider {
566588
567589 // eslint-disable-next-line sonarjs/cognitive-complexity, complexity
568590 private utxoByAddresses ( { addresses } : UtxoByAddressesArgs ) {
591+ this . logger . debug ( 'CardanoWsClient.utxoByAddresses called' , addresses ) ;
592+
569593 for ( const address of addresses ) {
570594 const status = this . addresses [ address ] ;
595+ let details : string ;
596+
597+ if ( ! status ) {
598+ this . logger . error ( 'CardanoWsClient.utxoByAddresses error' , ( details = `${ address } not loaded` ) ) ;
571599
572- if ( ! status )
573- return Promise . reject ( new ProviderError ( ProviderFailure . NotImplemented , null , `${ address } not loaded` ) ) ;
600+ return Promise . reject ( new ProviderError ( ProviderFailure . NotImplemented , null , details ) ) ;
601+ }
602+
603+ if ( status . status === 'syncing' ) {
604+ this . logger . error ( 'CardanoWsClient.utxoByAddresses error' , ( details = `${ address } still loading` ) ) ;
574605
575- if ( status . status === 'syncing' )
576- return Promise . reject ( new ProviderError ( ProviderFailure . Conflict , null , ` ${ address } still loading` ) ) ;
606+ return Promise . reject ( new ProviderError ( ProviderFailure . Conflict , null , details ) ) ;
607+ }
577608 }
578609
579610 const result : [ Cardano . HydratedTxIn , Cardano . TxOut ] [ ] = [ ] ;
@@ -605,6 +636,8 @@ export class CardanoWsClient extends WsProvider {
605636 }
606637 }
607638
639+ this . logger . debug ( 'CardanoWsClient.utxoByAddresses response' , toSerializableObject ( result ) ) ;
640+
608641 return Promise . resolve ( result ) ;
609642 }
610643}
0 commit comments