-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various improvements to the CLI, allow voters to revote for a group (#…
- Loading branch information
Showing
34 changed files
with
494 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { sleep } from '@celo/utils/lib/async' | ||
import { flags } from '@oclif/command' | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
|
||
export default class ElectionVote extends BaseCommand { | ||
static description = 'Activate pending votes in validator elections to begin earning rewards' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ required: true, description: "Voter's address" }), | ||
wait: flags.boolean({ description: 'Wait until all pending votes become activatable' }), | ||
} | ||
|
||
static examples = [ | ||
'activate --from 0x4443d0349e8b3075cba511a0a87796597602a0f1', | ||
'activate --from 0x4443d0349e8b3075cba511a0a87796597602a0f1 --wait', | ||
] | ||
async run() { | ||
const res = this.parse(ElectionVote) | ||
|
||
this.kit.defaultAccount = res.flags.from | ||
await newCheckBuilder(this, res.flags.from) | ||
.isSignerOrAccount() | ||
.runChecks() | ||
|
||
const election = await this.kit.contracts.getElection() | ||
const accounts = await this.kit.contracts.getAccounts() | ||
const account = await accounts.voteSignerToAccount(res.flags.from) | ||
const hasPendingVotes = await election.hasPendingVotes(account) | ||
if (hasPendingVotes) { | ||
if (res.flags.wait) { | ||
// Spin until pending votes become activatable. | ||
while (!(await election.hasActivatablePendingVotes(account))) { | ||
await sleep(1000) | ||
} | ||
} | ||
const txos = await election.activate(account) | ||
for (const txo of txos) { | ||
await displaySendTx('activate', txo, { from: res.flags.from }) | ||
} | ||
if (txos.length === 0) { | ||
this.log(`Pending votes not yet activatable. Consider using the --wait flag.`) | ||
} | ||
} else { | ||
this.log(`No pending votes to activate`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { flags } from '@oclif/command' | ||
import BigNumber from 'bignumber.js' | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
|
||
export default class ElectionRevoke extends BaseCommand { | ||
static description = 'Revoke votes for a Validator Group in validator elections.' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ required: true, description: "Voter's address" }), | ||
for: Flags.address({ | ||
description: "ValidatorGroup's address", | ||
required: true, | ||
}), | ||
value: flags.string({ description: 'Value of votes to revoke', required: true }), | ||
} | ||
|
||
static examples = [ | ||
'revoke --from 0x4443d0349e8b3075cba511a0a87796597602a0f1 --for 0x932fee04521f5fcb21949041bf161917da3f588b, --value 1000000', | ||
] | ||
async run() { | ||
const res = this.parse(ElectionRevoke) | ||
|
||
this.kit.defaultAccount = res.flags.from | ||
await newCheckBuilder(this, res.flags.from) | ||
.isSignerOrAccount() | ||
.isValidatorGroup(res.flags.for) | ||
.runChecks() | ||
|
||
const election = await this.kit.contracts.getElection() | ||
const accounts = await this.kit.contracts.getAccounts() | ||
const account = await accounts.voteSignerToAccount(res.flags.from) | ||
const txos = await election.revoke(account, res.flags.for, new BigNumber(res.flags.value)) | ||
for (const txo of txos) { | ||
await displaySendTx('revoke', txo, { from: res.flags.from }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import { flags } from '@oclif/command' | ||
import { IArg } from '@oclif/parser/lib/args' | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { printValueMap } from '../../utils/cli' | ||
import { printValueMapRecursive } from '../../utils/cli' | ||
import { Args } from '../../utils/command' | ||
|
||
export default class ElectionShow extends BaseCommand { | ||
static description = 'Show election information about an existing Validator Group' | ||
static description = 'Show election information about a voter or Validator Group' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
voter: flags.boolean({ | ||
exclusive: ['group'], | ||
description: 'Show information about an account voting in Validator elections', | ||
}), | ||
group: flags.boolean({ | ||
exclusive: ['voter'], | ||
description: 'Show information about a group running in Validator elections', | ||
}), | ||
} | ||
|
||
static args: IArg[] = [ | ||
Args.address('groupAddress', { description: "Validator Groups's address" }), | ||
Args.address('address', { description: "Voter or Validator Groups's address" }), | ||
] | ||
|
||
static examples = ['show 0x97f7333c51897469E8D98E7af8653aAb468050a3'] | ||
|
||
async run() { | ||
const { args } = this.parse(ElectionShow) | ||
const address = args.groupAddress | ||
const res = this.parse(ElectionShow) | ||
const address = res.args.address | ||
const election = await this.kit.contracts.getElection() | ||
|
||
await newCheckBuilder(this) | ||
.isValidatorGroup(address) | ||
.runChecks() | ||
|
||
const groupVotes = await election.getValidatorGroupVotes(address) | ||
printValueMap(groupVotes) | ||
if (res.flags.group) { | ||
await newCheckBuilder(this) | ||
.isValidatorGroup(address) | ||
.runChecks() | ||
const groupVotes = await election.getValidatorGroupVotes(address) | ||
printValueMapRecursive(groupVotes) | ||
} else if (res.flags.voter) { | ||
await newCheckBuilder(this) | ||
.isAccount(address) | ||
.runChecks() | ||
const voter = await election.getVoter(address) | ||
printValueMapRecursive(voter) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.