diff --git a/src/core/env.ts b/src/core/env.ts index f5d7a365..cecb7d05 100644 --- a/src/core/env.ts +++ b/src/core/env.ts @@ -28,6 +28,7 @@ import { FormulaPrefetch, FormulaPrefetchTransformations, FormulaProposalGetter, + FormulaProposalObject, FormulaProposalsGetter, FormulaSlashEventsGetter, FormulaTransformationDateGetter, @@ -1138,7 +1139,8 @@ export const getEnv = ({ await onFetch?.([event]) return { - ...event.value, + id: event.proposalId, + value: event.value, version: event.version, } } @@ -1208,11 +1210,12 @@ export const getEnv = ({ (acc, { proposalId, value, version }) => ({ ...acc, [proposalId]: { - ...value, + id: proposalId, + value, version, }, }), - {} as Record> + {} as Record ) } diff --git a/src/core/types.ts b/src/core/types.ts index 34253664..3cf26c5c 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -243,12 +243,18 @@ export type FormulaBalancesGetter = ( address: string ) => Promise | undefined> +export type FormulaProposalObject = { + id: string + value: string + version: string +} + export type FormulaProposalGetter = ( proposalId: string -) => Promise | undefined> +) => Promise export type FormulaProposalsGetter = () => Promise< - Record> | undefined + Record | undefined > export type Env = {}> = { @@ -481,7 +487,7 @@ export type ParsedGovStateEvent = { blockHeight: string blockTimeUnixMs: string blockTimestamp: Date - value: Record + value: string version: string } diff --git a/src/data/formulas/generic/gov.ts b/src/data/formulas/generic/gov.ts index 95f11305..bb8e3ab5 100644 --- a/src/data/formulas/generic/gov.ts +++ b/src/data/formulas/generic/gov.ts @@ -1,7 +1,7 @@ -import { GenericFormula } from '@/core' +import { FormulaProposalObject, GenericFormula } from '@/core' export const proposal: GenericFormula< - Record | undefined, + FormulaProposalObject | undefined, { proposalId: string } > = { compute: async ({ getProposal, args: { proposalId } }) => { @@ -15,7 +15,7 @@ export const proposal: GenericFormula< export const proposals: GenericFormula< { - proposals: Record[] + proposals: FormulaProposalObject[] total: number }, { @@ -52,7 +52,7 @@ export const proposals: GenericFormula< export const reverseProposals: GenericFormula< { - proposals: Record[] + proposals: FormulaProposalObject[] total: number }, { diff --git a/src/db/migrations/20240108103200-change-gov-value-to-string.ts b/src/db/migrations/20240108103200-change-gov-value-to-string.ts new file mode 100644 index 00000000..f95a93b2 --- /dev/null +++ b/src/db/migrations/20240108103200-change-gov-value-to-string.ts @@ -0,0 +1,19 @@ +import { QueryInterface } from 'sequelize' +import { DataType } from 'sequelize-typescript' + +module.exports = { + async up(queryInterface: QueryInterface) { + await queryInterface.bulkDelete('GovStateEvents', {}) + await queryInterface.changeColumn('GovStateEvents', 'value', { + type: DataType.TEXT('long'), + allowNull: false, + }) + }, + + async down(queryInterface: QueryInterface) { + await queryInterface.changeColumn('GovStateEvents', 'value', { + type: DataType.JSONB, + allowNull: false, + }) + }, +} diff --git a/src/db/models/GovStateEvent.ts b/src/db/models/GovStateEvent.ts index 3ec2a663..9697bd48 100644 --- a/src/db/models/GovStateEvent.ts +++ b/src/db/models/GovStateEvent.ts @@ -47,9 +47,10 @@ export class GovStateEvent extends DependendableEventModel { @Column(DataType.DATE) blockTimestamp!: Date + // Base64-encoded protobuf @AllowNull(false) - @Column(DataType.JSONB) - value!: any + @Column(DataType.TEXT('long')) + value!: string @AllowNull(false) @Column(DataType.STRING) diff --git a/src/scripts/export/handlers/gov.ts b/src/scripts/export/handlers/gov.ts index c2c24b5a..9837a55d 100644 --- a/src/scripts/export/handlers/gov.ts +++ b/src/scripts/export/handlers/gov.ts @@ -1,4 +1,4 @@ -import { fromBase64 } from '@cosmjs/encoding' +import { fromBase64, toBase64 } from '@cosmjs/encoding' import retry from 'async-await-retry' import { Sequelize } from 'sequelize' @@ -58,11 +58,13 @@ export const gov: HandlerMaker = async () => { let value: any let version try { - value = ProposalV1.toAmino(ProposalV1.decode(valueData)) + value = toBase64(ProposalV1.toProto(ProposalV1.decode(valueData))) version = 'v1' } catch { try { - value = ProposalV1Beta1.toAmino(ProposalV1Beta1.decode(valueData)) + value = toBase64( + ProposalV1Beta1.toProto(ProposalV1Beta1.decode(valueData)) + ) version = 'v1beta1' } catch { return