Skip to content

Commit

Permalink
Merge pull request #1343 from privacy-scaling-explorations/feature/ad…
Browse files Browse the repository at this point in the history
…d-start-block

feat(cli): add start block for signup event parsing
  • Loading branch information
0xmad authored Apr 3, 2024
2 parents e7ec721 + 9657b6e commit 5e65e8e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cli/ts/commands/genLocalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export const genLocalState = async ({
const messageAqContract = AccQueueFactory.connect(messageAq, signer);

const [defaultStartBlockSignup, defaultStartBlockPoll, stateRoot, numSignups, messageRoot] = await Promise.all([
maciContract.queryFilter(maciContract.filters.SignUp()).then((events) => events[0]?.blockNumber ?? 0),
maciContract.queryFilter(maciContract.filters.DeployPoll()).then((events) => events[0]?.blockNumber ?? 0),
maciContract.queryFilter(maciContract.filters.SignUp(), startBlock).then((events) => events[0]?.blockNumber ?? 0),
maciContract
.queryFilter(maciContract.filters.DeployPoll(), startBlock)
.then((events) => events[0]?.blockNumber ?? 0),
maciContract.getStateAqRoot(),
maciContract.numSignUps(),
messageAqContract.getMainRoot(messageTreeDepth),
Expand Down
6 changes: 4 additions & 2 deletions cli/ts/commands/genProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ export const genProofs = async ({
} else {
// build an off-chain representation of the MACI contract using data in the contract storage
const [defaultStartBlockSignup, defaultStartBlockPoll, stateRoot, numSignups, messageRoot] = await Promise.all([
maciContract.queryFilter(maciContract.filters.SignUp()).then((events) => events[0]?.blockNumber ?? 0),
maciContract.queryFilter(maciContract.filters.DeployPoll()).then((events) => events[0]?.blockNumber ?? 0),
maciContract.queryFilter(maciContract.filters.SignUp(), startBlock).then((events) => events[0]?.blockNumber ?? 0),
maciContract
.queryFilter(maciContract.filters.DeployPoll(), startBlock)
.then((events) => events[0]?.blockNumber ?? 0),
maciContract.getStateAqRoot(),
maciContract.numSignUps(),
messageAqContract.getMainRoot(messageTreeDepth),
Expand Down
6 changes: 5 additions & 1 deletion cli/ts/commands/signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ export const isRegisteredUser = async ({
maciAddress,
maciPubKey,
signer,
startBlock,
quiet = true,
}: IRegisteredUserArgs): Promise<{ isRegistered: boolean; stateIndex?: string; voiceCredits?: string }> => {
banner(quiet);

const maciContract = MACIFactory.connect(maciAddress, signer);
const publicKey = PubKey.deserialize(maciPubKey).asContractParam();

const events = await maciContract.queryFilter(maciContract.filters.SignUp(undefined, publicKey.x, publicKey.y));
const events = await maciContract.queryFilter(
maciContract.filters.SignUp(undefined, publicKey.x, publicKey.y),
startBlock,
);
const stateIndex = events[0]?.args[0].toString() as string | undefined;
const voiceCredits = events[0]?.args[3].toString() as string | undefined;

Expand Down
5 changes: 5 additions & 0 deletions cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ export interface IRegisteredUserArgs {
*/
maciAddress: string;

/**
* Start block for event parsing
*/
startBlock?: number;

/**
* Whether to log the output
*/
Expand Down
8 changes: 6 additions & 2 deletions contracts/tasks/helpers/ProofGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ export class ProofGenerator {
// build an off-chain representation of the MACI contract using data in the contract storage
const [defaultStartBlockSignup, defaultStartBlockPoll, { messageTreeDepth }, stateRoot, numSignups] =
await Promise.all([
maciContract.queryFilter(maciContract.filters.SignUp()).then((events) => events[0]?.blockNumber ?? 0),
maciContract.queryFilter(maciContract.filters.DeployPoll()).then((events) => events[0]?.blockNumber ?? 0),
maciContract
.queryFilter(maciContract.filters.SignUp(), startBlock)
.then((events) => events[0]?.blockNumber ?? 0),
maciContract
.queryFilter(maciContract.filters.DeployPoll(), startBlock)
.then((events) => events[0]?.blockNumber ?? 0),
pollContract.treeDepths(),
maciContract.getStateAqRoot(),
maciContract.numSignUps(),
Expand Down

0 comments on commit 5e65e8e

Please sign in to comment.