Add Governor signature nonces (#4378)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco <fg@frang.io> Co-authored-by: Sergei Tikhomirov <sergey.s.tikhomirov@gmail.com> Co-authored-by: Renan Souza <renan.rodrigues.souza1@gmail.com>
This commit is contained in:
@ -91,26 +91,17 @@ class GovernorHelper {
|
||||
return vote.signature
|
||||
? // if signature, and either params or reason →
|
||||
vote.params || vote.reason
|
||||
? vote
|
||||
.signature(this.governor, {
|
||||
proposalId: proposal.id,
|
||||
support: vote.support,
|
||||
reason: vote.reason || '',
|
||||
params: vote.params || '',
|
||||
})
|
||||
.then(({ v, r, s }) =>
|
||||
this.governor.castVoteWithReasonAndParamsBySig(
|
||||
...concatOpts([proposal.id, vote.support, vote.reason || '', vote.params || '', v, r, s], opts),
|
||||
? this.sign(vote).then(({ v, r, s }) =>
|
||||
this.governor.castVoteWithReasonAndParamsBySig(
|
||||
...concatOpts(
|
||||
[proposal.id, vote.support, vote.voter, vote.reason || '', vote.params || '', v, r, s],
|
||||
opts,
|
||||
),
|
||||
)
|
||||
: vote
|
||||
.signature(this.governor, {
|
||||
proposalId: proposal.id,
|
||||
support: vote.support,
|
||||
})
|
||||
.then(({ v, r, s }) =>
|
||||
this.governor.castVoteBySig(...concatOpts([proposal.id, vote.support, v, r, s], opts)),
|
||||
)
|
||||
),
|
||||
)
|
||||
: this.sign(vote).then(({ v, r, s }) =>
|
||||
this.governor.castVoteBySig(...concatOpts([proposal.id, vote.support, vote.voter, v, r, s], opts)),
|
||||
)
|
||||
: vote.params
|
||||
? // otherwise if params
|
||||
this.governor.castVoteWithReasonAndParams(
|
||||
@ -122,6 +113,23 @@ class GovernorHelper {
|
||||
: this.governor.castVote(...concatOpts([proposal.id, vote.support], opts));
|
||||
}
|
||||
|
||||
sign(vote = {}) {
|
||||
return vote.signature(this.governor, this.forgeMessage(vote));
|
||||
}
|
||||
|
||||
forgeMessage(vote = {}) {
|
||||
const proposal = this.currentProposal;
|
||||
|
||||
const message = { proposalId: proposal.id, support: vote.support, voter: vote.voter, nonce: vote.nonce };
|
||||
|
||||
if (vote.params || vote.reason) {
|
||||
message.reason = vote.reason || '';
|
||||
message.params = vote.params || '';
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
async waitForSnapshot(offset = 0) {
|
||||
const proposal = this.currentProposal;
|
||||
const timepoint = await this.governor.proposalSnapshot(proposal.id);
|
||||
|
||||
Reference in New Issue
Block a user