Skip to content

Commit

Permalink
chore: get poll mode within sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Sep 2, 2024
1 parent eb1ce58 commit fe7a8d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/cli/ts/commands/poll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ZeroAddress } from "ethers";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory } from "maci-contracts/typechain-types";
import { MACI__factory as MACIFactory, Poll__factory as PollFactory, Tally__factory as TallyFactory } from "maci-contracts/typechain-types";

Check failure on line 2 in packages/cli/ts/commands/poll.ts

View workflow job for this annotation

GitHub Actions / check (lint:ts)

Replace `·MACI__factory·as·MACIFactory,·Poll__factory·as·PollFactory,·Tally__factory·as·TallyFactory·` with `⏎··MACI__factory·as·MACIFactory,⏎··Poll__factory·as·PollFactory,⏎··Tally__factory·as·TallyFactory,⏎`

import type { IGetPollArgs, IGetPollData } from "../utils/interfaces";

Expand Down Expand Up @@ -32,9 +32,9 @@ export const getPoll = async ({
logError(`Invalid poll id ${id}`);
}

const { poll: pollAddress } = await maciContract.polls(id);
const { poll: pollAddress, tally: tallyAddress } = await maciContract.polls(id);

if (pollAddress === ZeroAddress) {
if (pollAddress === ZeroAddress || tallyAddress === ZeroAddress) {
logError(`MACI contract doesn't have any deployed poll ${id}`);
}

Expand All @@ -47,6 +47,10 @@ export const getPoll = async ({
const isMerged = mergedStateRoot !== BigInt(0);
const numSignups = await (isMerged ? pollContract.numSignups() : maciContract.numSignUps());

// get the poll mode
const tallyContract = TallyFactory.connect(tallyAddress, signer ?? provider);
const mode = await tallyContract.mode();

logGreen(
quiet,
success(
Expand All @@ -56,6 +60,7 @@ export const getPoll = async ({
`End time: ${new Date(Number(deployTime + duration) * 1000).toString()}`,
`Number of signups ${numSignups}`,
`State tree merged: ${mergedStateRoot}`,
`Mode: ${mode === 0n ? "Quadratic Voting" : "Non-Quadratic Voting"}`,
].join("\n"),
),
);
Expand All @@ -67,5 +72,6 @@ export const getPoll = async ({
duration,
numSignups,
isMerged,
mode,
};
};
6 changes: 6 additions & 0 deletions packages/cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,12 @@ export interface IGetPollData {
* Whether the MACI contract's state root has been merged
*/
isMerged: boolean;


Check failure on line 948 in packages/cli/ts/utils/interfaces.ts

View workflow job for this annotation

GitHub Actions / check (lint:ts)

Delete `⏎`
/**
* Mode of the poll
*/
mode: BigNumberish;
}

/**
Expand Down

0 comments on commit fe7a8d7

Please sign in to comment.