diff --git a/worker-service/example.env b/worker-service/example.env index 1265c48c..fc635b28 100644 --- a/worker-service/example.env +++ b/worker-service/example.env @@ -25,4 +25,9 @@ GOV_ACTION_PROPOSALS_PER_PAGE=10 # Scheduler DB-SYNC VOTES_JOB_FREQUENCY=*/30 * * * * * -GOV_ACTION_PROPOSALS_JOB_FREQUENCY=0 * * * * * \ No newline at end of file +GOV_ACTION_PROPOSALS_JOB_FREQUENCY=0 * * * * * + +# Epoch duration in seconds +EPOCH_DURATION=86400 +# GAP duration in epoch count +GAP_DURATION_IN_EPOCH_COUNT=6 \ No newline at end of file diff --git a/worker-service/src/common/common-service.ts b/worker-service/src/common/common-service.ts index cad4e24a..2b797457 100644 --- a/worker-service/src/common/common-service.ts +++ b/worker-service/src/common/common-service.ts @@ -119,4 +119,10 @@ export abstract class CommonService { } return ipfsUrl; // Return the original URL if it doesn't start with ipfs:// } + + async getEndTime(startTime: Date, interval: number): Promise { + const startDate = new Date(startTime); + const endTime = new Date(startDate.getTime() + interval * 1000); + return endTime; + } } diff --git a/worker-service/src/governance/dto/gov-action-proposal.request.ts b/worker-service/src/governance/dto/gov-action-proposal.request.ts index 74657613..cfed4321 100644 --- a/worker-service/src/governance/dto/gov-action-proposal.request.ts +++ b/worker-service/src/governance/dto/gov-action-proposal.request.ts @@ -4,7 +4,7 @@ export class GovActionProposalRequest { govActionType: string; govMetadataUrl: string; status: string; - endTime: string; + endTime: Date; txHash: string; - submitTime: string; + submitTime: Date; } diff --git a/worker-service/src/governance/facade/governance.facade.spec.ts b/worker-service/src/governance/facade/governance.facade.spec.ts index 345f2ea2..92a58af7 100644 --- a/worker-service/src/governance/facade/governance.facade.spec.ts +++ b/worker-service/src/governance/facade/governance.facade.spec.ts @@ -26,8 +26,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - submitTime: '2024-05-21 15:18:06.000', - endTime: '2024-05-26T22:29:45.000Z', + submitTime: new Date('2024-05-21 15:18:06.000'), + endTime: new Date('2024-05-26T22:29:45.000Z'), txHash: 'D775FBCB6006524ABBFFE6DAF538E71941745B44A3A735852FBBD49FD7D59A95', }, @@ -38,8 +38,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - submitTime: '2024-05-21 17:08:38.000', - endTime: '2024-05-26T22:29:45.000Z', + submitTime: new Date('2024-05-21 17:08:38.000'), + endTime: new Date('2024-05-26T22:29:45.000Z'), txHash: 'DB4DBEB5946E5D49778F457D9C5A460488C40AF0B93D8B98111F5BE11BF165A6', }, @@ -50,8 +50,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: '1111111111111111111111111111111111111111111111111111111111111111', status: 'DROPPED', - submitTime: '2024-05-22 10:08:20.000', - endTime: '2024-05-27T22:29:38.000Z', + submitTime: new Date('2024-05-22 10:08:20.000'), + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: '67820C121787464A9B670CF4C648F67CABD9573EB71B220214971CE467D25027', }, @@ -61,8 +61,8 @@ describe('GovernanceFacade', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json', status: 'DROPPED', - submitTime: '2024-05-17 12:56:00.000', - endTime: '2024-05-17 12:56:00.000', + submitTime: new Date('2024-05-17 12:56:00.000'), + endTime: new Date('2024-05-17 12:56:00.000'), txHash: '69AA81F4AA0140E8D2AB2B6642C403611CD730FAB42E6C9F9E3E15D6D90BD3E9', }, @@ -73,8 +73,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt', status: 'DROPPED', - submitTime: '2024-05-17 16:15:34.000', - endTime: '2024-05-22T22:29:33.000Z', + submitTime: new Date('2024-05-17 16:15:34.000'), + endTime: new Date('2024-05-22T22:29:33.000Z'), txHash: 'EDEF927AF962664ED7A02BEDFA913C7F1CD271494871C25EE7DE66E941D83C79', }, @@ -85,8 +85,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://raw.githubusercontent.com/Sworzen1/Testing-Todo-app/main/Treasury.jsonld', status: 'DROPPED', - submitTime: '2024-05-27 09:19:00.000', - endTime: '2024-06-01T22:29:51.000Z', + submitTime: new Date('2024-05-27 09:19:00.000'), + endTime: new Date('2024-06-01T22:29:51.000Z'), txHash: '2C2F01F6818CEE5E2EC29EF965DF347099173707BAFCEFC7F6FE3D66CD5F66EC', }, @@ -97,8 +97,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://raw.githubusercontent.com/Ryun1/metadata/main/cip100/ga.jsonld', status: 'DROPPED', - submitTime: '2024-05-27 20:34:28.000', - endTime: '2024-06-01T22:29:51.000Z', + submitTime: new Date('2024-05-27 20:34:28.000'), + endTime: new Date('2024-06-01T22:29:51.000Z'), txHash: '3B15AC25580564C8C565121188B142BEE99F6AAD7D4130FFC6A5A764EBA1159A', }, @@ -108,8 +108,8 @@ describe('GovernanceFacade', () => { govActionType: 'ParameterChange', govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json', status: 'DROPPED', - submitTime: '2024-05-18 20:25:26.000', - endTime: '2024-05-23T22:27:46.000Z', + submitTime: new Date('2024-05-18 20:25:26.000'), + endTime: new Date('2024-05-23T22:27:46.000Z'), txHash: '6A3319F5AC57551C4CABF77D0603BD6C72F44E9D10830363D87EB34CB43AFCB2', }, @@ -119,8 +119,8 @@ describe('GovernanceFacade', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info', status: 'DROPPED', - submitTime: '2024-05-18 14:29:22.000', - endTime: '2024-05-23T22:27:46.000Z', + submitTime: new Date('2024-05-18 14:29:22.000'), + endTime: new Date('2024-05-23T22:27:46.000Z'), txHash: 'B9532421430F6611C0170993E88DFA29B6AA0D4CCE024AD88346C59BE2B65B41', }, @@ -130,8 +130,8 @@ describe('GovernanceFacade', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info', status: 'DROPPED', - submitTime: '2024-05-26 04:02:39.000', - endTime: '2024-05-31T22:29:15.000Z', + submitTime: new Date('2024-05-26 04:02:39.000'), + endTime: new Date('2024-05-31T22:29:15.000Z'), txHash: '2EC4AD524F0AF3EEB1F05C360BFDECF815936E7CBF8EAC9C07A4E0C7072D03D1', }, @@ -144,8 +144,8 @@ describe('GovernanceFacade', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://bit.ly/3zCH2HL', status: 'DROPPED', - submitTime: '2024-05-20 06:39:16.000', - endTime: '2024-05-25T22:29:48.000Z', + submitTime: new Date('2024-05-20 06:39:16.000'), + endTime: new Date('2024-05-25T22:29:48.000Z'), txHash: 'cef93aface365b575e1f33987fad4093e2a8a06d31c01a260e0e7db325fc0b50', }, @@ -155,8 +155,8 @@ describe('GovernanceFacade', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info', status: 'DROPPED', - submitTime: '2024-05-22 12:24:59.000', - endTime: '2024-05-27T22:29:38.000Z', + submitTime: new Date('2024-05-22 12:24:59.000'), + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: '75d1c676f459f1192c7fd2c73423635a074c5e7b46497e00f44428861f460153', }, @@ -167,8 +167,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - submitTime: '2024-05-22 19:47:27.000', - endTime: '2024-05-27T22:29:38.000Z', + submitTime: new Date('2024-05-22 19:47:27.000'), + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: '9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397', }, @@ -179,8 +179,8 @@ describe('GovernanceFacade', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - submitTime: '2024-05-22 21:44:26.000', - endTime: '2024-05-27T22:29:38.000Z', + submitTime: new Date('2024-05-22 21:44:26.000'), + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: 'f6ca72e9fe225c01e1a622d529ad807d668a786cb28d1eb352b8da58b66dd8c2', }, diff --git a/worker-service/src/governance/queues/processors/gov-action-proposal.processor.ts b/worker-service/src/governance/queues/processors/gov-action-proposal.processor.ts index 56597e54..ae7ae974 100644 --- a/worker-service/src/governance/queues/processors/gov-action-proposal.processor.ts +++ b/worker-service/src/governance/queues/processors/gov-action-proposal.processor.ts @@ -1,4 +1,4 @@ -import { OnWorkerEvent, Processor, WorkerHost } from '@nestjs/bullmq'; +import { Processor, WorkerHost } from '@nestjs/bullmq'; import { Job } from 'bullmq'; import { JOB_NAME_GOV_ACTIONS_SYNC, @@ -7,12 +7,11 @@ import { import { Logger } from '@nestjs/common'; import { GovActionProposalService } from '../../services/gov-action-proposal.service'; - @Processor(QUEUE_NAME_DB_SYNC_GOV_ACTIONS) export class GovActionsProposalProcessor extends WorkerHost { protected readonly logger = new Logger(GovActionsProposalProcessor.name); constructor( - private readonly govActionProposalService: GovActionProposalService + private readonly govActionProposalService: GovActionProposalService, ) { super(); } diff --git a/worker-service/src/governance/queues/processors/vote.processor.ts b/worker-service/src/governance/queues/processors/vote.processor.ts index 7cdf2a6c..3866db61 100644 --- a/worker-service/src/governance/queues/processors/vote.processor.ts +++ b/worker-service/src/governance/queues/processors/vote.processor.ts @@ -1,4 +1,4 @@ -import { OnWorkerEvent, Processor, WorkerHost } from '@nestjs/bullmq'; +import { Processor, WorkerHost } from '@nestjs/bullmq'; import { Job } from 'bullmq'; import { JOB_NAME_VOTE_SYNC, diff --git a/worker-service/src/governance/services/gov-action-proposal.service.spec.ts b/worker-service/src/governance/services/gov-action-proposal.service.spec.ts index 644b399c..1f3188a8 100644 --- a/worker-service/src/governance/services/gov-action-proposal.service.spec.ts +++ b/worker-service/src/governance/services/gov-action-proposal.service.spec.ts @@ -20,10 +20,10 @@ describe('GovActionProposalService', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json', status: 'DROPPED', - endTime: '2024-05-22T22:29:33.000Z', + endTime: new Date('2024-05-22T22:29:33.000Z'), txHash: '69aa81f4aa0140e8d2ab2b6642c403611cd730fab42e6c9f9e3e15d6d90bd3e9', - submitTime: '2024-05-17T10:56:00.000Z', + submitTime: new Date('2024-05-17T10:56:00.000Z'), }, { id: '2', @@ -32,10 +32,10 @@ describe('GovActionProposalService', () => { govMetadataUrl: 'https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt', status: 'DROPPED', - endTime: '2024-05-22T22:29:33.000Z', + endTime: new Date('2024-05-22T22:29:33.000Z'), txHash: 'edef927af962664ed7a02bedfa913c7f1cd271494871c25ee7de66e941d83c79', - submitTime: '2024-05-17T14:15:34.000Z', + submitTime: new Date('2024-05-17T14:15:34.000Z'), }, { id: '3', @@ -43,10 +43,10 @@ describe('GovActionProposalService', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info', status: 'DROPPED', - endTime: '2024-05-23T22:27:46.000Z', + endTime: new Date('2024-05-23T22:27:46.000Z'), txHash: 'b9532421430f6611c0170993e88dfa29b6aa0d4cce024ad88346c59be2b65b41', - submitTime: '2024-05-18T12:29:22.000Z', + submitTime: new Date('2024-05-18T12:29:22.000Z'), }, { id: '4', @@ -54,10 +54,10 @@ describe('GovActionProposalService', () => { govActionType: 'ParameterChange', govMetadataUrl: 'https://my-ip.at/test/cip-0100.common.json', status: 'DROPPED', - endTime: '2024-05-23T22:27:46.000Z', + endTime: new Date('2024-05-23T22:27:46.000Z'), txHash: '6a3319f5ac57551c4cabf77d0603bd6c72f44e9d10830363d87eb34cb43afcb2', - submitTime: '2024-05-18T18:25:26.000Z', + submitTime: new Date('2024-05-18T18:25:26.000Z'), }, { id: '5', @@ -65,10 +65,10 @@ describe('GovActionProposalService', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://bit.ly/3zCH2HL', status: 'DROPPED', - endTime: '2024-05-25T22:29:48.000Z', + endTime: new Date('2024-05-25T22:29:48.000Z'), txHash: 'cef93aface365b575e1f33987fad4093e2a8a06d31c01a260e0e7db325fc0b50', - submitTime: '2024-05-20T04:39:16.000Z', + submitTime: new Date('2024-05-20T04:39:16.000Z'), }, { id: '6', @@ -77,10 +77,10 @@ describe('GovActionProposalService', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - endTime: '2024-05-26T22:29:45.000Z', + endTime: new Date('2024-05-26T22:29:45.000Z'), txHash: 'd775fbcb6006524abbffe6daf538e71941745b44a3a735852fbbd49fd7d59a95', - submitTime: '2024-05-21T13:18:06.000Z', + submitTime: new Date('2024-05-21T13:18:06.000Z'), }, { id: '7', @@ -89,10 +89,10 @@ describe('GovActionProposalService', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - endTime: '2024-05-26T22:29:45.000Z', + endTime: new Date('2024-05-26T22:29:45.000Z'), txHash: 'db4dbeb5946e5d49778f457d9c5a460488c40af0b93d8b98111f5be11bf165a6', - submitTime: '2024-05-21T15:08:38.000Z', + submitTime: new Date('2024-05-21T15:08:38.000Z'), }, { id: '8', @@ -101,10 +101,10 @@ describe('GovActionProposalService', () => { govMetadataUrl: '1111111111111111111111111111111111111111111111111111111111111111', status: 'DROPPED', - endTime: '2024-05-27T22:29:38.000Z', + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: '67820c121787464a9b670cf4c648f67cabd9573eb71b220214971ce467d25027', - submitTime: '2024-05-22T08:08:20.000Z', + submitTime: new Date('2024-05-22T08:08:20.000Z'), }, { id: '9', @@ -112,10 +112,10 @@ describe('GovActionProposalService', () => { govActionType: 'InfoAction', govMetadataUrl: 'https://metadata.cardanoapi.io/data/Info', status: 'DROPPED', - endTime: '2024-05-27T22:29:38.000Z', + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: '75d1c676f459f1192c7fd2c73423635a074c5e7b46497e00f44428861f460153', - submitTime: '2024-05-22T10:24:59.000Z', + submitTime: new Date('2024-05-22T10:24:59.000Z'), }, { id: '10', @@ -124,10 +124,10 @@ describe('GovActionProposalService', () => { govMetadataUrl: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', status: 'DROPPED', - endTime: '2024-05-27T22:29:38.000Z', + endTime: new Date('2024-05-27T22:29:38.000Z'), txHash: '9bd2b6547ab8e8ed5c34049d6b984772a8352ac70e92198e1a7f6cdbb12d6397', - submitTime: '2024-05-22T17:47:27.000Z', + submitTime: new Date('2024-05-22T17:47:27.000Z'), }, ]; @@ -296,7 +296,7 @@ describe('GovActionProposalService', () => { { id: '1', type: 'InfoAction', - end_time: '2024-05-22T22:29:33.000Z', + end_time: new Date('2024-05-22T22:29:33.000Z'), voting_anchor_id: '1', url: 'https://my-ip.at/test/cip-0100.common.json', hash: new Uint8Array([ @@ -304,13 +304,13 @@ describe('GovActionProposalService', () => { 28, 215, 48, 250, 180, 46, 108, 159, 158, 62, 21, 214, 217, 11, 211, 233, ]), - time: '2024-05-17T10:56:00.000Z', + time: new Date('2024-05-17T10:56:00.000Z'), epoch_status: 'DROPPED', }, { id: '2', type: 'HardForkInitiation', - end_time: '2024-05-22T22:29:33.000Z', + end_time: new Date('2024-05-22T22:29:33.000Z'), voting_anchor_id: '2', url: 'https://github.com/carloslodelar/proposals/blob/main/why-hardfork-to-10.txt', hash: new Uint8Array([ @@ -318,52 +318,52 @@ describe('GovActionProposalService', () => { 127, 28, 210, 113, 73, 72, 113, 194, 94, 231, 222, 102, 233, 65, 216, 60, 121, ]), - time: '2024-05-17T14:15:34.000Z', + time: new Date('2024-05-17T14:15:34.000Z'), epoch_status: 'DROPPED', }, { id: '3', type: 'InfoAction', - end_time: '2024-05-23T22:27:46.000Z', + end_time: new Date('2024-05-23T22:27:46.000Z'), voting_anchor_id: '4', url: 'https://metadata.cardanoapi.io/data/Info', hash: new Uint8Array([ 185, 83, 36, 33, 67, 15, 102, 17, 192, 23, 9, 147, 232, 141, 250, 41, 182, 170, 13, 76, 206, 2, 74, 216, 131, 70, 197, 155, 226, 182, 91, 65, ]), - time: '2024-05-18T12:29:22.000Z', + time: new Date('2024-05-18T12:29:22.000Z'), epoch_status: 'DROPPED', }, { id: '4', type: 'ParameterChange', - end_time: '2024-05-23T22:27:46.000Z', + end_time: new Date('2024-05-23T22:27:46.000Z'), voting_anchor_id: '1', url: 'https://my-ip.at/test/cip-0100.common.json', hash: new Uint8Array([ 106, 51, 25, 245, 172, 87, 85, 28, 76, 171, 247, 125, 6, 3, 189, 108, 114, 244, 78, 157, 16, 131, 3, 99, 216, 126, 179, 76, 180, 58, 252, 178, ]), - time: '2024-05-18T18:25:26.000Z', + time: new Date('2024-05-18T18:25:26.000Z'), epoch_status: 'DROPPED', }, { id: '5', type: 'InfoAction', - end_time: '2024-05-25T22:29:48.000Z', + end_time: new Date('2024-05-25T22:29:48.000Z'), voting_anchor_id: '62', url: 'https://bit.ly/3zCH2HL', hash: new Uint8Array([ 206, 249, 58, 250, 206, 54, 91, 87, 94, 31, 51, 152, 127, 173, 64, 147, 226, 168, 160, 109, 49, 192, 26, 38, 14, 14, 125, 179, 37, 252, 11, 80, ]), - time: '2024-05-20T04:39:16.000Z', + time: new Date('2024-05-20T04:39:16.000Z'), epoch_status: 'DROPPED', }, { id: '6', type: 'InfoAction', - end_time: '2024-05-26T22:29:45.000Z', + end_time: new Date('2024-05-26T22:29:45.000Z'), voting_anchor_id: '168', url: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', hash: new Uint8Array([ @@ -371,13 +371,13 @@ describe('GovActionProposalService', () => { 65, 116, 91, 68, 163, 167, 53, 133, 47, 187, 212, 159, 215, 213, 154, 149, ]), - time: '2024-05-21T13:18:06.000Z', + time: new Date('2024-05-21T13:18:06.000Z'), epoch_status: 'DROPPED', }, { id: '7', type: 'InfoAction', - end_time: '2024-05-26T22:29:45.000Z', + end_time: new Date('2024-05-26T22:29:45.000Z'), voting_anchor_id: '168', url: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', hash: new Uint8Array([ @@ -385,39 +385,39 @@ describe('GovActionProposalService', () => { 136, 196, 10, 240, 185, 61, 139, 152, 17, 31, 91, 225, 27, 241, 101, 166, ]), - time: '2024-05-21T15:08:38.000Z', + time: new Date('2024-05-21T15:08:38.000Z'), epoch_status: 'DROPPED', }, { id: '8', type: 'HardForkInitiation', - end_time: '2024-05-27T22:29:38.000Z', + end_time: new Date('2024-05-27T22:29:38.000Z'), voting_anchor_id: '216', url: '1111111111111111111111111111111111111111111111111111111111111111', hash: new Uint8Array([ 103, 130, 12, 18, 23, 135, 70, 74, 155, 103, 12, 244, 198, 72, 246, 124, 171, 217, 87, 62, 183, 27, 34, 2, 20, 151, 28, 228, 103, 210, 80, 39, ]), - time: '2024-05-22T08:08:20.000Z', + time: new Date('2024-05-22T08:08:20.000Z'), epoch_status: 'DROPPED', }, { id: '9', type: 'InfoAction', - end_time: '2024-05-27T22:29:38.000Z', + end_time: new Date('2024-05-27T22:29:38.000Z'), voting_anchor_id: '239', url: 'https://metadata.cardanoapi.io/data/Info', hash: new Uint8Array([ 117, 209, 198, 118, 244, 89, 241, 25, 44, 127, 210, 199, 52, 35, 99, 90, 7, 76, 94, 123, 70, 73, 126, 0, 244, 68, 40, 134, 31, 70, 1, 83, ]), - time: '2024-05-22T10:24:59.000Z', + time: new Date('2024-05-22T10:24:59.000Z'), epoch_status: 'DROPPED', }, { id: '10', type: 'InfoAction', - end_time: '2024-05-27T22:29:38.000Z', + end_time: new Date('2024-05-27T22:29:38.000Z'), voting_anchor_id: '168', url: 'https://raw.githubusercontent.com/mpawel79/testrepo/master/Info.jsonld', hash: new Uint8Array([ @@ -425,7 +425,7 @@ describe('GovActionProposalService', () => { 114, 168, 53, 42, 199, 14, 146, 25, 142, 26, 127, 108, 219, 177, 45, 99, 151, ]), - time: '2024-05-22T17:47:27.000Z', + time: new Date('2024-05-22T17:47:27.000Z'), epoch_status: 'DROPPED', }, ]; diff --git a/worker-service/src/governance/services/gov-action-proposal.service.ts b/worker-service/src/governance/services/gov-action-proposal.service.ts index 02608b48..33fe763f 100644 --- a/worker-service/src/governance/services/gov-action-proposal.service.ts +++ b/worker-service/src/governance/services/gov-action-proposal.service.ts @@ -18,6 +18,7 @@ import { GovActionProposalMapper } from '../mapper/gov-action-proposal.mapper'; import { CommonService } from 'src/common/common-service'; import { GovActionProposal } from '../entities/gov-action-proposal.entity'; import { ConfigService } from '@nestjs/config'; +import { GovActionProposalDto } from '../dto/gov-action-proposal.dto'; @Injectable() export class GovActionProposalService extends CommonService { @@ -56,17 +57,24 @@ export class GovActionProposalService extends CommonService { requests: GovActionProposalRequest[], ): Promise> { const govActionProposals = []; + const endTimeInterval: number = + this.configService.getOrThrow('EPOCH_DURATION') * + this.configService.getOrThrow('GAP_DURATION_IN_EPOCH_COUNT'); for (const request of requests) { const govMetadataUrl = await this.transformIpfsUrl( request.govMetadataUrl, ); const axiosData = await this.getGovActionProposalFromUrl(govMetadataUrl); - const govActionProposal = { + let endTime: Date = request.endTime; + if (!request.endTime) { + endTime = await this.getEndTime(request.submitTime, endTimeInterval); + } + const govActionProposal: Partial = { id: request.id, votingAnchorId: request.votingAnchorId, govActionType: request.govActionType, govMetadataUrl: govMetadataUrl, - endTime: request?.endTime, + endTime: endTime, status: request.status, txHash: request.txHash, submitTime: request.submitTime, diff --git a/worker-service/src/governance/services/vote.service.ts b/worker-service/src/governance/services/vote.service.ts index 9e842273..865e51e2 100644 --- a/worker-service/src/governance/services/vote.service.ts +++ b/worker-service/src/governance/services/vote.service.ts @@ -127,6 +127,16 @@ export class VoteService extends CommonService { private async prepareGAP( voteRequest: VoteRequest, ): Promise { + const endTimeInterval: number = + this.configService.getOrThrow('EPOCH_DURATION') * + this.configService.getOrThrow('GAP_DURATION_IN_EPOCH_COUNT'); + let endTime: Date = voteRequest.endTime; + if (!voteRequest.endTime) { + endTime = await this.getEndTime( + voteRequest.govActionProposalSubmitTime, + endTimeInterval, + ); + } const govMetadataUrl = await this.transformIpfsUrl( voteRequest.govMetadataUrl, ); @@ -135,7 +145,7 @@ export class VoteService extends CommonService { govActionProposalDto.id = voteRequest.govActionProposalId; govActionProposalDto.votingAnchorId = voteRequest.votingAnchorId; govActionProposalDto.status = voteRequest.status; - govActionProposalDto.endTime = voteRequest.endTime; + govActionProposalDto.endTime = endTime; govActionProposalDto.txHash = Buffer.from(voteRequest.txHash).toString( 'hex', ); diff --git a/worker-service/src/governance/sql/get-gov-action-proposals-data.sql b/worker-service/src/governance/sql/get-gov-action-proposals-data.sql index d8e8c03e..1e1df1fb 100644 --- a/worker-service/src/governance/sql/get-gov-action-proposals-data.sql +++ b/worker-service/src/governance/sql/get-gov-action-proposals-data.sql @@ -1,14 +1,14 @@ select gap.id, -- Should be id value from Governance Action Proposal table gap.type, -- Should be Governance Action Proposal category (ParameterChange, HardForkInitiation, TreasuryWithdrawals...) -gap_exp_epoch.end_time, -- Should be GAP "Expiry date" info wwhen clicking on show more button +gap_exp_epoch.end_time, -- Should be GAP "Expiry date" info when clicking on show more button gap.voting_anchor_id, -- Should be anchor id for URL that contins JSon governance action metadata va.url, -- Should be a URL that contains JSon governance action metadata gap_tx.hash, -- Should be transaction hash from tx table gap_block.time, -- Should be Governance Action Proposal "Submit time" case - when gap.ratified_epoch is not null then 'RATIFIED' when gap.enacted_epoch is not null then 'ENACTED' + when gap.ratified_epoch is not null then 'RATIFIED' when gap.dropped_epoch is not null then 'DROPPED' when gap.expired_epoch is not null then 'EXPIRED' else 'ACTIVE' diff --git a/worker-service/src/governance/sql/get-votes.sql b/worker-service/src/governance/sql/get-votes.sql index 81470526..5eb042bb 100644 --- a/worker-service/src/governance/sql/get-votes.sql +++ b/worker-service/src/governance/sql/get-votes.sql @@ -13,8 +13,8 @@ va2.url vote_url, -- Should be a URL that contains Rationale JSON vp_tx.hash, -- Should be transaction hash from tx table gap_block.time gap_submit_time, -- Should be Governance Action Proposal "Submit time" case - when gap.ratified_epoch is not null then 'RATIFIED' when gap.enacted_epoch is not null then 'ENACTED' + when gap.ratified_epoch is not null then 'RATIFIED' when gap.dropped_epoch is not null then 'DROPPED' when gap.expired_epoch is not null then 'EXPIRED' else 'ACTIVE'