Merge branch 'master' into tests/contracts-contributor

This commit is contained in:
haythem 2019-07-10 10:18:23 +01:00
commit d206d55b7d
5 changed files with 783 additions and 110 deletions

View File

@ -14,6 +14,10 @@ class Contribution extends Record {
}); });
} }
getData (id) {
return this.functions.getContribution(id);
}
getByContributorId (contributorId) { getByContributorId (contributorId) {
return this.functions.getContributorAddressById(contributorId) return this.functions.getContributorAddressById(contributorId)
.then(address => this.getByContributorAddress(address)); .then(address => this.getByContributorAddress(address));
@ -62,6 +66,7 @@ class Contribution extends Record {
deprecate('The function `addContribution()` is deprecated and will be removed in the next major version. Use `add()` instead'); deprecate('The function `addContribution()` is deprecated and will be removed in the next major version. Use `add()` instead');
return this.add(...arguments); return this.add(...arguments);
} }
} }
module.exports = Contribution; module.exports = Contribution;

View File

@ -15,6 +15,10 @@ class Contributor extends Record {
}); });
} }
getData (id) {
return this.functions.getContributorById(id);
}
filterByAccount (search) { filterByAccount (search) {
return this._byAccount(search, 'filter'); return this._byAccount(search, 'filter');
} }
@ -84,6 +88,7 @@ class Contributor extends Record {
}); });
}); });
} }
} }
module.exports = Contributor; module.exports = Contributor;

View File

@ -1,13 +1,14 @@
const ipfsClient = require('ipfs-http-client'); const ipfsClient = require('ipfs-http-client');
const multihashes = require('multihashes'); const multihashes = require('multihashes');
const fetch = require('node-fetch');
class IPFS { class IPFS {
constructor (config) { constructor (config) {
if (!config) { if (!config) {
config = { host: 'localhost', port: '5001', protocol: 'http' }; config = { host: 'localhost', port: '5001', protocol: 'http' };
} }
this._ipfsAPI = ipfsClient(config);
this._config = config; this._config = config;
this._ipfsAPI = ipfsClient(config);
} }
catAndMerge (data, deserialize) { catAndMerge (data, deserialize) {
@ -38,8 +39,20 @@ class IPFS {
if (hashData.hasOwnProperty('hashSize')) { if (hashData.hasOwnProperty('hashSize')) {
ipfsHash = this.encodeHash(hashData); ipfsHash = this.encodeHash(hashData);
} }
if (this._config['gatewayUrl']) {
return fetch(`${this._config['gatewayUrl']}/${ipfsHash}`).then(r => r.text());
} else {
return this._ipfsAPI.cat(ipfsHash); return this._ipfsAPI.cat(ipfsHash);
} }
}
pin (hashData) {
let ipfsHash = hashData; // default - if it is a string
if (hashData.hasOwnProperty('hashSize')) {
ipfsHash = this.encodeHash(hashData);
}
return this._ipfsAPI.pin.add(multihashes.toB58String(ipfsHash));
}
decodeHash (ipfsHash) { decodeHash (ipfsHash) {
let multihash = multihashes.decode(multihashes.fromB58String(ipfsHash)); let multihash = multihashes.decode(multihashes.fromB58String(ipfsHash));

857
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "kredits-contracts", "name": "kredits-contracts",
"version": "5.3.0", "version": "5.4.0",
"description": "Ethereum contracts and npm wrapper for Kredits", "description": "Ethereum contracts and npm wrapper for Kredits",
"main": "./lib/kredits.js", "main": "./lib/kredits.js",
"directories": { "directories": {
@ -12,7 +12,7 @@
"build-json": "npm run compile-contracts && node ./scripts/build-json.js", "build-json": "npm run compile-contracts && node ./scripts/build-json.js",
"repl": "truffle exec scripts/repl.js", "repl": "truffle exec scripts/repl.js",
"seeds": "truffle exec scripts/seeds.js", "seeds": "truffle exec scripts/seeds.js",
"compile-contracts": "aragon contracts compile --all", "compile-contracts": "truffle compile --all",
"bootstrap": "npm run reset:hard && npm run seeds", "bootstrap": "npm run reset:hard && npm run seeds",
"reset": "npm run deploy:kit && npm run deploy:dao", "reset": "npm run deploy:kit && npm run deploy:dao",
"reset:hard": "npm run deploy:apps && npm run reset", "reset:hard": "npm run deploy:apps && npm run reset",
@ -59,8 +59,9 @@
}, },
"dependencies": { "dependencies": {
"ethers": "^4.0.29", "ethers": "^4.0.29",
"ipfs-http-client": "^32.0.1", "ipfs-http-client": "^30.1.3",
"kosmos-schemas": "^2.1.0", "kosmos-schemas": "^2.1.0",
"node-fetch": "^2.6.0",
"tv4": "^1.3.0" "tv4": "^1.3.0"
}, },
"keywords": [ "keywords": [