Skip to content

Commit ea24748

Browse files
committed
refactor(cardano-services): optimize get gov_action_proposals query
The 'tag' attribute in the 'description' field is a duplication of the field 'type'; reduce one field from the query to use the attribute in the JSON.
1 parent a06ddc8 commit ea24748

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/ChainHistoryBuilder.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ const mapWithdrawals: (source: [{ credential: DbSyncCredential; network: string
9393
const getGovernanceAction = ({
9494
denominator,
9595
description,
96-
numerator,
97-
type
96+
numerator
9897
}: ProposalProcedureModel): Cardano.GovernanceAction => {
99-
const { contents } = description;
98+
const { contents, tag } = description;
10099
const governanceActionId =
101100
contents && contents[0] ? { actionIndex: contents[0].govActionIx, id: contents[0].txId } : null;
102101

103-
switch (type) {
102+
if (!tag) throw new Error('Missing "tag" in governance action proposal description');
103+
if (typeof tag !== 'string') throw new Error('Wrong "tag" type in governance action proposal description');
104+
105+
switch (tag) {
104106
case 'HardForkInitiation':
105107
return {
106108
__typename: GovernanceActionType.hard_fork_initiation_action,
@@ -159,7 +161,7 @@ const getGovernanceAction = ({
159161
};
160162
}
161163

162-
throw new Error(`Unknown GovernanceActionType '${type}' with description "${JSON.stringify(description)}"`);
164+
throw new Error(`Unknown GovernanceActionType '${tag}' with description "${JSON.stringify(description)}"`);
163165
};
164166

165167
const getVoter = (

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/queries.ts

-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export const findProposalProceduresByTxIds = `
222222
tx.hash AS tx_id,
223223
ga.deposit,
224224
ga.description,
225-
ga.type,
226225
va.url,
227226
va.data_hash,
228227
sa.view,

packages/cardano-services/src/ChainHistory/DbSyncChainHistory/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ export interface ProposalProcedureModel {
137137
// eslint-disable-next-line @typescript-eslint/no-explicit-any
138138
description: any;
139139
tx_id: Buffer;
140-
type: string;
141140
url: string;
142141
view: string;
143142
// LW-9675

0 commit comments

Comments
 (0)