-
Notifications
You must be signed in to change notification settings - Fork 54
/
genesis.ts
30 lines (28 loc) · 1.13 KB
/
genesis.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { GenesisData } from '../types';
import { ProviderError, ProviderFailure } from '@cardano-sdk/core';
import JSONbig from 'json-bigint';
import fs from 'fs';
import path from 'path';
export const loadGenesisData = async (cardanoNodeConfigPath: string): Promise<GenesisData> => {
try {
const genesisFilePath = require(path.resolve(cardanoNodeConfigPath)).ShelleyGenesisFile;
const genesis = JSONbig({ useNativeBigInt: true }).parse(
fs.readFileSync(path.resolve(path.dirname(cardanoNodeConfigPath), genesisFilePath), 'utf-8')
);
return {
activeSlotsCoefficient: genesis.activeSlotsCoeff,
epochLength: genesis.epochLength,
maxKesEvolutions: genesis.maxKESEvolutions,
maxLovelaceSupply: genesis.maxLovelaceSupply,
networkId: genesis.networkId,
networkMagic: genesis.networkMagic,
securityParameter: genesis.securityParam,
slotLength: genesis.slotLength,
slotsPerKesPeriod: genesis.slotsPerKESPeriod,
systemStart: genesis.systemStart,
updateQuorum: genesis.updateQuorum
};
} catch (error) {
throw new ProviderError(ProviderFailure.Unhealthy, error);
}
};