Skip to content

Commit

Permalink
refactor(ogmios): remove duplication in healthCheck code
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Mar 16, 2023
1 parent b7f23bf commit a911199
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
8 changes: 6 additions & 2 deletions packages/ogmios/src/CardanoNode/OgmiosCardanoNode.ts
Expand Up @@ -89,10 +89,14 @@ export class OgmiosCardanoNode extends RunnableModule implements CardanoNode {
}
}

async healthCheck(): Promise<HealthCheckResponse> {
healthCheck(): Promise<HealthCheckResponse> {
return OgmiosCardanoNode.healthCheck(this.#connectionConfig);
}

static async healthCheck(connectionConfig: ConnectionConfig): Promise<HealthCheckResponse> {
try {
const { networkSynchronization, lastKnownTip } = await getServerHealth({
connection: createConnectionObject(this.#connectionConfig)
connection: createConnectionObject(connectionConfig)
});
return {
localNode: {
Expand Down
Expand Up @@ -4,8 +4,6 @@ import {
CardanoNodeErrors,
HealthCheckResponse,
ProviderDependencies,
ProviderError,
ProviderFailure,
SubmitTxArgs,
TxSubmitProvider
} from '@cardano-sdk/core';
Expand All @@ -14,11 +12,10 @@ import {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
TxSubmission,
createConnectionObject,
createTxSubmissionClient,
getServerHealth
createTxSubmissionClient
} from '@cardano-ogmios/client';
import { Logger } from 'ts-log';
import { OgmiosCardanoNode } from '../../CardanoNode';
import { RunnableModule, contextLogger, isNotNil } from '@cardano-sdk/util';
import { createInteractionContextWithLogger } from '../../util';

Expand Down Expand Up @@ -80,24 +77,7 @@ export class OgmiosTxSubmitProvider extends RunnableModule implements TxSubmitPr
}

async healthCheck(): Promise<HealthCheckResponse> {
try {
const { networkSynchronization, lastKnownTip } = await getServerHealth({
connection: createConnectionObject(this.#connectionConfig)
});
return {
localNode: {
ledgerTip: lastKnownTip,
networkSync: Cardano.Percent(networkSynchronization)
},
ok: networkSynchronization > 0.99
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.name === 'FetchError') {
return { ok: false };
}
throw new ProviderError(ProviderFailure.Unknown, error);
}
return OgmiosCardanoNode.healthCheck(this.#connectionConfig);
}

async startImpl(): Promise<void> {
Expand Down

0 comments on commit a911199

Please sign in to comment.