Skip to content

Commit

Permalink
Removed archive functionality because it will be no longer used
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Aug 29, 2024
1 parent 5156639 commit a1008eb
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 80 deletions.
5 changes: 0 additions & 5 deletions src/api/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ export interface IElectionInfoResponse {
*/
manuallyEnded: boolean;

/**
* If the election comes from the archive
*/
fromArchive: boolean;

/**
* The chain identifier of the election
*/
Expand Down
3 changes: 1 addition & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Account,
AllElectionStatus,
AnonymousVote,
ArchivedElection,
CensusType,
CspVote,
ElectionStatus,
Expand Down Expand Up @@ -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<PublishedElection | ArchivedElection> {
async fetchElection(electionId?: string, password?: string): Promise<PublishedElection> {
invariant(this.electionId || electionId, 'No election set');

this.election = await this.electionService.fetchElection(electionId ?? this.electionId, password);
Expand Down
26 changes: 11 additions & 15 deletions src/services/election.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Service, ServiceProperties } from './service';
import {
AllElectionStatus,
ArchivedElection,
Census,
CspCensus,
ElectionResultsTypeNames,
Expand All @@ -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';
Expand All @@ -49,7 +47,7 @@ export interface FetchElectionsParameters {
status: Exclude<AllElectionStatus, ElectionStatus.ONGOING | ElectionStatus.UPCOMING>;
}

export type ElectionList = Array<PublishedElection | ArchivedElection | InvalidElection>;
export type ElectionList = Array<PublishedElection | InvalidElection>;
export type ElectionListWithPagination = { elections: ElectionList } & PaginationResponse;

export type ElectionKeys = IElectionKeysResponse;
Expand Down Expand Up @@ -116,13 +114,11 @@ export class ElectionService extends Service implements ElectionServicePropertie
);
}

private buildCensus(electionInfo): Promise<PublishedCensus | ArchivedCensus> {
private buildCensus(electionInfo): Promise<PublishedCensus> {
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) {
Expand Down Expand Up @@ -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<PublishedElection | ArchivedElection> {
async fetchElection(electionId: string, password?: string): Promise<PublishedElection> {
invariant(this.url, 'No URL set');
invariant(this.censusService, 'No census service set');

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 0 additions & 21 deletions src/types/census/archived.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/types/election/archived.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/types/election/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
7 changes: 0 additions & 7 deletions src/types/election/published.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface IPublishedElectionParameters extends IElectionParameters {
finalResults: boolean;
results: Array<Array<string>>;
manuallyEnded: boolean;
fromArchive: boolean;
chainId: string;
creationTime: string;
metadataURL: string;
Expand All @@ -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<Array<string>>;
private readonly _creationTime: Date;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -212,10 +209,6 @@ export class PublishedElection extends Election {
return this._manuallyEnded;
}

get fromArchive(): boolean {
return this._fromArchive;
}

get chainId(): string {
return this._chainId;
}
Expand Down
1 change: 0 additions & 1 deletion test/integration/election.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions test/unit/types/election.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});

0 comments on commit a1008eb

Please sign in to comment.