Skip to content
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 ENS registry address flag #16

Merged
merged 3 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ const handle = require('../src/handle')
const cli = meow(`
Usage
$ aragon-dev-cli <subcommand>

Commands
init <name> Initialize a new Aragon module
version <major|minor|patch> Bump the module version
versions List the published versions of this module
publish Publish a new version of the module
playground Inject module into local Aragon application
playground Inject module into local Aragon application

Options
--key <privkey> The Ethereum private key to sign transactions with. Raw transaction will be dumped to stdout if no key is provided.
--key <privkey> The Ethereum private key to sign transactions with. Raw transaction will be dumped to stdout if no key is provided.
--registry <registry> The repository registry to use for creating and publishing packages (default: aragonpm.eth)
--rpc A URI to the Ethereum node used for RPC calls (default: https://ropsten.infura.io)
--chain-id The ID of the chain to interact with (default: 3)
--ens Address for the ENS registry (default: canonical ENS for chainId)

Examples
$ aragon-dev-cli version major
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const handlers = {
.then(async ({ appName }) => {
const eth = new Web3Eth(flags.rpc)

const repoAddress = await ens.resolve(appName, eth, flags.chainId)
const ensAddress = flags.ens || ens.chainRegistry(flags.chainId)
const repoAddress = await ens.resolve(appName, eth, ensAddress)
if (repoAddress === consts.NULL_ADDRESS) {
return []
}
Expand Down Expand Up @@ -200,11 +201,12 @@ const handlers = {
.then(async ({ appName, version, hash }) => {
const eth = new Web3Eth(flags.rpc)

let repoAddress = await ens.resolve(appName, eth, flags.chainId)
const ensAddress = flags.ens || ens.chainRegistry(flags.chainId)
let repoAddress = await ens.resolve(appName, eth, ensAddress)
if (repoAddress === consts.NULL_ADDRESS) {
// Create new repo
const registryName = appName.split('.').splice(-2).join('.')
const registryAddress = await ens.resolve(registryName, eth, flags.chainId)
const registryAddress = await ens.resolve(registryName, eth, ensAddress)
if (registryAddress === consts.NULL_ADDRESS) {
reporter.error(`Registry ${registryName} does not exist.`)
return
Expand Down
36 changes: 21 additions & 15 deletions src/utils/ens-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ const consts = require('./constants')

const registries = {
1: '0x314159265dd8dbb310642f98f50c066173c1259b',
3: '0x112234455c3a32fd11230c42e7bccd4a84e02010'
3: '0x112234455c3a32fd11230c42e7bccd4a84e02010',
}

module.exports.resolve = function (name, eth, chainId = 1) {
const node = hash(name)
module.exports = {
chainRegistry(chainId) {
return registries[chainId]
},

return new eth.Contract(
require('../../abi/ens/ENSRegistry.json'),
registries[chainId]
).methods.resolver(node).call()
.then((resolverAddress) =>
resolverAddress === consts.NULL_ADDRESS
? resolverAddress
: new eth.Contract(
require('../../abi/ens/ENSResolver.json'),
resolverAddress
).methods.addr(node).call()
)
resolve(name, eth, registryAddress = this.chainRegistry(1)) {
const node = hash(name)

return new eth.Contract(
require('../../abi/ens/ENSRegistry.json'),
registryAddress
).methods.resolver(node).call()
.then((resolverAddress) =>
resolverAddress === consts.NULL_ADDRESS
? resolverAddress
: new eth.Contract(
require('../../abi/ens/ENSResolver.json'),
resolverAddress
).methods.addr(node).call()
)
},
}