Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cardano-services): add NetworkInfoHttpService
- extend env vars with CARDANO_NODE_CONFIG_PATH - create NetworkInfoHttpService - implement loadConfigs method to load genesis configs - extend loadHttpServer with NetworkInfo service attached on demand
- Loading branch information
Ivaylo Andonov
committed
May 23, 2022
1 parent
e3d6876
commit 5f5f007
Showing
9 changed files
with
115 additions
and
89 deletions.
There are no files selected for viewing
21 changes: 12 additions & 9 deletions
21
...s/cardano-services/src/NetworkInfo/DbSyncNetworkInfoProvider/DbSyncNetworkInfoProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
...ges/cardano-services/src/NetworkInfo/DbSyncNetworkInfoProvider/shelleyGenesisTestnet.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/cardano-services/src/NetworkInfo/NetworkInfoHttpService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DbSyncNetworkInfoProvider } from './DbSyncNetworkInfoProvider'; | ||
import { HttpServer, HttpService } from '../Http'; | ||
import { Logger, dummyLogger } from 'ts-log'; | ||
import { NetworkInfo, ProviderError, ProviderFailure } from '@cardano-sdk/core'; | ||
import { ServiceNames } from '../Program'; | ||
import { providerHandler } from '../util'; | ||
import express from 'express'; | ||
|
||
export interface NetworkInfoServiceDependencies { | ||
logger?: Logger; | ||
networkInfoProvider: DbSyncNetworkInfoProvider; | ||
} | ||
|
||
export class NetworkInfoHttpService extends HttpService { | ||
private constructor({ logger = dummyLogger }: NetworkInfoServiceDependencies, router: express.Router) { | ||
super(ServiceNames.NetworkInfo, router, logger); | ||
} | ||
|
||
async healthCheck() { | ||
return Promise.resolve({ ok: true }); | ||
} | ||
|
||
static create({ logger = dummyLogger, networkInfoProvider }: NetworkInfoServiceDependencies) { | ||
const router = express.Router(); | ||
|
||
router.post( | ||
'/network', | ||
providerHandler<[], NetworkInfo>(async (_, __, res) => { | ||
try { | ||
return HttpServer.sendJSON(res, await networkInfoProvider.networkInfo()); | ||
} catch (error) { | ||
logger.error(error); | ||
return HttpServer.sendJSON(res, new ProviderError(ProviderFailure.Unhealthy, error), 500); | ||
} | ||
}, logger) | ||
); | ||
return new NetworkInfoHttpService({ logger, networkInfoProvider }, router); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters