Skip to content

Commit 0d138c9

Browse files
authored
Merge pull request #1421 from input-output-hk/feat/LW-11005-protocol-parameters-projection
LW-11005 Governance action proposals projection
2 parents bb3d3e8 + e4349d0 commit 0d138c9

File tree

16 files changed

+303
-5
lines changed

16 files changed

+303
-5
lines changed

compose/common.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ x-with-postgres: &with-postgres
4444
- postgres_db_db_sync
4545
- postgres_db_handle
4646
- postgres_db_stake_pool
47+
- postgres_db_wallet_api
4748

4849
x-projector-environment: &projector-environment
4950
API_URL: http://0.0.0.0:3000
@@ -78,26 +79,32 @@ x-sdk-environment: &sdk-environment
7879
POSTGRES_DB_FILE_DB_SYNC: /run/secrets/postgres_db_db_sync
7980
POSTGRES_DB_FILE_HANDLE: /run/secrets/postgres_db_handle
8081
POSTGRES_DB_FILE_STAKE_POOL: /run/secrets/postgres_db_stake_pool
82+
POSTGRES_DB_FILE_WALLET_API: /run/secrets/postgres_db_wallet_api
8183
POSTGRES_HOST_DB_SYNC: postgres
8284
POSTGRES_HOST_ASSET: postgres
8385
POSTGRES_HOST_HANDLE: postgres
8486
POSTGRES_HOST_STAKE_POOL: postgres
87+
POSTGRES_HOST_WALLET_API: postgres
8588
POSTGRES_POOL_MAX_DB_SYNC: ${POSTGRES_POOL_MAX:-10}
8689
POSTGRES_POOL_MAX_HANDLE: ${POSTGRES_POOL_MAX:-10}
8790
POSTGRES_POOL_MAX_ASSET: ${POSTGRES_POOL_MAX:-10}
8891
POSTGRES_POOL_MAX_STAKE_POOL: ${POSTGRES_POOL_MAX:-10}
92+
POSTGRES_POOL_MAX_WALLET_API: ${POSTGRES_POOL_MAX:-10}
8993
POSTGRES_PASSWORD_FILE_ASSET: /run/secrets/postgres_password
9094
POSTGRES_PASSWORD_FILE_DB_SYNC: /run/secrets/postgres_password
9195
POSTGRES_PASSWORD_FILE_HANDLE: /run/secrets/postgres_password
9296
POSTGRES_PASSWORD_FILE_STAKE_POOL: /run/secrets/postgres_password
97+
POSTGRES_PASSWORD_FILE_WALLET_API: /run/secrets/postgres_password
9398
POSTGRES_PORT_DB_SYNC: 5432
9499
POSTGRES_PORT_ASSET: 5432
95100
POSTGRES_PORT_HANDLE: 5432
96101
POSTGRES_PORT_STAKE_POOL: 5432
102+
POSTGRES_PORT_WALLET_API: 5432
97103
POSTGRES_USER_FILE_ASSET: /run/secrets/postgres_user
98104
POSTGRES_USER_FILE_DB_SYNC: /run/secrets/postgres_user
99105
POSTGRES_USER_FILE_HANDLE: /run/secrets/postgres_user
100106
POSTGRES_USER_FILE_STAKE_POOL: /run/secrets/postgres_user
107+
POSTGRES_USER_FILE_WALLET_API: /run/secrets/postgres_user
101108
TOKEN_METADATA_SERVER_URL: https://metadata.world.dev.cardano.org
102109
USE_WEB_SOCKET_API: true
103110
WEB_SOCKET_API_URL: ws://ws-server:3000/ws
@@ -294,6 +301,21 @@ services:
294301
ports:
295302
- ${STAKE_POOL_PROJECTOR_PORT:-4002}:3000
296303

304+
wallet-api-projector:
305+
<<:
306+
- *from-sdk
307+
- *logging
308+
- *projector
309+
- *with-postgres
310+
environment:
311+
<<:
312+
- *projector-environment
313+
- *sdk-environment
314+
POSTGRES_DB_FILE: /run/secrets/postgres_db_wallet_api
315+
PROJECTION_NAMES: protocol-parameters
316+
ports:
317+
- ${WALLET_API_PROJECTOR_PORT:-4005}:3000
318+
297319
provider-server:
298320
<<:
299321
- *from-sdk
@@ -400,6 +422,8 @@ secrets:
400422
file: ../../compose/placeholder-secrets/postgres_db_handle
401423
postgres_db_stake_pool:
402424
file: ../../compose/placeholder-secrets/postgres_db_stake_pool
425+
postgres_db_wallet_api:
426+
file: ../../compose/placeholder-secrets/postgres_db_wallet_api
403427
postgres_password:
404428
file: ../../compose/placeholder-secrets/postgres_password
405429
postgres_user:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wallet_api

packages/cardano-services/src/Program/options/postgres.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface BasePosgresProgramOptions {
3333
postgresSslCaFile?: string;
3434
}
3535

36-
export type ConnectionNames = 'DbSync' | 'Handle' | 'StakePool' | 'Asset' | '';
36+
export type ConnectionNames = 'Asset' | 'DbSync' | 'Handle' | 'StakePool' | 'WalletApi' | '';
3737

3838
export type PosgresProgramOptions<
3939
Suffix extends ConnectionNames,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { GovernanceActionEntity } from '@cardano-sdk/projection-typeorm';
2+
import { MigrationInterface, QueryRunner } from 'typeorm';
3+
4+
export class GovernanceActionMigration1724168174191 implements MigrationInterface {
5+
static entity = GovernanceActionEntity;
6+
7+
public async up(queryRunner: QueryRunner): Promise<void> {
8+
await queryRunner.query(
9+
'CREATE TABLE "governance_action" ("id" SERIAL NOT NULL, "tx_id" character varying NOT NULL, "index" smallint NOT NULL, "stake_credential_hash" character varying NOT NULL, "anchor_url" character varying NOT NULL, "anchor_hash" character(64), "deposit" bigint NOT NULL, "action" character varying NOT NULL, "block_slot" integer NOT NULL, CONSTRAINT "PK_governance_action_id" PRIMARY KEY ("id"))'
10+
);
11+
await queryRunner.query(
12+
'ALTER TABLE "governance_action" ADD CONSTRAINT "FK_governance_action_block_slot" FOREIGN KEY ("block_slot") REFERENCES "block"("slot") ON DELETE CASCADE ON UPDATE NO ACTION'
13+
);
14+
}
15+
16+
public async down(queryRunner: QueryRunner): Promise<void> {
17+
await queryRunner.query('ALTER TABLE "governance_action" DROP CONSTRAINT "FK_governance_action_block_slot"');
18+
await queryRunner.query('DROP TABLE "governance_action"');
19+
}
20+
}

packages/cardano-services/src/Projection/migrations/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CostPledgeNumericMigration1689091319930 } from './1689091319930-cost-pl
66
import { CurrentStakePollMetricsAttributesMigrations1698174358997 } from './1698174358997-current-pool-metrics-attributes';
77
import { FkPoolRegistrationMigration1682519108369 } from './1682519108369-fk-pool-registration';
88
import { FkPoolRetirementMigration1682519108370 } from './1682519108370-fk-pool-retirement';
9+
import { GovernanceActionMigration1724168174191 } from './1724168174191-governance-actions-table';
910
import { HandleDefaultMigrations1693830294136 } from './1693830294136-handle-default-columns';
1011
import { HandleMetadataTableMigrations1693490983715 } from './1693490983715-handle-metadata-table';
1112
import { HandleParentMigration1700556589063 } from './1700556589063-handle-parent';
@@ -53,5 +54,6 @@ export const migrations: ProjectionMigration[] = [
5354
CurrentStakePollMetricsAttributesMigrations1698174358997,
5455
PoolRewardsTableMigrations1698175956871,
5556
HandleParentMigration1700556589063,
56-
RewardsPledgeNumericMigration1715157190230
57+
RewardsPledgeNumericMigration1715157190230,
58+
GovernanceActionMigration1724168174191
5759
];

packages/cardano-services/src/Projection/prepareTypeormProjection.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BlockEntity,
66
CurrentPoolMetricsEntity,
77
DataSourceExtensions,
8+
GovernanceActionEntity,
89
HandleEntity,
910
HandleMetadataEntity,
1011
NftMetadataEntity,
@@ -22,6 +23,7 @@ import {
2223
storeAddresses,
2324
storeAssets,
2425
storeBlock,
26+
storeGovernanceAction,
2527
storeHandleMetadata,
2628
storeHandles,
2729
storeNftMetadata,
@@ -32,6 +34,7 @@ import {
3234
willStoreAddresses,
3335
willStoreAssets,
3436
willStoreBlockData,
37+
willStoreGovernanceAction,
3538
willStoreHandleMetadata,
3639
willStoreHandles,
3740
willStoreNftMetadata,
@@ -53,6 +56,7 @@ export enum ProjectionName {
5356
Address = 'address',
5457
Asset = 'asset',
5558
Handle = 'handle',
59+
ProtocolParameters = 'protocol-parameters',
5660
StakePool = 'stake-pool',
5761
StakePoolMetadataJob = 'stake-pool-metadata-job',
5862
StakePoolMetricsJob = 'stake-pool-metrics-job',
@@ -112,6 +116,7 @@ export const storeOperators = {
112116
storeAddresses: storeAddresses(),
113117
storeAssets: storeAssets(),
114118
storeBlock: storeBlock(),
119+
storeGovernanceAction: storeGovernanceAction(),
115120
storeHandleMetadata: storeHandleMetadata(),
116121
storeHandles: storeHandles(),
117122
storeNftMetadata: storeNftMetadata(),
@@ -138,6 +143,7 @@ type WillStore = {
138143
const willStore: Partial<WillStore> = {
139144
storeAddresses: willStoreAddresses,
140145
storeAssets: willStoreAssets,
146+
storeGovernanceAction: willStoreGovernanceAction,
141147
storeHandleMetadata: willStoreHandleMetadata,
142148
storeHandles: willStoreHandles,
143149
storeNftMetadata: willStoreNftMetadata,
@@ -154,6 +160,7 @@ const entities = {
154160
block: BlockEntity,
155161
blockData: BlockDataEntity,
156162
currentPoolMetrics: CurrentPoolMetricsEntity,
163+
governanceAction: GovernanceActionEntity,
157164
handle: HandleEntity,
158165
handleMetadata: HandleMetadataEntity,
159166
nftMetadata: NftMetadataEntity,
@@ -176,6 +183,7 @@ const storeEntities: Partial<Record<StoreName, EntityName[]>> = {
176183
storeAddresses: ['address'],
177184
storeAssets: ['asset'],
178185
storeBlock: ['block', 'blockData'],
186+
storeGovernanceAction: ['governanceAction'],
179187
storeHandleMetadata: ['handleMetadata', 'output'],
180188
storeHandles: ['handle', 'asset', 'tokens', 'output'],
181189
storeNftMetadata: ['asset'],
@@ -194,6 +202,7 @@ const entityInterDependencies: Partial<Record<EntityName, EntityName[]>> = {
194202
asset: ['block', 'nftMetadata'],
195203
blockData: ['block'],
196204
currentPoolMetrics: ['stakePool'],
205+
governanceAction: ['block'],
197206
handle: ['asset'],
198207
handleMetadata: ['output'],
199208
output: ['block', 'tokens'],
@@ -253,6 +262,7 @@ const storeMapperDependencies: Partial<Record<StoreName, MapperName[]>> = {
253262
const storeInterDependencies: Partial<Record<StoreName, StoreName[]>> = {
254263
storeAddresses: ['storeBlock', 'storeStakeKeyRegistrations'],
255264
storeAssets: ['storeBlock'],
265+
storeGovernanceAction: ['storeBlock'],
256266
storeHandleMetadata: ['storeUtxo'],
257267
storeHandles: ['storeUtxo', 'storeAddresses', 'storeHandleMetadata'],
258268
storeNftMetadata: ['storeAssets'],
@@ -269,6 +279,7 @@ const projectionStoreDependencies: Record<ProjectionName, StoreName[]> = {
269279
// TODO: remove storeNftMetadata when TypeormAssetProvider tests
270280
// are updated to use 'asset' database instead of a handle database
271281
handle: ['storeHandles', 'storeHandleMetadata', 'storeNftMetadata'],
282+
'protocol-parameters': ['storeGovernanceAction'],
272283
'stake-pool': ['storeStakePools'],
273284
'stake-pool-metadata-job': ['storeStakePoolMetadataJob'],
274285
'stake-pool-metrics-job': ['storePoolMetricsUpdateJob'],

packages/e2e/test/wallet_epoch_3/PersonalWallet/conwayTransactions.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// cSpell:ignore costmdls vasil
2+
13
import * as Crypto from '@cardano-sdk/crypto';
24
import { BaseWallet } from '@cardano-sdk/wallet';
35
import { Cardano, setInConwayEra } from '@cardano-sdk/core';
@@ -82,7 +84,7 @@ export const vasilPlutusV2Costmdls = [
8284
32_696, 32, 43_357, 32, 32_247, 32, 38_314, 32, 35_892_428, 10, 57_996_947, 18_975, 10, 38_887_044, 32_947, 10
8385
];
8486

85-
export const paramsUpdate: Cardano.ProtocolParametersUpdateConway = {
87+
export const protocolParamUpdate: Cardano.ProtocolParametersUpdateConway = {
8688
coinsPerUtxoByte: 35_000,
8789
collateralPercentage: 852,
8890
committeeTermLimit: Cardano.EpochNo(200),
@@ -462,7 +464,7 @@ describe('PersonalWallet/conwayTransactions', () => {
462464
__typename: GovernanceActionType.parameter_change_action,
463465
governanceActionId: null,
464466
policyHash: null,
465-
protocolParamUpdate: { ...paramsUpdate }
467+
protocolParamUpdate
466468
},
467469
rewardAccount
468470
},
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { BigIntColumnOptions, OnDeleteCascadeRelationOptions } from './util';
2+
import { BlockEntity } from './Block.entity';
3+
import { Cardano } from '@cardano-sdk/core';
4+
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
5+
import { Hash28ByteBase16, Hash32ByteBase16 } from '@cardano-sdk/crypto';
6+
import { json, serializableObj } from './transformers';
7+
8+
@Entity()
9+
export class GovernanceActionEntity {
10+
@PrimaryGeneratedColumn()
11+
id?: number;
12+
13+
// LW-11270
14+
// This is required to handle rollbacks, once we have transactions projection
15+
// the OnDeleteCascadeRelationOptions can be moved on txId and this column could be removed
16+
@ManyToOne(() => BlockEntity, OnDeleteCascadeRelationOptions)
17+
@JoinColumn()
18+
block?: BlockEntity;
19+
20+
@Column('varchar')
21+
txId?: Cardano.TransactionId;
22+
23+
@Column('smallint')
24+
index?: number;
25+
26+
@Column('varchar')
27+
stakeCredentialHash?: Hash28ByteBase16;
28+
29+
@Column('varchar')
30+
anchorUrl?: string;
31+
32+
@Column('char', { length: 64, nullable: true })
33+
anchorHash?: Hash32ByteBase16;
34+
35+
@Column(BigIntColumnOptions)
36+
deposit?: bigint;
37+
38+
@Column({ transformer: [serializableObj, json], type: 'varchar' })
39+
action?: Cardano.GovernanceAction;
40+
}

packages/projection-typeorm/src/entity/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from './Handle.entity';
77
export * from './HandleMetadata.entity';
88
export * from './NftMetadata.entity';
99
export * from './Output.entity';
10+
export * from './GovernanceAction.entity';
1011
export * from './PoolDelisted.entity';
1112
export * from './PoolMetadata.entity';
1213
export * from './PoolRegistration.entity';

packages/projection-typeorm/src/operators/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './storeAddresses';
22
export * from './storeAssets';
33
export * from './storeBlock';
4+
export * from './storeGovernanceAction';
45
export * from './storeHandles';
56
export * from './storeHandleMetadata';
67
export * from './storeNftMetadata';

0 commit comments

Comments
 (0)