diff --git a/src/api/election.ts b/src/api/election.ts index 123873c8..5c7cb4ae 100644 --- a/src/api/election.ts +++ b/src/api/election.ts @@ -197,11 +197,6 @@ export interface IElectionInfoResponse { */ manuallyEnded: boolean; - /** - * If the election comes from the archive - */ - fromArchive: boolean; - /** * The chain identifier of the election */ diff --git a/src/client.ts b/src/client.ts index ec9528e3..1cb1a5d8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -10,7 +10,6 @@ import { Account, AllElectionStatus, AnonymousVote, - ArchivedElection, CensusType, CspVote, ElectionStatus, @@ -252,7 +251,7 @@ export class VocdoniSDKClient { * @param electionId - The id of the election * @param password - The password to decrypt the metadata */ - async fetchElection(electionId?: string, password?: string): Promise { + async fetchElection(electionId?: string, password?: string): Promise { invariant(this.electionId || electionId, 'No election set'); this.election = await this.electionService.fetchElection(electionId ?? this.electionId, password); diff --git a/src/services/election.ts b/src/services/election.ts index f644b67a..cbc8a6b4 100644 --- a/src/services/election.ts +++ b/src/services/election.ts @@ -1,7 +1,6 @@ import { Service, ServiceProperties } from './service'; import { AllElectionStatus, - ArchivedElection, Census, CspCensus, ElectionResultsTypeNames, @@ -26,7 +25,6 @@ import { ElectionCore } from '../core/election'; import { ChainService } from './chain'; import { Wallet } from '@ethersproject/wallet'; import { Signer } from '@ethersproject/abstract-signer'; -import { ArchivedCensus } from '../types/census/archived'; import { keccak256 } from '@ethersproject/keccak256'; import { Buffer } from 'buffer'; import { Asymmetric } from '../util/encryption'; @@ -49,7 +47,7 @@ export interface FetchElectionsParameters { status: Exclude; } -export type ElectionList = Array; +export type ElectionList = Array; export type ElectionListWithPagination = { elections: ElectionList } & PaginationResponse; export type ElectionKeys = IElectionKeysResponse; @@ -116,13 +114,11 @@ export class ElectionService extends Service implements ElectionServicePropertie ); } - private buildCensus(electionInfo): Promise { + private buildCensus(electionInfo): Promise { if (electionInfo.census.censusOrigin === CensusTypeEnum.OFF_CHAIN_CA) { return Promise.resolve(new CspCensus(electionInfo.census.censusRoot, electionInfo.census.censusURL)); } - return electionInfo.fromArchive - ? Promise.resolve(new ArchivedCensus(electionInfo.census.censusRoot, electionInfo.census.censusURL)) - : this.buildPublishedCensus(electionInfo); + return this.buildPublishedCensus(electionInfo); } decryptMetadata(electionInfo, password) { @@ -163,7 +159,7 @@ export class ElectionService extends Service implements ElectionServicePropertie * @param electionId - The id of the election * @param password - The password to decrypt the metadata */ - async fetchElection(electionId: string, password?: string): Promise { + async fetchElection(electionId: string, password?: string): Promise { invariant(this.url, 'No URL set'); invariant(this.censusService, 'No census service set'); @@ -172,16 +168,19 @@ export class ElectionService extends Service implements ElectionServicePropertie throw err; }); - let electionInfo, censusInfo; + let electionInfo, census; try { electionInfo = this.decryptMetadata(electionInformation, password); - censusInfo = await this.buildCensus(electionInfo); } catch (e) { e.electionId = electionId; e.raw = electionInformation; throw e; } + try { + census = await this.buildCensus(electionInfo); + } catch (e) {} + const electionParameters = { id: electionInfo.electionId, organizationId: electionInfo.organizationId, @@ -192,10 +191,9 @@ export class ElectionService extends Service implements ElectionServicePropertie meta: electionInfo.metadata?.meta, startDate: electionInfo.startDate, endDate: electionInfo.endDate, - census: censusInfo, + census, maxCensusSize: electionInfo.census.maxCensusSize, manuallyEnded: electionInfo.manuallyEnded, - fromArchive: electionInfo.fromArchive, chainId: electionInfo.chainId, status: electionInfo.status, voteCount: electionInfo.voteCount, @@ -236,9 +234,7 @@ export class ElectionService extends Service implements ElectionServicePropertie raw: electionInfo, }; - return electionParameters.fromArchive - ? new ArchivedElection(electionParameters) - : new PublishedElection(electionParameters); + return new PublishedElection(electionParameters); } private calculateChoiceResults(electionType, result, qIndex, cIndex) { diff --git a/src/types/census/archived.ts b/src/types/census/archived.ts deleted file mode 100644 index fa920ed2..00000000 --- a/src/types/census/archived.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Census, CensusType } from './census'; -import invariant from 'tiny-invariant'; - -/** - * Represents an archived census - */ -export class ArchivedCensus extends Census { - /** - * Constructs an archived census - * - * @param censusId - The id of the census - * @param censusURI - The URI of the census - * @param type - The type of the census - * @param size - The size of the census - * @param weight - The weight of the census - */ - public constructor(censusId: string, censusURI?: string, type?: CensusType, size?: number, weight?: bigint) { - invariant(/^(0x)?[0-9a-fA-F]+$/.test(censusId), 'Census identifier is missing or invalid'); - super(censusId, censusURI, type, size, weight); - } -} diff --git a/src/types/election/archived.ts b/src/types/election/archived.ts deleted file mode 100644 index 4b73a86a..00000000 --- a/src/types/election/archived.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { IPublishedElectionParameters, PublishedElection } from './published'; -import { ArchivedCensus } from '../census/archived'; - -/** - * Represents a published election - */ -export class ArchivedElection extends PublishedElection { - /** - * Constructs an archived election - * - * @param params - Election parameters - */ - public constructor(params: IPublishedElectionParameters) { - super(params); - } - - get census(): ArchivedCensus { - return super.census; - } -} diff --git a/src/types/election/index.ts b/src/types/election/index.ts index 804d9bf1..45c01a02 100644 --- a/src/types/election/index.ts +++ b/src/types/election/index.ts @@ -3,7 +3,6 @@ export * from './unpublished'; export * from './election'; export * from './published'; export * from './invalid'; -export * from './archived'; export * from './multichoice'; export * from './budget'; export * from './approval'; diff --git a/src/types/election/published.ts b/src/types/election/published.ts index f1f31808..357e4eed 100644 --- a/src/types/election/published.ts +++ b/src/types/election/published.ts @@ -31,7 +31,6 @@ export interface IPublishedElectionParameters extends IElectionParameters { finalResults: boolean; results: Array>; manuallyEnded: boolean; - fromArchive: boolean; chainId: string; creationTime: string; metadataURL: string; @@ -49,7 +48,6 @@ export class PublishedElection extends Election { private readonly _voteCount: number; private readonly _finalResults: boolean; private readonly _manuallyEnded: boolean; - private readonly _fromArchive: boolean; private readonly _chainId: string; private readonly _results: Array>; private readonly _creationTime: Date; @@ -84,7 +82,6 @@ export class PublishedElection extends Election { this._finalResults = params.finalResults; this._results = params.results; this._manuallyEnded = params.manuallyEnded; - this._fromArchive = params.fromArchive; this._chainId = params.chainId; this._creationTime = new Date(params.creationTime); this._metadataURL = params.metadataURL; @@ -212,10 +209,6 @@ export class PublishedElection extends Election { return this._manuallyEnded; } - get fromArchive(): boolean { - return this._fromArchive; - } - get chainId(): string { return this._chainId; } diff --git a/test/integration/election.test.ts b/test/integration/election.test.ts index 8d4f241c..68453457 100644 --- a/test/integration/election.test.ts +++ b/test/integration/election.test.ts @@ -124,7 +124,6 @@ describe('Election integration tests', () => { maxTotalCost: 0, }); expect(publishedElection.manuallyEnded).toBeFalsy(); - expect(publishedElection.fromArchive).toBeFalsy(); expect(publishedElection.chainId).toBeDefined(); expect(publishedElection.maxCensusSize).toEqual(1); expect(publishedElection.resultsType.name).toEqual(ElectionResultsTypeNames.SINGLE_CHOICE_MULTIQUESTION); diff --git a/test/unit/types/election.test.ts b/test/unit/types/election.test.ts index ae795120..ffe4ea77 100644 --- a/test/unit/types/election.test.ts +++ b/test/unit/types/election.test.ts @@ -1,6 +1,4 @@ import { CensusType, Election, UnpublishedElection, PublishedCensus, InvalidElection } from '../../../src'; -import { ArchivedElection } from '../../../src/types/election/archived'; -import { ArchivedCensus } from '../../../src/types/census/archived'; const validCensusId = '43cbda11b9d1a322c03eac325eb8a7b72779b46a76f8a727cff94b539ed9b903'; const validCensusURI = 'ipfs://QmeowUvr4Q9SMBSB942QVzFAqQQYukbjLYXxwANH3oTxbf'; @@ -150,10 +148,4 @@ describe('Election tests', () => { expect(election.id).toEqual('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'); expect(election.isValid).toBeFalsy(); }); - it('should be possible to create an archived election', () => { - electionData.census = new ArchivedCensus(validCensusId, validCensusURI); - const election = new ArchivedElection(electionData); - expect(election).toBeInstanceOf(ArchivedElection); - expect(election.census).toBeInstanceOf(ArchivedCensus); - }); });