Filter init msg (#6)

This commit is contained in:
Szymon Szlachtowicz 2021-08-10 15:20:35 +02:00 committed by GitHub
parent c1b326ab9c
commit e564350805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -62,6 +62,7 @@ class WakuVoting {
return messages return messages
?.filter((e): e is WakuMessage & { payload: Uint8Array } => !!e?.payload) ?.filter((e): e is WakuMessage & { payload: Uint8Array } => !!e?.payload)
.map((msg) => PollInit.decode(msg.payload, msg.timestamp)) .map((msg) => PollInit.decode(msg.payload, msg.timestamp))
.filter((poll): poll is PollInitMsg => !!poll)
} }
} }

View File

@ -12,8 +12,10 @@ export class PollInitMsg {
public minToken?: BigNumber public minToken?: BigNumber
public endTime: number public endTime: number
public signature: string public signature: string
public id: string
private constructor( private constructor(
id: string,
owner: string, owner: string,
signature: string, signature: string,
timestamp: number, timestamp: number,
@ -23,6 +25,7 @@ export class PollInitMsg {
endTime: number, endTime: number,
minToken?: BigNumber minToken?: BigNumber
) { ) {
this.id = id
this.owner = owner this.owner = owner
this.timestamp = timestamp this.timestamp = timestamp
this.question = question this.question = question
@ -70,8 +73,8 @@ export class PollInitMsg {
const packedData = utils.arrayify(utils.solidityPack(types, msg)) const packedData = utils.arrayify(utils.solidityPack(types, msg))
const signature = await signer.signMessage(packedData) const signature = await signer.signMessage(packedData)
const id = utils.solidityKeccak256(['address', 'uint256'], [owner, timestamp])
return new PollInitMsg(owner, signature, timestamp, question, answers, pollType, newEndTime, minToken) return new PollInitMsg(id, owner, signature, timestamp, question, answers, pollType, newEndTime, minToken)
} }
static fromProto(payload: PollInit) { static fromProto(payload: PollInit) {
@ -108,7 +111,7 @@ export class PollInitMsg {
if (verifiedAddress != owner) { if (verifiedAddress != owner) {
return undefined return undefined
} }
const id = utils.solidityKeccak256(['address', 'uint256'], [owner, timestamp])
return new PollInitMsg(owner, signature, timestamp, question, answers, pollType, endTime, minToken) return new PollInitMsg(id, owner, signature, timestamp, question, answers, pollType, endTime, minToken)
} }
} }