Skip to content

Commit e6e2e3e

Browse files
committed
Added gov proposal version.
1 parent 2e8013b commit e6e2e3e

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

src/core/env.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,10 @@ export const getEnv = ({
11371137
// Call hook.
11381138
await onFetch?.([event])
11391139

1140-
return event.value
1140+
return {
1141+
...event.value,
1142+
version: event.version,
1143+
}
11411144
}
11421145

11431146
const getProposals: FormulaProposalsGetter = async () => {
@@ -1199,11 +1202,14 @@ export const getEnv = ({
11991202
// Call hook.
12001203
await onFetch?.(events)
12011204

1202-
// Create denom balance map.
1205+
// Create proposal map.
12031206
return events.reduce(
1204-
(acc, { proposalId, value }) => ({
1207+
(acc, { proposalId, value, version }) => ({
12051208
...acc,
1206-
[proposalId]: value,
1209+
[proposalId]: {
1210+
...value,
1211+
version,
1212+
},
12071213
}),
12081214
{} as Record<string, Record<string, any>>
12091215
)

src/core/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ export type ParsedGovStateEvent = {
482482
blockTimeUnixMs: string
483483
blockTimestamp: Date
484484
value: Record<string, any>
485+
version: string
485486
}
486487

487488
type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<

src/db/migrations/20230930091910-alter-bank-state-event-balance-type-bigint-to-string.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { QueryInterface } from 'sequelize'
2+
import { DataType } from 'sequelize-typescript'
23

34
module.exports = {
45
async up(queryInterface: QueryInterface) {
56
await queryInterface.changeColumn('BankStateEvents', 'balance', {
6-
type: 'text',
7+
type: DataType.TEXT,
78
allowNull: false,
89
})
910
},
1011

1112
async down(queryInterface: QueryInterface) {
1213
await queryInterface.changeColumn('BankStateEvents', 'balance', {
13-
type: 'bigint',
14+
type: DataType.BIGINT,
1415
allowNull: false,
1516
})
1617
},
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { QueryInterface } from 'sequelize'
2+
import { DataType } from 'sequelize-typescript'
3+
4+
module.exports = {
5+
async up(queryInterface: QueryInterface) {
6+
await queryInterface.addColumn('GovStateEvents', 'version', {
7+
type: DataType.STRING,
8+
allowNull: false,
9+
})
10+
},
11+
12+
async down(queryInterface: QueryInterface) {
13+
await queryInterface.removeColumn('GovStateEvents', 'version')
14+
},
15+
}

src/db/models/GovStateEvent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ export class GovStateEvent extends DependendableEventModel {
4747
@Column(DataType.DATE)
4848
blockTimestamp!: Date
4949

50-
@AllowNull
50+
@AllowNull(false)
5151
@Column(DataType.JSONB)
5252
value!: any
5353

54+
@AllowNull(false)
55+
@Column(DataType.STRING)
56+
version!: string
57+
5458
get block(): Block {
5559
return {
5660
height: BigInt(this.blockHeight),

src/scripts/export/handlers/gov.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ export const gov: HandlerMaker<ParsedGovStateEvent> = async () => {
5656

5757
// Attempt v1 decoding, falling back to v1beta1. If both fail, ignore.
5858
let value: any
59+
let version
5960
try {
6061
value = ProposalV1.toJSON(ProposalV1.decode(valueData))
62+
version = 'v1'
6163
} catch {
6264
try {
6365
value = ProposalV1Beta1.toJSON(ProposalV1Beta1.decode(valueData))
66+
version = 'v1beta1'
6467
} catch {
6568
return
6669
}
@@ -73,17 +76,19 @@ export const gov: HandlerMaker<ParsedGovStateEvent> = async () => {
7376
blockTimeUnixMs,
7477
blockTimestamp,
7578
value,
79+
version,
7680
}
7781
}
7882

7983
const process: Handler<ParsedGovStateEvent>['process'] = async (events) => {
8084
const exportEvents = async () =>
8185
// Unique index on [blockHeight, proposalId] ensures that we don't insert
8286
// duplicate events. If we encounter a duplicate, we update the `value`
83-
// field in case event processing for a block was batched separately.
87+
// and `version` fields in case event processing for a block was batched
88+
// separately.
8489
events.length > 0
8590
? await GovStateEvent.bulkCreate(events, {
86-
updateOnDuplicate: ['value'],
91+
updateOnDuplicate: ['value', 'version'],
8792
})
8893
: []
8994

0 commit comments

Comments
 (0)