|
1 | 1 | import {
|
| 2 | + Cardano, |
2 | 3 | CardanoNodeErrors,
|
3 | 4 | ChainSyncEvent,
|
4 | 5 | ChainSyncEventType,
|
| 6 | + ChainSyncRollBackward, |
| 7 | + ChainSyncRollForward, |
| 8 | + Intersection, |
5 | 9 | ObservableCardanoNode,
|
6 | 10 | Point,
|
7 | 11 | PointOrOrigin
|
8 | 12 | } from '@cardano-sdk/core';
|
9 |
| -import { ChainSyncData } from '../../../golden-test-generator/src'; |
10 | 13 | import { Observable, of } from 'rxjs';
|
11 |
| -import { SerializedChainSyncEvent } from '../../../golden-test-generator/src/ChainSyncEvents'; |
12 | 14 | import { genesisToEraSummary } from './genesisToEraSummary';
|
| 15 | +import memoize from 'lodash/memoize'; |
| 16 | + |
| 17 | +export type SerializedChainSyncEvent = |
| 18 | + | Omit<ChainSyncRollForward, 'requestNext'> |
| 19 | + | Omit<ChainSyncRollBackward, 'requestNext'>; |
| 20 | + |
| 21 | +export type ChainSyncMetadata = { |
| 22 | + cardano: { |
| 23 | + compactGenesis: Cardano.CompactGenesis; |
| 24 | + intersection: Intersection; |
| 25 | + }; |
| 26 | +}; |
| 27 | + |
| 28 | +export type ChainSyncData = { |
| 29 | + body: SerializedChainSyncEvent[]; |
| 30 | + metadata: ChainSyncMetadata; |
| 31 | +}; |
| 32 | + |
| 33 | +export * from './genesisToEraSummary'; |
13 | 34 |
|
14 | 35 | const intersect = (events: ChainSyncData['body'], points: PointOrOrigin[]) => {
|
15 | 36 | const blockPoints = points.filter((point): point is Point => point !== 'origin');
|
@@ -65,13 +86,18 @@ const intersect = (events: ChainSyncData['body'], points: PointOrOrigin[]) => {
|
65 | 86 | throw new CardanoNodeErrors.CardanoClientErrors.IntersectionNotFoundError(points as any[]);
|
66 | 87 | };
|
67 | 88 |
|
68 |
| -const prepareData = (dataFileName: string) => { |
| 89 | +export enum ChainSyncDataSet { |
| 90 | + WithPoolRetirement = 'with-pool-retirement.json', |
| 91 | + WithStakeKeyDeregistration = 'with-stake-key-deregistration.json' |
| 92 | +} |
| 93 | + |
| 94 | +export const chainSyncData = memoize((dataSet: ChainSyncDataSet) => { |
69 | 95 | const {
|
70 | 96 | body: allEvents,
|
71 | 97 | metadata: {
|
72 | 98 | cardano: { compactGenesis }
|
73 | 99 | }
|
74 |
| - } = require(`./data/${dataFileName}`) as ChainSyncData; |
| 100 | + } = require(`./data/${dataSet}`) as ChainSyncData; |
75 | 101 | const eraSummaries = [genesisToEraSummary(compactGenesis)];
|
76 | 102 | const cardanoNode: ObservableCardanoNode = {
|
77 | 103 | eraSummaries$: of(eraSummaries),
|
@@ -106,8 +132,6 @@ const prepareData = (dataFileName: string) => {
|
106 | 132 | genesisParameters: compactGenesis
|
107 | 133 | }
|
108 | 134 | };
|
109 |
| -}; |
110 |
| -export type StubChainSyncData = ReturnType<typeof prepareData>; |
| 135 | +}); |
111 | 136 |
|
112 |
| -export const dataWithPoolRetirement = prepareData('with-pool-retirement.json'); |
113 |
| -export const dataWithStakeKeyDeregistration = prepareData('with-stake-key-deregistration'); |
| 137 | +export type StubChainSyncData = ReturnType<typeof chainSyncData>; |
0 commit comments