Skip to content

Commit

Permalink
Merge pull request #16 from aragon/ens-address
Browse files Browse the repository at this point in the history
Add ENS registry address flag
  • Loading branch information
izqui authored Nov 15, 2017
2 parents a5c3dd8 + c569d2e commit 61f18f8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
22 changes: 9 additions & 13 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,32 @@ const handle = require('../src/handle')
const cli = meow(`
Usage
$ aragon-dev-cli <subcommand>
Commands
init <name> Initialize a new Aragon module
init <name> Initialize a new Aragon module (e.g. test.aragonpm.eth)
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.
--registry <registry> The repository registry to use for creating and publishing packages (default: aragonpm.eth)
--key <privkey> The Ethereum private key to sign transactions with. Raw transaction will be dumped to stdout if no key is provided.
--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-registry Address for the ENS registry (default: canonical ENS for chainId)
Examples
$ aragon-dev-cli version major
New version is 2.0.0
$ aragon-dev-cli init poll --registry=module-corp.eth
Created new module poll.module-corp.eth
$ aragon-dev-cli init cool-app
$ aragon-dev-cli init cool-app.aragonpm.eth
Created new module cool-app.aragonpm.eth
`, {
default: {
registry: 'aragonpm.eth',
rpc: 'https://ropsten.infura.io',
chainId: 3
chainId: 3,
},
string: ['key', 'rpc', 'registry']
string: ['key', 'rpc', 'ens-registry']
})

handle(cli)
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.

14 changes: 6 additions & 8 deletions src/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ const handlers = {
reporter.fatal('No name specified')
}

if (!flags.registry) {
reporter.fatal('No registry specified')
}

pkg.write({
appName: name + '.' + flags.registry,
appName: name,
version: '1.0.0',
roles: [],
path: 'src/App.sol'
Expand All @@ -44,7 +40,8 @@ const handlers = {
.then(async ({ appName }) => {
const eth = new Web3Eth(flags.rpc)

const repoAddress = await ens.resolve(appName, eth, flags.chainId)
const ensAddress = flags.ensRegistry || ens.chainRegistry(flags.chainId)
const repoAddress = await ens.resolve(appName, eth, ensAddress)
if (repoAddress === consts.NULL_ADDRESS) {
return []
}
Expand Down Expand Up @@ -200,11 +197,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.ensRegistry || 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()
)
},
}

0 comments on commit 61f18f8

Please sign in to comment.