From e1f19a1832120a8f65d4deb74b122e295fa47f37 Mon Sep 17 00:00:00 2001
From: bumi
Date: Sun, 15 Apr 2018 16:45:09 +0200
Subject: [PATCH 01/12] Fail smarter with better error handling
This should give more insights in case of an error during loading data
from Ethereum and IPFS.
---
app/lib/kredits/kredits.js | 45 +++++++++++++++++++++++++++--------
app/lib/kredits/utils/ipfs.js | 1 -
app/routes/application.js | 2 ++
3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/app/lib/kredits/kredits.js b/app/lib/kredits/kredits.js
index b087371..7001a9a 100644
--- a/app/lib/kredits/kredits.js
+++ b/app/lib/kredits/kredits.js
@@ -27,22 +27,44 @@ export default class Kredits {
this.ipfsConfig = ipfsConfig;
this.ipfs = new IPFS(ipfsConfig);
- let registryContract = this.initRegistryContract(provider);
+ return this.ipfs._ipfsAPI.id().catch((error) => {
+ throw new Error(`IPFS node not available; config: ${JSON.stringify(ipfsConfig)} - ${error.message}`);
+ }).then(() => {
- let addresses = Object.keys(contracts).reduce((mem, name) => {
- let contractName = capitalize(name);
- mem[contractName] = registryContract.functions.getProxyFor(contractName);
- return mem;
- }, {});
+ let registryContract = this.initRegistryContract(provider);
- return RSVP.hash(addresses)
- .then((addresses) => {
- return new Kredits(provider, signer, addresses);
- });
+ let addresses = Object.keys(contracts).reduce((mem, name) => {
+ let contractName = capitalize(name);
+ mem[contractName] = registryContract.functions.getProxyFor(contractName).catch((error) => {
+ throw new Error(`Failed to get address for ${contractName} from registry at ${registryContract.address}
+ - correct registry? does it have version entry? - ${error.message}`
+ );
+ });
+ return mem;
+ }, {});
+
+ return RSVP.hash(addresses)
+ .then((addresses) => {
+ return new Kredits(provider, signer, addresses);
+ });
+ });
}
static initRegistryContract(provider) {
let address = addresses['Registry'][provider.chainId];
+ if (!address) {
+ throw new Error(`Registry address not found; invalid network?
+ requested network: ${provider.chainId}
+ supported networks: ${Object.keys(addresses['Registry'])}
+ `);
+ }
+ provider.getCode(address).then((code) => {
+ // not sure if we always get the same return value of the code is not available
+ // that's why checking if it is < 5 long
+ if (code === '0x00' || code.length < 5) {
+ throw new Error(`Registry not found at ${address} on network ${provider.chainId}`);
+ }
+ });
let abi = abis['Registry'];
console.log('Initialize registry contract:', address, abi, provider);
return new ethers.Contract(address, abi, provider);
@@ -69,6 +91,9 @@ export default class Kredits {
let contractName = capitalize(name);
let address = this.addresses[contractName];
+ if (!address || !abis[contractName]) {
+ throw new Error('Address or ABI not found for ' + contractName);
+ }
let contract = new ethers.Contract(address, abis[contractName], this.signer);
this.contracts[name] = new contracts[contractName](contract);
diff --git a/app/lib/kredits/utils/ipfs.js b/app/lib/kredits/utils/ipfs.js
index 5a2a7e4..bc6ccda 100644
--- a/app/lib/kredits/utils/ipfs.js
+++ b/app/lib/kredits/utils/ipfs.js
@@ -51,5 +51,4 @@ export default class IPFS {
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
}
-
}
diff --git a/app/routes/application.js b/app/routes/application.js
index 9371c64..602cdbd 100644
--- a/app/routes/application.js
+++ b/app/routes/application.js
@@ -13,6 +13,8 @@ export default Route.extend({
transition.retry();
}
}
+ }).catch((error) => {
+ console.log('Error initializing Kredits', error);
});
},
});
--
2.50.1
From 7e6c6a037d3e0ce73034cc56ee1c8e5d735ee6f5 Mon Sep 17 00:00:00 2001
From: bumi
Date: Sun, 15 Apr 2018 18:02:52 +0200
Subject: [PATCH 02/12] code style. use interpolation syntax
---
app/lib/kredits/kredits.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/lib/kredits/kredits.js b/app/lib/kredits/kredits.js
index 7001a9a..46a893f 100644
--- a/app/lib/kredits/kredits.js
+++ b/app/lib/kredits/kredits.js
@@ -92,7 +92,7 @@ export default class Kredits {
let contractName = capitalize(name);
let address = this.addresses[contractName];
if (!address || !abis[contractName]) {
- throw new Error('Address or ABI not found for ' + contractName);
+ throw new Error(`Address or ABI not found for ${contractName}`);
}
let contract = new ethers.Contract(address, abis[contractName], this.signer);
this.contracts[name] = new contracts[contractName](contract);
--
2.50.1
From 399ee27af975ed71720bebb510e32798d3840a8d Mon Sep 17 00:00:00 2001
From: Michael Bumann
Date: Sun, 15 Apr 2018 16:35:31 +0000
Subject: [PATCH 03/12] Revert "Adjust for new naming conventions"
---
app/components/add-contributor/component.js | 8 ++++----
app/components/add-contributor/template.hbs | 6 +++---
app/components/contributor-list/template.hbs | 2 +-
app/controllers/index.js | 6 ++++--
app/lib/kredits/contracts/contributor.js | 10 +++++++++-
app/lib/kredits/contracts/operator.js | 10 +++++++++-
app/models/contributor.js | 3 ++-
app/models/proposal.js | 2 +-
app/services/kredits.js | 5 +++++
app/templates/index.hbs | 2 +-
10 files changed, 39 insertions(+), 15 deletions(-)
diff --git a/app/components/add-contributor/component.js b/app/components/add-contributor/component.js
index 254ec95..13c83da 100644
--- a/app/components/add-contributor/component.js
+++ b/app/components/add-contributor/component.js
@@ -9,7 +9,7 @@ export default Component.extend({
// Default attributes used by reset
attributes: {
- account: null,
+ address: null,
name: null,
kind: 'person',
url: null,
@@ -24,9 +24,9 @@ export default Component.extend({
this.reset();
},
- isValidAccount: computed('kredits.ethProvider', 'account', function() {
+ isValidAddress: computed('kredits.ethProvider', 'address', function() {
// TODO: add proper address validation
- return this.get('account') !== '';
+ return this.get('address') !== '';
}),
isValidName: isPresent('name'),
isValidURL: isPresent('url'),
@@ -34,7 +34,7 @@ export default Component.extend({
isValidGithubUsername: isPresent('github_username'),
isValidWikiUsername: isPresent('wiki_username'),
isValid: and(
- 'isValidAccount',
+ 'isValidAddress',
'isValidName',
'isValidGithubUID'
),
diff --git a/app/components/add-contributor/template.hbs b/app/components/add-contributor/template.hbs
index c47fd92..ded7d47 100644
--- a/app/components/add-contributor/template.hbs
+++ b/app/components/add-contributor/template.hbs
@@ -9,11 +9,11 @@
- {{input name="account"
+ {{input name="address"
type="text"
placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4"
- value=account
- class=(if isValidAccount 'valid' '')}}
+ value=address
+ class=(if isValidAddress 'valid' '')}}