Merge pull request #200 from 67P/ethers5

Update to ethers 5
This commit is contained in:
bumi 2020-07-07 16:59:40 +02:00 committed by GitHub
commit fbd82a442e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 230 additions and 72 deletions

View File

@ -1,4 +1,3 @@
{ {
"4": "0x76e069b47b79442657eaf0555a32c6b16fa1b8b4", "4": "0x76e069b47b79442657eaf0555a32c6b16fa1b8b4"
"18335577": "0xeE10a87d8D758B563E301F5C5d029bDD21166DCC"
} }

View File

@ -1,4 +1,3 @@
{ {
"4": "0xc34edf7d11b7f8433d597f0bb0697acdff55ef14", "4": "0xc34edf7d11b7f8433d597f0bb0697acdff55ef14"
"18335577": "0x29E33B66108fa2DC3a018f3DdE41D295eB0922D5"
} }

View File

@ -5,7 +5,7 @@ class Acl extends Base {
hasPermission (fromAddress, contractAddress, roleID, params = null) { hasPermission (fromAddress, contractAddress, roleID, params = null) {
let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID)); let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID));
return this.functions.hasPermission( return this.hasPermission(
fromAddress, fromAddress,
contractAddress, contractAddress,
roleHash, roleHash,

View File

@ -1,10 +1,13 @@
const deprecate = require('../utils/deprecate');
class Base { class Base {
constructor (contract) { constructor (contract) {
this.contract = contract; this.contract = contract;
} }
get functions () { get functions () {
return this.contract.functions; deprecate('The property `functions` is deprecated. contract functions are now directly defined on the ethers contract object. https://github.com/ethers-io/ethers.js/issues/920#issuecomment-650836642');
return this.contract;
} }
get address () { get address () {

View File

@ -4,33 +4,33 @@ const deprecate = require('../utils/deprecate');
class Contribution extends Record { class Contribution extends Record {
get count () { get count () {
return this.functions.contributionsCount(); return this.contract.contributionsCount();
} }
getById (id) { getById (id) {
return this.functions.getContribution(id) return this.contract.getContribution(id)
.then(data => { .then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
}); });
} }
getData (id) { getData (id) {
return this.functions.getContribution(id); return this.contract.getContribution(id);
} }
getByContributorId (contributorId) { getByContributorId (contributorId) {
return this.functions.getContributorAddressById(contributorId) return this.contract.getContributorAddressById(contributorId)
.then(address => this.getByContributorAddress(address)); .then(address => this.getByContributorAddress(address));
} }
getByContributorAddress (address) { getByContributorAddress (address) {
return this.functions.balanceOf(address) return this.contract.balanceOf(address)
.then(async (balance) => { .then(async (balance) => {
const count = balance.toNumber(); const count = balance.toNumber();
const contributions = []; const contributions = [];
for (let index = 0; index < count; index++) { for (let index = 0; index < count; index++) {
const id = await this.functions.tokenOfOwnerByIndex(address, index); const id = await this.contract.tokenOfOwnerByIndex(address, index);
const contribution = await this.getById(id); const contribution = await this.getById(id);
contributions.push(contribution); contributions.push(contribution);
} }
@ -58,7 +58,7 @@ class Contribution extends Record {
ipfsHashAttr.hashSize, ipfsHashAttr.hashSize,
]; ];
return this.functions.add(...contribution, callOptions); return this.contract.add(...contribution, callOptions);
}); });
} }

View File

@ -4,19 +4,20 @@ const formatKredits = require('../utils/format-kredits');
class Contributor extends Record { class Contributor extends Record {
get count () { get count () {
return this.functions.contributorsCount(); return this.contract.contributorsCount();
} }
getById (id) { getById (id) {
return this.functions.getContributorById(id) return this.contract.getContributorById(id)
.then(data => { .then(contractData => {
let data = {...contractData};
data.balanceInt = formatKredits(data.balance); data.balanceInt = formatKredits(data.balance);
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize); return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
}); });
} }
getData (id) { getData (id) {
return this.functions.getContributorById(id); return this.contract.getContributorById(id);
} }
filterByAccount (search) { filterByAccount (search) {
@ -61,7 +62,7 @@ class Contributor extends Record {
ipfsHashAttr.hashSize, ipfsHashAttr.hashSize,
]; ];
return this.functions.addContributor(...contributor, callOptions); return this.contract.addContributor(...contributor, callOptions);
}); });
} }
@ -78,7 +79,7 @@ class Contributor extends Record {
return this.ipfs return this.ipfs
.add(jsonStr) .add(jsonStr)
.then(ipfsHashAttr => { .then(ipfsHashAttr => {
return this.functions.updateContributorProfileHash( return this.contract.updateContributorProfileHash(
contributorId, contributorId,
ipfsHashAttr.hashDigest, ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction, ipfsHashAttr.hashFunction,

View File

@ -11,9 +11,9 @@ class Kernel extends Base {
getApp (appName) { getApp (appName) {
if (appName === 'Acl') { if (appName === 'Acl') {
return this.functions.acl(); return this.contract.acl();
} }
return this.functions.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName)); return this.contract.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName));
} }
appNamehash (appName) { appNamehash (appName) {

View File

@ -4,11 +4,11 @@ const deprecate = require('../utils/deprecate');
class Proposal extends Record { class Proposal extends Record {
get count () { get count () {
return this.functions.proposalsCount(); return this.contract.proposalsCount();
} }
getById (id) { getById (id) {
return this.functions.getProposal(id) return this.contract.getProposal(id)
.then(data => { .then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
}); });
@ -33,7 +33,7 @@ class Proposal extends Record {
ipfsHashAttr.hashSize, ipfsHashAttr.hashSize,
]; ];
return this.functions.addProposal(...proposal, callOptions); return this.contract.addProposal(...proposal, callOptions);
}); });
} }

View File

@ -30,11 +30,11 @@ class KreditsKit {
appIdFor (contractName) { appIdFor (contractName) {
// see appIds in KreditsKit.sol for more details // see appIds in KreditsKit.sol for more details
const knownContracts = ['Contribution', 'Contributor', 'Proposal', 'Token']; const knownContracts = ['Contribution', 'Contributor', 'Proposal', 'Token'];
return this.contract.functions.appIds(knownContracts.indexOf(contractName)); return this.contract.appIds(knownContracts.indexOf(contractName));
} }
newDAO (options = {}) { newDAO (options = {}) {
return this.contract.functions.newInstance(options).then(transaction => { return this.contract.newInstance(options).then(transaction => {
return transaction.wait().then(result => { return transaction.wait().then(result => {
const deployEvent = result.events.find(e => e.event === 'DeployInstance'); const deployEvent = result.events.find(e => e.event === 'DeployInstance');
return { return {

View File

@ -11,7 +11,8 @@ class IPFS {
this._ipfsAPI = ipfsClient(config); this._ipfsAPI = ipfsClient(config);
} }
catAndMerge (data, deserialize) { catAndMerge (contractData, deserialize) {
let data = {...contractData}; // data from ethers.js is not extensible. this copy the attributes in a new object
// if no hash details are found simply return the data; nothing to merge // if no hash details are found simply return the data; nothing to merge
if (!data.hashSize || data.hashSize === 0) { if (!data.hashSize || data.hashSize === 0) {
return data; return data;

170
package-lock.json generated
View File

@ -473,6 +473,12 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"await-semaphore": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/await-semaphore/-/await-semaphore-0.1.3.tgz",
"integrity": "sha512-d1W2aNSYcz/sxYO4pMGX9vq65qOTu0P800epMud+6cYYX0QcT7zyqcxec3VWzpgvdXo57UWmVbZpLMjX2m1I7Q==",
"dev": true
},
"aws-sign2": { "aws-sign2": {
"version": "0.7.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
@ -1408,6 +1414,12 @@
"safe-buffer": "^5.1.2" "safe-buffer": "^5.1.2"
} }
}, },
"btoa": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz",
"integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==",
"dev": true
},
"buffer": { "buffer": {
"version": "5.4.3", "version": "5.4.3",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz",
@ -2900,6 +2912,97 @@
"js-sha3": "^0.5.7" "js-sha3": "^0.5.7"
} }
}, },
"eth-json-rpc-errors": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-1.1.1.tgz",
"integrity": "sha512-WT5shJ5KfNqHi9jOZD+ID8I1kuYWNrigtZat7GOQkvwo99f8SzAVaEcWhJUv656WiZOAg3P1RiJQANtUmDmbIg==",
"dev": true,
"requires": {
"fast-safe-stringify": "^2.0.6"
}
},
"eth-json-rpc-filters": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/eth-json-rpc-filters/-/eth-json-rpc-filters-4.1.1.tgz",
"integrity": "sha512-GkXb2h6STznD+AmMzblwXgm1JMvjdK9PTIXG7BvIkTlXQ9g0QOxuU1iQRYHoslF9S30BYBSoLSisAYPdLggW+A==",
"dev": true,
"requires": {
"await-semaphore": "^0.1.3",
"eth-json-rpc-middleware": "^4.1.4",
"eth-query": "^2.1.2",
"json-rpc-engine": "^5.1.3",
"lodash.flatmap": "^4.5.0",
"safe-event-emitter": "^1.0.1"
},
"dependencies": {
"eth-json-rpc-middleware": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.1.tgz",
"integrity": "sha512-yoSuRgEYYGFdVeZg3poWOwAlRI+MoBIltmOB86MtpoZjvLbou9EB/qWMOWSmH2ryCWLW97VYY6NWsmWm3OAA7A==",
"dev": true,
"requires": {
"btoa": "^1.2.1",
"clone": "^2.1.1",
"eth-json-rpc-errors": "^1.0.1",
"eth-query": "^2.1.2",
"eth-sig-util": "^1.4.2",
"ethereumjs-block": "^1.6.0",
"ethereumjs-tx": "^1.3.7",
"ethereumjs-util": "^5.1.2",
"ethereumjs-vm": "^2.6.0",
"fetch-ponyfill": "^4.0.0",
"json-rpc-engine": "^5.1.3",
"json-stable-stringify": "^1.0.1",
"pify": "^3.0.0",
"safe-event-emitter": "^1.0.1"
}
},
"ethereumjs-util": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz",
"integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==",
"dev": true,
"requires": {
"bn.js": "^4.11.0",
"create-hash": "^1.1.2",
"ethjs-util": "^0.1.3",
"keccak": "^1.0.2",
"rlp": "^2.0.0",
"safe-buffer": "^5.1.1",
"secp256k1": "^3.0.1"
}
},
"json-rpc-engine": {
"version": "5.1.8",
"resolved": "https://registry.npmjs.org/json-rpc-engine/-/json-rpc-engine-5.1.8.tgz",
"integrity": "sha512-vTBSDEPJV1fPAsbm2g5sEuPjsgLdiab2f1CTn2PyRr8nxggUpA996PDlNQDsM0gnrA99F8KIBLq2nIKrOFl1Mg==",
"dev": true,
"requires": {
"async": "^2.0.1",
"eth-json-rpc-errors": "^2.0.1",
"promise-to-callback": "^1.0.0",
"safe-event-emitter": "^1.0.1"
},
"dependencies": {
"eth-json-rpc-errors": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-2.0.2.tgz",
"integrity": "sha512-uBCRM2w2ewusRHGxN8JhcuOb2RN3ueAOYH/0BhqdFmQkZx5lj5+fLKTz0mIVOzd4FG5/kUksCzCD7eTEim6gaA==",
"dev": true,
"requires": {
"fast-safe-stringify": "^2.0.6"
}
}
}
},
"pify": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=",
"dev": true
}
}
},
"eth-json-rpc-infura": { "eth-json-rpc-infura": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/eth-json-rpc-infura/-/eth-json-rpc-infura-3.2.1.tgz", "resolved": "https://registry.npmjs.org/eth-json-rpc-infura/-/eth-json-rpc-infura-3.2.1.tgz",
@ -3532,6 +3635,12 @@
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
"dev": true "dev": true
}, },
"fast-safe-stringify": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz",
"integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==",
"dev": true
},
"fd-slicer": { "fd-slicer": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
@ -5156,6 +5265,12 @@
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=", "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=",
"dev": true "dev": true
}, },
"lodash.flatmap": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.flatmap/-/lodash.flatmap-4.5.0.tgz",
"integrity": "sha1-74y/QI9uSCaGYzRTBcaswLd4cC4=",
"dev": true
},
"loose-envify": { "loose-envify": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
@ -8716,8 +8831,10 @@
"backoff": "^2.5.0", "backoff": "^2.5.0",
"clone": "^2.0.0", "clone": "^2.0.0",
"cross-fetch": "^2.1.0", "cross-fetch": "^2.1.0",
"eth-block-tracker": "^3.0.0", "eth-block-tracker": "^4.2.0",
"eth-json-rpc-filters": "^4.0.2",
"eth-json-rpc-infura": "^3.1.0", "eth-json-rpc-infura": "^3.1.0",
"eth-json-rpc-middleware": "^4.1.1",
"eth-sig-util": "^1.4.2", "eth-sig-util": "^1.4.2",
"ethereumjs-block": "^1.2.2", "ethereumjs-block": "^1.2.2",
"ethereumjs-tx": "^1.2.0", "ethereumjs-tx": "^1.2.0",
@ -8734,6 +8851,28 @@
"xtend": "^4.0.1" "xtend": "^4.0.1"
}, },
"dependencies": { "dependencies": {
"eth-json-rpc-middleware": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.1.tgz",
"integrity": "sha512-yoSuRgEYYGFdVeZg3poWOwAlRI+MoBIltmOB86MtpoZjvLbou9EB/qWMOWSmH2ryCWLW97VYY6NWsmWm3OAA7A==",
"dev": true,
"requires": {
"btoa": "^1.2.1",
"clone": "^2.1.1",
"eth-json-rpc-errors": "^1.0.1",
"eth-query": "^2.1.2",
"eth-sig-util": "^1.4.2",
"ethereumjs-block": "^1.6.0",
"ethereumjs-tx": "^1.3.7",
"ethereumjs-util": "^5.1.2",
"ethereumjs-vm": "^2.6.0",
"fetch-ponyfill": "^4.0.0",
"json-rpc-engine": "^5.1.3",
"json-stable-stringify": "^1.0.1",
"pify": "^3.0.0",
"safe-event-emitter": "^1.0.1"
}
},
"ethereumjs-util": { "ethereumjs-util": {
"version": "5.2.0", "version": "5.2.0",
"resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz",
@ -8749,6 +8888,35 @@
"secp256k1": "^3.0.1" "secp256k1": "^3.0.1"
} }
}, },
"json-rpc-engine": {
"version": "5.1.8",
"resolved": "https://registry.npmjs.org/json-rpc-engine/-/json-rpc-engine-5.1.8.tgz",
"integrity": "sha512-vTBSDEPJV1fPAsbm2g5sEuPjsgLdiab2f1CTn2PyRr8nxggUpA996PDlNQDsM0gnrA99F8KIBLq2nIKrOFl1Mg==",
"dev": true,
"requires": {
"async": "^2.0.1",
"eth-json-rpc-errors": "^2.0.1",
"promise-to-callback": "^1.0.0",
"safe-event-emitter": "^1.0.1"
},
"dependencies": {
"eth-json-rpc-errors": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-2.0.2.tgz",
"integrity": "sha512-uBCRM2w2ewusRHGxN8JhcuOb2RN3ueAOYH/0BhqdFmQkZx5lj5+fLKTz0mIVOzd4FG5/kUksCzCD7eTEim6gaA==",
"dev": true,
"requires": {
"fast-safe-stringify": "^2.0.6"
}
}
}
},
"pify": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=",
"dev": true
},
"readable-stream": { "readable-stream": {
"version": "2.3.7", "version": "2.3.7",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",

View File

@ -60,7 +60,7 @@
"yargs": "^15.0.0" "yargs": "^15.0.0"
}, },
"dependencies": { "dependencies": {
"ethers": "^4.0.47", "ethers": "^5.0.2",
"ipfs-http-client": "^41.0.1", "ipfs-http-client": "^41.0.1",
"kosmos-schemas": "^2.2.1", "kosmos-schemas": "^2.2.1",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",

View File

@ -19,10 +19,10 @@ module.exports = async function(callback) {
let contributorAccount; let contributorAccount;
if (contributor.length < 5) { if (contributor.length < 5) {
contributorId = contributor; contributorId = contributor;
contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor); contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor);
} else { } else {
contributorAccount = contributor; contributorAccount = contributor;
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor); contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor);
} }
console.log(`Creating a contribution for contributor account ${contributorAccount} ID: ${contributorId}`); console.log(`Creating a contribution for contributor account ${contributorAccount} ID: ${contributorId}`);
@ -45,7 +45,7 @@ module.exports = async function(callback) {
console.log("\nAdding contribution:"); console.log("\nAdding contribution:");
console.log(contributionAttributes); console.log(contributionAttributes);
kredits.Contribution.addContribution(contributionAttributes, { gasLimit: 300000 }) kredits.Contribution.add(contributionAttributes, { gasLimit: 300000 })
.then(result => { .then(result => {
console.log("\n\nResult:"); console.log("\n\nResult:");
console.log(result); console.log(result);

View File

@ -19,10 +19,10 @@ module.exports = async function(callback) {
let contributorAccount; let contributorAccount;
if (contributor.length < 5) { if (contributor.length < 5) {
contributorId = contributor; contributorId = contributor;
contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor); contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor);
} else { } else {
contributorAccount = contributor; contributorAccount = contributor;
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor); contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor);
} }
console.log(`Creating a proposal for contributor ID #${contributorId} account: ${contributorAccount}`); console.log(`Creating a proposal for contributor ID #${contributorId} account: ${contributorAccount}`);

View File

@ -31,7 +31,7 @@ module.exports = async function(callback) {
if (c.contributorId === recipient && confirmed && !c.vetoed && !c.claimed) { if (c.contributorId === recipient && confirmed && !c.vetoed && !c.claimed) {
console.log(`Claiming contribution ID=${c.id}`); console.log(`Claiming contribution ID=${c.id}`);
return kredits.Contribution.functions.claim(c.id, { gasLimit: 500000 }).then(tx => { return kredits.Contribution.contract.claim(c.id, { gasLimit: 500000 }).then(tx => {
table.push([ table.push([
c.id.toString(), c.id.toString(),
`${c.description}`, `${c.description}`,

View File

@ -17,7 +17,7 @@ module.exports = async function(callback) {
method = await promptly.prompt('Function: '); method = await promptly.prompt('Function: ');
} }
if (!contractWrapper[method] && !contractWrapper.functions[method]) { if (!contractWrapper[method] && !contractWrapper.contract[method]) {
callback(new Error(`Method ${method} is not defined on ${contractName}`)); callback(new Error(`Method ${method} is not defined on ${contractName}`));
return; return;
} }
@ -33,7 +33,7 @@ module.exports = async function(callback) {
if (contractWrapper[method]) { if (contractWrapper[method]) {
func = contractWrapper[method]; func = contractWrapper[method];
} else { } else {
func = contractWrapper.functions[method]; func = contractWrapper.contract[method];
} }
func.apply(contractWrapper, args).then((result) => { func.apply(contractWrapper, args).then((result) => {
console.log("\nResult:"); console.log("\nResult:");

View File

@ -1,9 +1,12 @@
const knownDAOAddresses = require('../lib/addresses/dao.json'); const knownDAOAddresses = require('../lib/addresses/dao.json');
const knownKreditsKitAddresses = require('../lib/addresses/KreditsKit.json'); const knownKreditsKitAddresses = require('../lib/addresses/KreditsKit.json');
const getNetworkId = require('./helpers/networkid.js') const getNetworkId = require('./helpers/networkid.js')
const ethers = require('ethers');
module.exports = async function(callback) { module.exports = async function(callback) {
const networkId = await getNetworkId(web3) const provider = new ethers.providers.Web3Provider(web3.currentProvider);
let network = await provider.getNetwork();
let networkId = network.chainId;
console.log('# All known DAO addresses'); console.log('# All known DAO addresses');
Object.keys(knownDAOAddresses).forEach((networkId) => { Object.keys(knownDAOAddresses).forEach((networkId) => {

View File

@ -3,10 +3,10 @@ const deployDAOFactory = require('@aragon/os/scripts/deploy-daofactory.js')
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const argv = require('yargs').argv const argv = require('yargs').argv
const namehash = require('ethers').utils.namehash; const ethers = require('ethers');
const namehash = ethers.utils.namehash;
const fileInject = require('./helpers/file_inject.js') const fileInject = require('./helpers/file_inject.js')
const getNetworkId = require('./helpers/networkid.js')
const DAOFactory = artifacts.require('DAOFactory') const DAOFactory = artifacts.require('DAOFactory')
const KreditsKit = artifacts.require('KreditsKit') const KreditsKit = artifacts.require('KreditsKit')
@ -26,9 +26,10 @@ const daoFactoryAddress = kreditsArappConfig.daoFactory || argv['daoFactory']
const ensAddr = arapp.environments[environment].registry || argv['ensAddress'] const ensAddr = arapp.environments[environment].registry || argv['ensAddress']
module.exports = async function(callback) { module.exports = async function(callback) {
const networkId = await getNetworkId(web3) const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const network = await provider.getNetwork();
const networkId = network.chainId;
console.log(`Deploying to networkId: ${networkId}`) console.log(`Deploying to networkId: ${networkId}`)
if (!ensAddr) { if (!ensAddr) {

View File

@ -1,6 +1,5 @@
const argv = require('yargs').argv; const argv = require('yargs').argv;
const ethers = require('ethers'); const ethers = require('ethers');
const getNetworkId = require('./networkid.js');
const Kredits = require('../../lib/kredits'); const Kredits = require('../../lib/kredits');
const arapp = require('../../arapp.json'); const arapp = require('../../arapp.json');
@ -10,7 +9,7 @@ const apm = arapp.environments[environment].apm;
module.exports = async function(web3) { module.exports = async function(web3) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const provider = new ethers.providers.Web3Provider(web3.currentProvider); const provider = new ethers.providers.Web3Provider(web3.currentProvider);
let signer = provider.getSigner(); const signer = provider.getSigner();
// checking if siner supports signing transactions // checking if siner supports signing transactions
signer.getAddress().then(_ => { signer.getAddress().then(_ => {
new Kredits(provider, signer, { apm }).init().then(kredits => { new Kredits(provider, signer, { apm }).init().then(kredits => {

View File

@ -1,17 +0,0 @@
module.exports = function(web3) {
return new Promise((resolve, reject) => {
let func;
if (web3.version.getNetwork) {
func = web3.version.getNetwork;
} else {
func = web3.eth.net.getId;
}
func((err, network) => {
if (err) {
reject(err);
} else {
resolve(network);
}
})
})
}

View File

@ -1,12 +1,14 @@
const fs = require('fs'); const fs = require('fs');
const getNetworkId = require('./networkid.js'); const ethers = require('ethers');
module.exports = async function(callback) { module.exports = async function(callback) {
const daoAddressPath = 'lib/addresses/dao.json'; const daoAddressPath = 'lib/addresses/dao.json';
// TODO maybe do the same for KreditsKit address file // TODO maybe do the same for KreditsKit address file
try { try {
const networkId = await getNetworkId(web3); const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const network = await provider.getNetwork();
const networkId = network.chainId;
const daoAddresses = JSON.parse(fs.readFileSync(daoAddressPath)); const daoAddresses = JSON.parse(fs.readFileSync(daoAddressPath));
const oldNetworkId = Math.max(...Object.keys(daoAddresses).map(a => parseInt(a))); const oldNetworkId = Math.max(...Object.keys(daoAddresses).map(a => parseInt(a)));
const localDaoAddress = daoAddresses[oldNetworkId]; const localDaoAddress = daoAddresses[oldNetworkId];

View File

@ -41,8 +41,8 @@ module.exports = async function(callback) {
console.log(table.toString()); console.log(table.toString());
let totalKreditsEarnedUnConfirmed = await kredits.Contribution.functions.totalKreditsEarned(false); let totalKreditsEarnedUnConfirmed = await kredits.Contribution.contract.totalKreditsEarned(false);
let totalKreditsEarnedConfirmed = await kredits.Contribution.functions.totalKreditsEarned(true); let totalKreditsEarnedConfirmed = await kredits.Contribution.contract.totalKreditsEarned(true);
console.log(`Total Kredits: ${totalKreditsEarnedConfirmed} (confirmed) | ${totalKreditsEarnedUnConfirmed} (including unconfirmed)`); console.log(`Total Kredits: ${totalKreditsEarnedConfirmed} (confirmed) | ${totalKreditsEarnedUnConfirmed} (including unconfirmed)`);
} catch (err) { } catch (err) {
console.log(err); console.log(err);

View File

@ -3,13 +3,15 @@ const path = require('path');
const ethers = require('ethers'); const ethers = require('ethers');
const fileInject = require('./helpers/file_inject.js'); const fileInject = require('./helpers/file_inject.js');
const getNetworkId = require('./helpers/networkid.js');
const KreditsKit = require('../lib/kreditskit'); const KreditsKit = require('../lib/kreditskit');
const addressesPath = path.join(__dirname, '..', 'lib/addresses'); const addressesPath = path.join(__dirname, '..', 'lib/addresses');
module.exports = async function(callback) { module.exports = async function(callback) {
const networkId = await getNetworkId(web3) const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const signer = provider.getSigner();
const network = await provider.getNetwork();
const networkId = network.chainId;
console.log(`Deploying to networkId: ${networkId}`) console.log(`Deploying to networkId: ${networkId}`)
let kitAddresseFile = path.join(addressesPath, 'KreditsKit.json'); let kitAddresseFile = path.join(addressesPath, 'KreditsKit.json');
@ -20,9 +22,6 @@ module.exports = async function(callback) {
} }
console.log(`Using KreditsKit at: ${kreditsKitAddress}`); console.log(`Using KreditsKit at: ${kreditsKitAddress}`);
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
let signer = provider.getSigner();
let kit = await new KreditsKit(provider, signer).init() let kit = await new KreditsKit(provider, signer).init()
// TODO: get rid of the hard coded gas limit // TODO: get rid of the hard coded gas limit

View File

@ -38,7 +38,7 @@ module.exports = async function(callback) {
if (contractWrapper[method]) { if (contractWrapper[method]) {
func = contractWrapper[method]; func = contractWrapper[method];
} else { } else {
func = contractWrapper.functions[method]; func = contractWrapper.contract[method];
} }
func.apply(contractWrapper, args).then((result) => { func.apply(contractWrapper, args).then((result) => {
console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`); console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`);

View File

@ -15,7 +15,7 @@ module.exports = async function(callback) {
console.log(`Recording a veto for contribution #${contributionId}`); console.log(`Recording a veto for contribution #${contributionId}`);
try { try {
kredits.Contribution.functions.veto(contributionId, { gasLimit: 300000 }) kredits.Contribution.contract.veto(contributionId, { gasLimit: 300000 })
.then(result => { .then(result => {
console.log("\n\nResult:"); console.log("\n\nResult:");
console.log(result); console.log(result);