-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unfreeze-contracts command to celotool #2433
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* tslint:disable no-console */ | ||
import { newKit } from '@celo/contractkit' | ||
import { eqAddress } from '@celo/utils/lib/address' | ||
import { switchToClusterFromEnv } from 'src/lib/cluster' | ||
import { addCeloEnvMiddleware, CeloEnvArgv } from 'src/lib/env-utils' | ||
import { portForwardAnd } from 'src/lib/port_forward' | ||
import yargs from 'yargs' | ||
|
||
export const command = 'unfreeze-contracts' | ||
|
||
export const describe = 'command for unfreezing epoch rewards and the exchange' | ||
|
||
interface UnfreezeContractsArgv extends CeloEnvArgv { | ||
exchange: boolean | ||
rewards: boolean | ||
freeze: boolean | ||
precheck: boolean | ||
verify: boolean | ||
} | ||
|
||
export const builder = (argv: yargs.Argv) => { | ||
return addCeloEnvMiddleware(argv) | ||
.option('exchange', { | ||
type: 'boolean', | ||
description: 'Affect the exchange', | ||
default: true, | ||
}) | ||
.option('rewards', { | ||
type: 'boolean', | ||
description: 'Affect epoch rewards', | ||
default: true, | ||
}) | ||
.option('freeze', { | ||
type: 'boolean', | ||
description: 'Freeze contracts instead of unfreezing', | ||
default: false, | ||
}) | ||
.option('precheck', { | ||
type: 'boolean', | ||
description: 'Check the contract freeze status before continuing', | ||
default: true, | ||
}) | ||
.option('verify', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, shouldn't we always do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want this to be an option in case it causes some kind of issue. |
||
type: 'boolean', | ||
description: 'Verify the contract freeze status after', | ||
default: true, | ||
}) | ||
} | ||
|
||
export const handler = async (argv: UnfreezeContractsArgv) => { | ||
await switchToClusterFromEnv() | ||
|
||
const cb = async () => { | ||
const kit = newKit('http://localhost:8545') | ||
const account = (await kit.web3.eth.getAccounts())[0] | ||
console.log(`Using account: ${account}`) | ||
kit.defaultAccount = account | ||
|
||
const [exchange, epochRewards] = await Promise.all([ | ||
argv.exchange ? kit._web3Contracts.getExchange() : null, | ||
argv.rewards ? kit._web3Contracts.getEpochRewards() : null, | ||
]) | ||
|
||
for (const [name, contract] of Object.entries({ exchange, epochRewards })) { | ||
if (contract == null) { | ||
continue | ||
} | ||
|
||
if (argv.precheck) { | ||
const frozen = await contract.methods.frozen().call() | ||
// console.debug(`${name}.frozen = ${frozen}`) | ||
if (argv.freeze == frozen) { | ||
console.error(`${name} is already ${argv.freeze ? 'frozen' : 'unfrozen'}. Skipping.`) | ||
continue | ||
} | ||
|
||
const freezer = await contract.methods.freezer().call() | ||
// console.debug(`${name}.freezer = ${freezer}`) | ||
if (!eqAddress(freezer, account)) { | ||
console.error(`${account} cannot freeze or unfreeze ${name}. Skipping.`) | ||
continue | ||
} | ||
} | ||
|
||
if (argv.freeze) { | ||
console.info(`Sending freeze transaction to ${name} ...`) | ||
await contract.methods.freeze().send({ from: account }) | ||
} else { | ||
console.info(`Sending unfreeze transaction to ${name} ...`) | ||
await contract.methods.unfreeze().send({ from: account }) | ||
} | ||
|
||
if (argv.verify) { | ||
const frozen = await contract.methods.frozen().call() | ||
// console.debug(`${name}.frozen = ${frozen}`) | ||
if (argv.freeze != frozen) { | ||
console.error( | ||
`${name} is not ${argv.freeze ? 'frozen' : 'unfrozen'}. Something went wrong.` | ||
) | ||
continue | ||
} | ||
console.info(`Succesfully ${argv.freeze ? 'froze' : 'unfroze'} ${name}`) | ||
} | ||
} | ||
} | ||
|
||
try { | ||
await portForwardAnd(argv.celoEnv, cb) | ||
} catch (error) { | ||
console.error(`Unable to ${argv.freeze ? 'freeze' : 'unfreeze'} contracts on ${argv.celoEnv}`) | ||
console.error(error) | ||
process.exit(1) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we always do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want this to be an option in case it causes some kind of issue.