Skip to content

Commit

Permalink
feat(fetchlogs) - ensure that we are deserializing the Command object…
Browse files Browse the repository at this point in the history
…s correctly and fix bug in curentMessageBatchIndex
  • Loading branch information
ctrlc03 committed Nov 7, 2023
1 parent 5defa17 commit 1a2a444
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cli/ts/genProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from './utils'
import {readJSONFile} from 'maci-common'
import {contractFilepath} from './config'
import { MaciState } from 'maci-core'
import { MaciState, Poll } from 'maci-core'

const configureSubparser = (subparsers: any) => {
const parser = subparsers.addParser(
Expand Down Expand Up @@ -366,6 +366,8 @@ const genProofs = async (args: any) => {
// @todo actually read the file first
const content = JSON.parse(fs.readFileSync(args.state_file, 'utf-8').toString())
maciState = MaciState.fromJSON(content)
// ensure we merge all messages
maciState.polls.forEach((poll: Poll) => poll.mergeAllMessages())
} else {
// some rpc endpoint like bsc chain has limitation to retreive history logs
let fromBlock = args.start_block ? args.start_block : 0
Expand Down
17 changes: 15 additions & 2 deletions core/ts/MaciState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ class Poll {
ballots: this.ballots.map(ballot => ballot.toJSON()),
encPubKeys: this.encPubKeys.map(encPubKey => encPubKey.serialize()),
ballotTree: this.ballotTree,
currentMessageBatchIndex: this.currentMessageBatchIndex ? this.currentMessageBatchIndex.toString() : "",
currentMessageBatchIndex: this.currentMessageBatchIndex,
stateLeaves: this.stateLeaves.map(leaf => leaf.toJSON()),
results: this.results.map(result => result.toString()),
numBatchesProcessed: this.numBatchesProcessed,
Expand Down Expand Up @@ -1373,7 +1373,19 @@ class Poll {
poll.ballots = json.ballots.map((ballot: Ballot) => Ballot.fromJSON(ballot))
poll.encPubKeys = json.encPubKeys.map((key: string) => PubKey.unserialize(key))
poll.messages = json.messages.map((message: Message) => Message.fromJSON(message))
poll.commands = json.commands.map((command: Command) => Command.fromJSON(command))
poll.commands = json.commands.map((command: any) => {
switch (command.cmdType) {
case "1": {
return PCommand.fromJSON(command)
}
case "2": {
return TCommand.fromJSON(command)
}
default: {
return Command.fromJSON(command)
}
}
})
poll.results = json.results.map((result: string) => BigInt(result))
poll.currentMessageBatchIndex = json.currentMessageBatchIndex
poll.numBatchesProcessed = json.numBatchesProcessed
Expand All @@ -1387,6 +1399,7 @@ class Poll {

// copy maci state
poll.copyStateFromMaci()

return poll
}
}
Expand Down

0 comments on commit 1a2a444

Please sign in to comment.