Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Change admin command #47

Merged
merged 3 commits into from
Aug 28, 2018
Merged

Change admin command #47

merged 3 commits into from
Aug 28, 2018

Conversation

spalladino
Copy link
Contributor

Add new set-admin command to change admin ownership of a proxy. The command requires a -y or --yes flag to be actually run, otherwise it cowardly refuses. It can be run either with an address, or a contract name (optionally namespaced by a package). For instance:

$ zos session ...
$ zos set-admin MyContract $NEWADMIN -y
$ zos set-admin OpenZeppelin/ERC20 $NEWADMIN -y
$ zos set-admin 0x40 $NEWADMIN -y

Fixes #3

@spalladino spalladino added the status:ready-to-merge Order mergify to merge label Aug 28, 2018
Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I left some comments, the most important thing I think is to replicate the admin data of a contract instance in the rest of the code (e.g. status, create, etc). However, we can create further issues for that.

updateProxy({ package: proxyPackage, contract: proxyContract, address: proxyAddress }, fn) {
const fullname = toContractFullName(proxyPackage, proxyContract)
const index = _.findIndex(this.data.proxies[fullname], { address: proxyAddress })
if (index === -1) throw Error(`Proxy ${fullname} at ${proxyAddress} not found in network manifest`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we already introduce the word manifest (documentation and logging lines)? otherwise, I'd stay to files

@@ -148,6 +164,28 @@ export default class NetworkAppController extends NetworkBaseController {
log.error(`Possible migration method 'migrate' found in contract ${contractClass.contractName}. Remember running the migration after deploying it.`);
}

_fetchOwnedProxies(packageName, contractAlias, proxyAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a need to specify owned? is there a chance for a project to manage other proxies than the ones it owns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After changing ownership of a proxy, the project will still keep track of it, and they will still be listed in the network file. It doesn't manage them, but it does have a reference to them.

})

if (_.isEmpty(proxies)) {
log.info('No owned contract instances that match were found');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be No matching contract instances were found?
We could also log what we were looking for to be clearer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you are repeating this validation in line 181, I think you can just delete this one since the filter above won't bother you in case no proxies were found at this point

Copy link
Contributor Author

@spalladino spalladino Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation in line 181 is about ownedProxies, not proxies, and I wanted to show different messages depending on whether no proxies were found, or those found were not owned by the app.

_.map(proxies, async (proxy) => {
log.info(`Changing admin of proxy ${proxy.address} to ${newAdmin}`)
await this.project.changeProxyAdmin(proxy.address, newAdmin)
this.networkFile.updateProxy(proxy, proxy => ({ ... proxy, admin: newAdmin }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we set this value also when creating a new instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can safely assume that by default the admin of a new instance is the app

}
async setProxiesAdmin(packageName, contractAlias, proxyAddress, newAdmin) {
const proxies = this._fetchOwnedProxies(packageName, contractAlias, proxyAddress)
if (proxies.length === 0) return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use lodash here to be consistent?


if (_.isEmpty(ownedProxies)) {
log.info('No matching contract instances are owned by this application');
return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to specify different returns giving the one above will work as you are expecting in case no proxies were found


const name = 'set-admin'
const signature = `${name} [alias-or-address] [new-admin-address]`
const description = 'change upgradeability admin of a contract instance. Provide the [alias] or [package]/[alias] you added your contract with, or its [address]. Note that if you transfer to an incorrect address, you may irreversibly lose control over upgrading your contract.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make clear that in case of an alias we are going to set the admin of all the instances for that alias

@mergify mergify bot merged commit b58a7ec into next Aug 28, 2018
@facuspagnuolo facuspagnuolo deleted the feature/change-admin-command branch August 28, 2018 15:46
spalladino added a commit that referenced this pull request Sep 24, 2018
* Set admin script to change admin of a proxy

* Register set-admin command

* Add logging
spalladino added a commit that referenced this pull request Sep 24, 2018
* Set admin script to change admin of a proxy

* Register set-admin command

* Add logging
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready-to-merge Order mergify to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants