-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from input-output-hk/feat/pool-metadata-task-…
…queue feat: pool metadata task queue / single-tenant projection support
- Loading branch information
Showing
128 changed files
with
3,672 additions
and
1,553 deletions.
There are no files selected for viewing
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,27 @@ | ||
## [projection-typeorm.js](./projection-typeorm.js) | ||
|
||
An example of [projection](../packages/projection/) into PostgreSQL database ([projection-typeorm](../packages/projection-typeorm/)). | ||
|
||
### Environment | ||
|
||
```sh | ||
cd /path/to/cardano-js-sdk/ # monorepo root | ||
yarn && yarn build | ||
yarn preprod:up cardano-node-ogmios postgres # or preview:up/mainnet:up | ||
``` | ||
|
||
### Configuration | ||
|
||
Projection can be customized by adding/removing operators and TypeORM entities, e.g. you may add those operators `Mappers.withStakeKeys(), ..., storeStakeKeys()` alongside with adding a `StakeKeyEntity`. | ||
|
||
### Running the script | ||
|
||
```sh | ||
node demo/projection-typeorm.js | ||
``` | ||
|
||
### Recreating the schema | ||
|
||
```sh | ||
node demo/projection-typeorm.js --drop | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Runtime dependency: `yarn preprod:up cardano-node-ogmios postgres` (can be any network) | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const { Bootstrap, Mappers, requestNext, logProjectionProgress } = require('@cardano-sdk/projection'); | ||
const { | ||
createDataSource, | ||
withTypeormTransaction, | ||
typeormTransactionCommit, | ||
TypeormStabilityWindowBuffer, | ||
BlockDataEntity, | ||
BlockEntity, | ||
StakePoolEntity, | ||
PoolRegistrationEntity, | ||
PoolRetirementEntity, | ||
OutputEntity, | ||
AssetEntity, | ||
TokensEntity, | ||
storeBlock, | ||
storeAssets, | ||
storeUtxo, | ||
storeStakePools, | ||
storeStakePoolMetadataJob, | ||
isRecoverableTypeormError | ||
} = require('@cardano-sdk/projection-typeorm'); | ||
const { OgmiosObservableCardanoNode } = require('@cardano-sdk/ogmios'); | ||
const { defer, from, of } = require('rxjs'); | ||
const { createDatabase } = require('typeorm-extension'); | ||
const { shareRetryBackoff } = require('@cardano-sdk/util-rxjs'); | ||
|
||
const logger = { | ||
...console, | ||
debug: () => void 0 | ||
}; | ||
|
||
const entities = [ | ||
BlockDataEntity, | ||
BlockEntity, | ||
StakePoolEntity, | ||
PoolRegistrationEntity, | ||
PoolRetirementEntity, | ||
AssetEntity, | ||
TokensEntity, | ||
OutputEntity | ||
]; | ||
const extensions = { | ||
pgBoss: true | ||
}; | ||
|
||
const cardanoNode = new OgmiosObservableCardanoNode( | ||
{ | ||
connectionConfig$: of({ | ||
port: 1339 | ||
}) | ||
}, | ||
{ logger } | ||
); | ||
const buffer = new TypeormStabilityWindowBuffer({ logger }); | ||
|
||
// #region TypeORM setup | ||
|
||
const connectionConfig = { | ||
database: 'projection', | ||
host: 'localhost', | ||
password: 'doNoUseThisSecret!', | ||
username: 'postgres' | ||
}; | ||
|
||
const dataSource$ = defer(() => | ||
from( | ||
(async () => { | ||
const dataSource = createDataSource({ | ||
connectionConfig, | ||
devOptions: process.argv.includes('--drop') | ||
? { | ||
dropSchema: true, | ||
synchronize: true | ||
} | ||
: undefined, | ||
entities, | ||
extensions, | ||
logger | ||
}); | ||
await createDatabase({ | ||
options: { | ||
type: 'postgres', | ||
...connectionConfig, | ||
installExtensions: true | ||
} | ||
}); | ||
await dataSource.initialize(); | ||
await buffer.initialize(dataSource.createQueryRunner()); | ||
return dataSource; | ||
})() | ||
) | ||
); | ||
|
||
// #endregion | ||
|
||
Bootstrap.fromCardanoNode({ | ||
buffer, | ||
cardanoNode, | ||
logger | ||
}) | ||
.pipe( | ||
Mappers.withCertificates(), | ||
Mappers.withStakePools(), | ||
Mappers.withMint(), | ||
Mappers.withUtxo(), | ||
// Single-tenant example | ||
// Mappers.filterProducedUtxoByAddresses({ | ||
// addresses: [ | ||
// 'addr_test1qpgn04xka0857kh6859za75tfvlrlu2lft0yc9z87598yjezw8yvpkv977yj5va20xmd9vw5fczfl3uu4expskz8adfqpydths' | ||
// ] | ||
// }), | ||
shareRetryBackoff( | ||
(evt$) => | ||
evt$.pipe( | ||
withTypeormTransaction({ dataSource$, logger }, extensions), | ||
storeBlock(), | ||
buffer.storeBlockData(), | ||
storeAssets(), | ||
storeUtxo(), | ||
storeStakePools(), | ||
storeStakePoolMetadataJob(), | ||
typeormTransactionCommit() | ||
), | ||
{ shouldRetry: isRecoverableTypeormError } | ||
), | ||
requestNext(), | ||
logProjectionProgress(logger) | ||
) | ||
.subscribe(); |
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
Oops, something went wrong.