From fedb10c5dabc65cc50b5dc2426651d30a901b349 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Mon, 1 Apr 2019 22:41:00 +0200 Subject: [PATCH] Dynamically get app ids from the namehash This dynamically hashes the app id which makes it easier to manually set contract addresses. This is useful in development environments with no default network ids. The used apm (which is part of the app id hash) is configurable. usage: new Kredits(provider, signer, { addresses: { Kernel: '0x...' }, apm: 'aragonpm.eth' }) --- lib/app_ids.json | 14 -------------- lib/contracts/kernel.js | 11 +++++++---- lib/kredits.js | 8 +++++++- 3 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 lib/app_ids.json diff --git a/lib/app_ids.json b/lib/app_ids.json deleted file mode 100644 index 239e2c9..0000000 --- a/lib/app_ids.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "4": { - "Contribution": "0x09f5274cba299b46c5be722ef672d10eef7a2ef980b612aef529d74fb9da7643", - "Contributor": "0x8e50972b062e83b48dbb2a68d8a058f2a07227ca183c144dc974e6da3186d7e9", - "Proposal": "0xb48bc8b4e539823f3be98d67f4130c07b5d29cc998993debcdea15c6faf4cf8a", - "Token": "0x82c0e483537d703bb6f0fc799d2cc60d8f62edcb0f6d26d5571a92be8485b112" - }, - "41787949": { - "Contribution": "0xe401b988b8af39119004de5c7691a60391d69d873b3120682a8c61306a4883ce", - "Contributor": "0x7829d33291d6e118d115ce321de9341894a2da120bd35505fc03b98f715c606d", - "Proposal": "0x15d03d435b24a74317868c24fda4646302076b59272241a122a3868eb5c745da", - "Token": "0x85b0f626cecde6188d11940904fedeb16a4d49b0e8c878b9d109b23d38062ca7" - } -} diff --git a/lib/contracts/kernel.js b/lib/contracts/kernel.js index 7f7f8fd..84ac26f 100644 --- a/lib/contracts/kernel.js +++ b/lib/contracts/kernel.js @@ -1,8 +1,13 @@ -const AppIds = require('../app_ids.json'); +const namehash = require('eth-ens-namehash').hash; const Base = require('./base'); + const KERNEL_APP_ADDR_NAMESPACE = '0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb'; class Kernel extends Base { + constructor(contract) { + super(contract); + this.apm = 'aragonpm.eth'; // can be overwritten if needed + } getApp(appName) { if (appName === 'Acl') { @@ -12,9 +17,7 @@ class Kernel extends Base { } appNamehash(appName) { - // actually provider.network is an asynchronous property. - // but when we call this function kredits is already initialized and the network is already loaded - return AppIds[this.contract.provider.network.chainId.toString()][appName]; + return namehash(`kredits-${appName.toLowerCase()}.${this.apm}`); } } diff --git a/lib/kredits.js b/lib/kredits.js index 2f80b8d..ef47795 100644 --- a/lib/kredits.js +++ b/lib/kredits.js @@ -36,6 +36,7 @@ class Kredits { this.provider = provider; this.signer = signer; + this.options = options; this.addresses = addresses || {}; this.abis = abis || ABIS; this.ipfs = new IPFS(ipfsConfig); @@ -66,7 +67,12 @@ class Kredits { } get Kernel() { - return this.contractFor('Kernel'); + let k = this.contractFor('Kernel'); + // in case we want to use a special apm (e.g. development vs. production) + if (this.options.apm) { + k.apm = this.options.apm; + } + return k; } get Contributor() {