Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: hoist bufferChainSyncEvent to projection package #1486

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable prefer-spread */
import { Bootstrap, ProjectionEvent, logProjectionProgress, requestNext } from '@cardano-sdk/projection';
import { Cardano, ObservableCardanoNode } from '@cardano-sdk/core';
import {
Bootstrap,
ObservableCardanoNode,
ProjectionEvent,
logProjectionProgress,
requestNext
} from '@cardano-sdk/projection';
import { Cardano } from '@cardano-sdk/core';
import { Logger } from 'ts-log';
import { Observable, concat, defer, groupBy, mergeMap, take, takeWhile } from 'rxjs';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import {
willStoreStakePools,
willStoreUtxo
} from '@cardano-sdk/projection-typeorm';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Mappers as Mapper, ProjectionEvent } from '@cardano-sdk/projection';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers as Mapper, ProjectionEvent } from '@cardano-sdk/projection';
import { ObservableType, passthrough } from '@cardano-sdk/util-rxjs';
import { POOLS_METRICS_INTERVAL_DEFAULT, POOLS_METRICS_OUTDATED_INTERVAL_DEFAULT } from '../Program/programs/types';
import { Sorter } from '@hapi/topo';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
HandleOwnerChangeError,
HandleProvider,
HealthCheckResponse,
ObservableCardanoNode,
ProviderError,
ProviderFailure,
SubmitTxArgs,
Expand All @@ -14,6 +13,7 @@ import {
} from '@cardano-sdk/core';
import { InMemoryCache } from '../InMemoryCache';
import { Logger } from 'ts-log';
import { ObservableCardanoNode } from '@cardano-sdk/projection';
import { WithLogger } from '@cardano-sdk/util';

type ObservableTxSubmitter = Pick<ObservableCardanoNode, 'healthCheck$' | 'submitTx'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
TokensEntity,
createDataSource
} from '@cardano-sdk/projection-typeorm';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncDataSet, chainSyncData, logger } from '@cardano-sdk/util-dev';
import { ChainSyncEventType } from '@cardano-sdk/projection';
import { ProjectionName, createTypeormProjection, prepareTypeormProjection } from '../../src';
import { lastValueFrom } from 'rxjs';
import { projectorConnectionConfig, projectorConnectionConfig$ } from '../util';
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/CardanoNode/types/CardanoNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HealthCheckResponse } from '../../Provider';
import type { Lovelace, PoolId, VrfVkHex } from '../../Cardano';
import type { Lovelace, PoolId, Tip, VrfVkHex } from '../../Cardano';
import type { Milliseconds } from '../../util';

export interface EraSummary {
Expand Down Expand Up @@ -48,3 +48,13 @@ export interface CardanoNode {
*/
healthCheck(): Promise<HealthCheckResponse>;
}

// Similar to Ogmios.Point, but using Cardano.BlockId opaque string for hash
export type Point = Pick<Tip, 'hash' | 'slot'>;
export type Origin = 'origin';
export type TipOrOrigin = Tip | Origin;
export type PointOrOrigin = Point | Origin;
export type Intersection = {
point: PointOrOrigin;
tip: TipOrOrigin;
};
1 change: 0 additions & 1 deletion packages/core/src/CardanoNode/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './CardanoNode';
export * from './CardanoNodeErrors';
export * from './ObservableCardanoNode';
14 changes: 5 additions & 9 deletions packages/e2e/test/projection/offline-fork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ import * as Postgres from '@cardano-sdk/projection-typeorm';
import { BlockDataEntity, BlockEntity, StakeKeyEntity } from '@cardano-sdk/projection-typeorm';
import {
Bootstrap,
ChainSyncEvent,
ChainSyncEventType,
ChainSyncRollForward,
InMemory,
Mappers,
ObservableCardanoNode,
ProjectionEvent,
ProjectionOperator,
StabilityWindowBuffer,
WithBlock,
requestNext,
withStaticContext
} from '@cardano-sdk/projection';
import {
Cardano,
ChainSyncEvent,
ChainSyncEventType,
ChainSyncRollForward,
ObservableCardanoNode,
Point,
TipOrOrigin
} from '@cardano-sdk/core';
import { Cardano, Point, TipOrOrigin } from '@cardano-sdk/core';
import { ChainSyncDataSet, chainSyncData, logger } from '@cardano-sdk/util-dev';
import { ConnectionConfig } from '@cardano-ogmios/client';
import { Observable, filter, firstValueFrom, lastValueFrom, map, of, take, takeWhile, throwError, toArray } from 'rxjs';
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/test/projection/single-tenant-utxo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Postgres from '@cardano-sdk/projection-typeorm';
import { Bootstrap, Mappers, ProjectionEvent, requestNext } from '@cardano-sdk/projection';
import { Cardano, ObservableCardanoNode } from '@cardano-sdk/core';
import { Bootstrap, Mappers, ObservableCardanoNode, ProjectionEvent, requestNext } from '@cardano-sdk/projection';
import { Cardano } from '@cardano-sdk/core';
import { ConnectionConfig } from '@cardano-ogmios/client';
import { DataSource, QueryRunner } from 'typeorm';
import { Observable, filter, firstValueFrom, lastValueFrom, of, scan, takeWhile } from 'rxjs';
Expand Down
1 change: 1 addition & 0 deletions packages/golden-test-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dependencies": {
"@cardano-sdk/core": "workspace:~",
"@cardano-sdk/ogmios": "workspace:~",
"@cardano-sdk/projection": "workspace:~",
"@cardano-sdk/util": "workspace:~",
"@cardano-sdk/util-dev": "workspace:~",
"bunyan": "^1.8.15",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cardano, ChainSyncEventType, Intersection } from '@cardano-sdk/core';
import { Cardano, Intersection } from '@cardano-sdk/core';
import { ChainSyncEventType } from '@cardano-sdk/projection';
import { GeneratorMetadata } from '../Content';
import { Logger } from 'ts-log';
import { Ogmios, ogmiosToCore } from '@cardano-sdk/ogmios';
Expand Down
3 changes: 3 additions & 0 deletions packages/golden-test-generator/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
{
"path": "../../util/src"
},
{
"path": "../../projection/src"
}
]
}
1 change: 1 addition & 0 deletions packages/ogmios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@cardano-ogmios/schema": "6.5.0",
"@cardano-sdk/core": "workspace:~",
"@cardano-sdk/crypto": "workspace:~",
"@cardano-sdk/projection": "workspace:~",
"@cardano-sdk/util": "workspace:~",
"backoff-rxjs": "^7.0.0",
"buffer": "5.7.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
GeneralCardanoNodeErrorCode,
HealthCheckResponse,
Milliseconds,
ObservableCardanoNode,
ObservableChainSync,
PointOrOrigin,
StakeDistribution,
StateQueryErrorCode
Expand Down Expand Up @@ -49,6 +47,7 @@ import {
withCoreCardanoNodeError
} from '../queries';
import isEqual from 'lodash/isEqual.js';
import type { ObservableCardanoNode, ObservableChainSync } from '@cardano-sdk/projection';
import type { Serialization } from '@cardano-sdk/core';

const ogmiosToCoreIntersection = (intersection: ChainSynchronization.Intersection) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
ChainSyncEvent,
ChainSyncEventType,
GeneralCardanoNodeError,
GeneralCardanoNodeErrorCode,
PointOrOrigin,
RequestNext
} from '@cardano-sdk/core';
import { ChainSyncEvent, ChainSyncEventType, RequestNext } from '@cardano-sdk/projection';
import { ChainSynchronization, InteractionContext, Schema, safeJSON } from '@cardano-ogmios/client';
import { GeneralCardanoNodeError, GeneralCardanoNodeErrorCode, PointOrOrigin } from '@cardano-sdk/core';
import { Logger } from 'ts-log';
import { Observable, Subscriber, from, switchMap } from 'rxjs';
import { WithLogger, toSerializableObject } from '@cardano-sdk/util';
Expand Down
3 changes: 3 additions & 0 deletions packages/ogmios/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{
"path": "../../util-rxjs/src"
},
{
"path": "../../projection/src"
},
{
"path": "../../crypto/src"
}
Expand Down
10 changes: 8 additions & 2 deletions packages/projection-typeorm/src/TypeormStabilityWindowBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { BlockDataEntity } from './entity';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import {
ChainSyncEventType,
ProjectionEvent,
RollForwardEvent,
StabilityWindowBuffer,
WithNetworkInfo
} from '@cardano-sdk/projection';
import { LessThan, QueryRunner } from 'typeorm';
import { Logger } from 'ts-log';
import { Observable, catchError, concatMap, from, map, of, switchMap, take } from 'rxjs';
import { ProjectionEvent, RollForwardEvent, StabilityWindowBuffer, WithNetworkInfo } from '@cardano-sdk/projection';
import { ReconnectionConfig } from '@cardano-sdk/util-rxjs';
import { RetryBackoffConfig, retryBackoff } from 'backoff-rxjs';
import { TypeormConnection } from './createDataSource';
Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/createTypeormTipTracker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BaseProjectionEvent } from '@cardano-sdk/projection';
import { BaseProjectionEvent, ChainSyncEventType } from '@cardano-sdk/projection';
import { BlockEntity } from './entity';
import { ChainSyncEventType, TipOrOrigin } from '@cardano-sdk/core';
import { Observable, ReplaySubject, from, map, of, switchMap, take, tap } from 'rxjs';
import { ReconnectionConfig } from '@cardano-sdk/util-rxjs';
import { RetryBackoffConfig, retryBackoff } from 'backoff-rxjs';
import { TipOrOrigin } from '@cardano-sdk/core';
import { TypeormConnection } from './createDataSource';
import { isRecoverableTypeormError } from './isRecoverableTypeormError';

Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/operators/storeAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AddressEntity } from '../entity/Address.entity';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { Hash28ByteBase16 } from '@cardano-sdk/crypto';
import { Mappers } from '@cardano-sdk/projection';
import { QueryRunner } from 'typeorm';
import { StakeKeyRegistrationEntity } from '../entity';
import { certificatePointerToId, typeormOperator } from './util';
Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/operators/storeAssets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AssetEntity } from '../entity';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Mappers } from '@cardano-sdk/projection';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { QueryRunner } from 'typeorm';
import { typeormOperator } from './util';

Expand Down
2 changes: 1 addition & 1 deletion packages/projection-typeorm/src/operators/storeBlock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BlockEntity } from '../entity';
import { ChainSyncEventType } from '@cardano-sdk/core';
import { ChainSyncEventType } from '@cardano-sdk/projection';
import { typeormOperator } from './util';

export const storeBlock = typeormOperator(async (evt) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { GovernanceActionEntity } from '../entity';
import { Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { typeormOperator } from './util';

export const willStoreGovernanceAction = (evt: ProjectionEvent<Mappers.WithGovernanceActions>) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChainSyncEventType } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { HandleMetadataEntity } from '../entity';
import { Mappers } from '@cardano-sdk/projection';
import { WithStoredProducedUtxo } from './storeUtxo';
import { typeormOperator } from './util';

Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/operators/storeHandles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssetEntity, HandleEntity, HandleMetadataEntity } from '../entity';
import { Cardano, ChainSyncEventType, Handle } from '@cardano-sdk/core';
import { Cardano, Handle } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { In, QueryRunner } from 'typeorm';
import { Mappers } from '@cardano-sdk/projection';
import { WithMintedAssetSupplies } from './storeAssets';
import { typeormOperator } from './util';
import sortBy from 'lodash/sortBy.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/operators/storeNftMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Asset, Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Asset, Cardano } from '@cardano-sdk/core';
import { AssetEntity, NftMetadataEntity, NftMetadataType } from '../entity';
import { Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { ChainSyncEventType, Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { Repository } from 'typeorm';
import { typeormOperator } from './util';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType } from '@cardano-sdk/projection';
import { STAKE_POOL_METRICS_UPDATE } from '../pgBoss';
import { WithPgBoss } from './withTypeormTransaction';
import { typeormOperator } from './util';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChainSyncEventType } from '@cardano-sdk/core';
import { Mappers } from '@cardano-sdk/projection';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { StakeKeyRegistrationEntity } from '../entity';
import { certificatePointerToId, typeormOperator } from './util';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChainSyncEventType } from '@cardano-sdk/core';
import { Mappers } from '@cardano-sdk/projection';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { STAKE_POOL_METADATA_QUEUE, StakePoolMetadataJob, defaultJobOptions } from '../pgBoss';
import { WithPgBoss } from './withTypeormTransaction';
import { certificatePointerToId, typeormOperator } from './util';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType } from '@cardano-sdk/projection';
import { STAKE_POOL_REWARDS, defaultJobOptions } from '../pgBoss';
import { WithPgBoss } from './withTypeormTransaction';
import { typeormOperator } from './util';
Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/operators/storeStakePools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cardano, ChainSyncEventType, EraSummary, epochSlotsCalc } from '@cardano-sdk/core';
import { Cardano, EraSummary, epochSlotsCalc } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { In, Not, QueryRunner, Repository } from 'typeorm';
import { Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import {
MaxCertificatePointerIdCertificateIndex as MaxCertificatePointerIdCertIndex,
MaxCertificatePointerIdTxIndex,
Expand Down
4 changes: 2 additions & 2 deletions packages/projection-typeorm/src/operators/storeUtxo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cardano, ChainSyncEventType, Serialization } from '@cardano-sdk/core';
import { Mappers } from '@cardano-sdk/projection';
import { Cardano, Serialization } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers } from '@cardano-sdk/projection';
import { ObjectLiteral } from 'typeorm';
import { OutputEntity, TokensEntity } from '../entity';
import { typeormOperator } from './util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
createObservableConnection,
willStoreBlockData
} from '../src';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType, ProjectionEvent } from '@cardano-sdk/projection';
import { DataSource, NoConnectionForRepositoryError, QueryRunner, Repository } from 'typeorm';
import { ProjectionEvent } from '@cardano-sdk/projection';
import { connectionConfig$, createBlockEntity, createBlockHeader, initializeDataSource } from './util';
import { createStubObservable, logger } from '@cardano-sdk/util-dev';
import { firstValueFrom, of, throwError } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseProjectionEvent } from '@cardano-sdk/projection';
import { BaseProjectionEvent, ChainSyncEventType } from '@cardano-sdk/projection';
import {
BlockEntity,
TypeormConnection,
TypeormTipTracker,
createObservableConnection,
createTypeormTipTracker
} from '../src';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { DataSource, NoConnectionForRepositoryError, QueryRunner, Repository } from 'typeorm';
import { Observable, firstValueFrom, of, throwError } from 'rxjs';
import { RetryBackoffConfig } from 'backoff-rxjs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
willStoreAssets,
withTypeormTransaction
} from '../../src';
import { Bootstrap, Mappers, requestNext } from '@cardano-sdk/projection';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Bootstrap, ChainSyncEventType, Mappers, requestNext } from '@cardano-sdk/projection';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncDataSet, chainSyncData, logger } from '@cardano-sdk/util-dev';
import { Mint } from '@cardano-sdk/projection/dist/cjs/operators/Mappers';
import { QueryRunner } from 'typeorm';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BlockEntity, GovernanceActionEntity } from '../../src';
import { Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncEventType, Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { DataSource, QueryRunner } from 'typeorm';
import { Mappers, ProjectionEvent } from '@cardano-sdk/projection';
import { WithTypeormContext, storeBlock, storeGovernanceAction } from '../../src/operators';
import { firstValueFrom, of } from 'rxjs';
import { initializeDataSource } from '../util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
willStoreHandleMetadata,
withTypeormTransaction
} from '../../src';
import { Bootstrap, Mappers, ProjectionEvent, requestNext } from '@cardano-sdk/projection';
import { Cardano, ObservableCardanoNode } from '@cardano-sdk/core';
import { Bootstrap, Mappers, ObservableCardanoNode, ProjectionEvent, requestNext } from '@cardano-sdk/projection';
import { Cardano } from '@cardano-sdk/core';
import { ChainSyncDataSet, chainSyncData, logger } from '@cardano-sdk/util-dev';
import { HandleMetadata } from '@cardano-sdk/projection/dist/cjs/operators/Mappers';
import { Observable, firstValueFrom } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Asset, Cardano, ChainSyncEventType } from '@cardano-sdk/core';
import { Asset, Cardano } from '@cardano-sdk/core';
import { AssetEntity, HandleEntity, OutputEntity, willStoreHandles } from '../../../src';
import { ChainSyncEventType } from '@cardano-sdk/projection';
import { HandleOwnership } from '@cardano-sdk/projection/dist/cjs/operators/Mappers';
import { ProjectorContext, createProjectorContext } from '../util';
import { QueryRunner } from 'typeorm';
Expand Down
Loading
Loading