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 8807c44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/cli/ts/commands/poll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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";

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

Expand Down Expand Up @@ -32,9 +36,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 +51,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 +64,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 +76,6 @@ export const getPoll = async ({
duration,
numSignups,
isMerged,
mode,
};
};
5 changes: 5 additions & 0 deletions packages/cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ export interface IGetPollData {
* Whether the MACI contract's state root has been merged
*/
isMerged: boolean;

/**
* Mode of the poll
*/
mode: BigNumberish;
}

/**
Expand Down

0 comments on commit 8807c44

Please sign in to comment.