chore: migrate ipfs-api to ipfs-http-client

This commit is contained in:
Andre Medeiros 2019-05-30 16:32:55 -04:00
parent 3c9ed4183d
commit e07dc09b53
15 changed files with 469 additions and 257 deletions

View File

@ -11,7 +11,7 @@
"versions": { "versions": {
"web3": "1.0.0-beta", "web3": "1.0.0-beta",
"solc": "0.5.0", "solc": "0.5.0",
"ipfs-api": "17.2.4" "ipfs-http-client": "32.0.1"
}, },
"plugins": { "plugins": {
"embarkjs-connector-web3": {} "embarkjs-connector-web3": {}

View File

@ -161,7 +161,7 @@ class Storage extends React.Component {
!this.props.enabled ? !this.props.enabled ?
<React.Fragment> <React.Fragment>
<Alert bsStyle="warning">The node you are using does not support IPFS. Please ensure <a <Alert bsStyle="warning">The node you are using does not support IPFS. Please ensure <a
href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS href="https://github.com/ipfs/js-ipfs-http-client#cors" target="_blank">CORS</a> is setup for the IPFS
node.</Alert> node.</Alert>
</React.Fragment> : '' </React.Fragment> : ''
} }

View File

@ -11,7 +11,7 @@
"versions": { "versions": {
"web3": "1.0.0-beta", "web3": "1.0.0-beta",
"solc": "0.5.0", "solc": "0.5.0",
"ipfs-api": "17.2.4" "ipfs-http-client": "32.0.1"
}, },
"plugins": { "plugins": {
"embarkjs-connector-web3": {} "embarkjs-connector-web3": {}

View File

@ -42,7 +42,7 @@
</div> </div>
</div> </div>
<div role="tabpanel" class="tab-pane" id="storage"> <div role="tabpanel" class="tab-pane" id="storage">
<div class="error alert alert-danger" role="alert">The node you are using does not support IPFS. Please ensure <a href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS node.</div> <div class="error alert alert-danger" role="alert">The node you are using does not support IPFS. Please ensure <a href="https://github.com/ipfs/js-ipfs-http-client#cors" target="_blank">CORS</a> is setup for the IPFS node.</div>
<div id="storage-controls"> <div id="storage-controls">
<h3>Save text to IPFS</h3> <h3>Save text to IPFS</h3>

View File

@ -17,7 +17,7 @@
"versions": { "versions": {
"solc": "0.4.25", "solc": "0.4.25",
"web3": "1.0.0-beta", "web3": "1.0.0-beta",
"ipfs-api": "17.2.7" "ipfs-http-client": "32.0.1"
}, },
"plugins": { "plugins": {
"embark-dapp-test-service": {}, "embark-dapp-test-service": {},

View File

@ -40,7 +40,7 @@ class VM {
"eth-ens-namehash", "eth-ens-namehash",
"swarm-api", "swarm-api",
"embarkjs-whisper", "embarkjs-whisper",
"ipfs-api", "ipfs-http-client",
"embarkjs-ipfs", "embarkjs-ipfs",
"embarkjs-swarm", "embarkjs-swarm",
"rxjs", "rxjs",

View File

@ -2,10 +2,15 @@ import { __ } from 'embark-i18n';
import { dappPath, embarkPath } from 'embark-utils'; import { dappPath, embarkPath } from 'embark-utils';
var Npm = require('./npm.js'); var Npm = require('./npm.js');
const DEPRECATIONS = {
'ipfs-api': 'ipfs-http-client'
};
class LibraryManager { class LibraryManager {
constructor(embark, {useDashboard}) { constructor(embark, {useDashboard}) {
this.embark = embark; this.embark = embark;
this.logger = embark.logger;
this.config = embark.config; this.config = embark.config;
this.contractsConfig = this.config.contractsConfig; this.contractsConfig = this.config.contractsConfig;
this.storageConfig = this.config.storageConfig; this.storageConfig = this.config.storageConfig;
@ -24,11 +29,11 @@ class LibraryManager {
let solcVersionInConfig = this.contractsConfig.versions.solc; let solcVersionInConfig = this.contractsConfig.versions.solc;
let web3VersionInConfig = this.contractsConfig.versions["web3"]; let web3VersionInConfig = this.contractsConfig.versions["web3"];
let ipfsApiVersion = this.storageConfig.versions["ipfs-api"]; let ipfsHttpClientVersion = this.storageConfig.versions["ipfs-http-client"];
this.versions['solc'] = solcVersionInConfig; this.versions['solc'] = solcVersionInConfig;
this.versions['web3'] = web3VersionInConfig; this.versions['web3'] = web3VersionInConfig;
this.versions['ipfs-api'] = ipfsApiVersion; this.versions['ipfs-http-client'] = ipfsHttpClientVersion;
Object.keys(this.versions).forEach(versionKey => { Object.keys(this.versions).forEach(versionKey => {
const newVersion = this.versions[versionKey].trim(); const newVersion = this.versions[versionKey].trim();
@ -78,6 +83,14 @@ class LibraryManager {
cb(lib); cb(lib);
}); });
} }
for(let oldLib in DEPRECATIONS) {
let replacement = DEPRECATIONS[oldLib];
this.embark.events.setCommandHandler('version:get:' + oldLib, (cb) => {
self.logger.warn(`${oldLib} has been deprecated in favor of ${replacement}. This will be used instead.`);
self.embark.events.request(`version:get:${replacement}`, cb);
});
}
} }
downloadIfNeeded(packageName, cb) { downloadIfNeeded(packageName, cb) {
@ -95,14 +108,27 @@ class LibraryManager {
} }
listenToCommandsToGetLibrary() { listenToCommandsToGetLibrary() {
const self = this;
let npm = new Npm({logger: this.embark.logger, useDashboard: this.useDashboard}); let npm = new Npm({logger: this.embark.logger, useDashboard: this.useDashboard});
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => { this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
if(DEPRECATIONS[libName]) {
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
libName = DEPRECATIONS[libName];
}
npm.getPackageVersion(libName, version, cb); npm.getPackageVersion(libName, version, cb);
}); });
this.embark.events.setCommandHandler('version:downloadIfNeeded', (libName, cb) => { this.embark.events.setCommandHandler('version:downloadIfNeeded', (libName, cb) => {
if(DEPRECATIONS[libName]) {
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
libName = DEPRECATIONS[libName];
}
this.downloadIfNeeded(libName, cb); this.downloadIfNeeded(libName, cb);
}); });
this.embark.events.setCommandHandler('version:getPackagePath', (libName, version, cb) => { this.embark.events.setCommandHandler('version:getPackagePath', (libName, version, cb) => {
if(DEPRECATIONS[libName]) {
self.logger.warn(`${libName} has been deprecated in favor of ${DEPRECATIONS[libName]}. This will be used instead.`);
libName = DEPRECATIONS[libName];
}
cb(null, Npm.getPackagePath(libName, version)); cb(null, Npm.getPackagePath(libName, version));
}); });
} }

View File

@ -149,7 +149,7 @@
"hosted-git-info": "2.7.1", "hosted-git-info": "2.7.1",
"http-proxy": "1.17.0", "http-proxy": "1.17.0",
"http-shutdown": "1.2.0", "http-shutdown": "1.2.0",
"ipfs-api": "17.2.4", "ipfs-http-client": "32.0.1",
"istanbul": "0.4.5", "istanbul": "0.4.5",
"json-parse-better-errors": "1.0.2", "json-parse-better-errors": "1.0.2",
"live-plugin-manager-git-fix": "0.12.1", "live-plugin-manager-git-fix": "0.12.1",

View File

@ -435,7 +435,7 @@ Config.prototype.loadExternalContractsFiles = function() {
}; };
Config.prototype.loadStorageConfigFile = function() { Config.prototype.loadStorageConfigFile = function() {
var versions = recursiveMerge({"ipfs-api": "17.2.4"}, this.embarkConfig.versions || {}); var versions = recursiveMerge({ "ipfs-http-client": "32.0.1" }, this.embarkConfig.versions || {});
var configObject = { var configObject = {
"default": { "default": {

View File

@ -1,7 +1,7 @@
import { __ } from 'embark-i18n'; import { __ } from 'embark-i18n';
const UploadIPFS = require('./upload.js'); const UploadIPFS = require('./upload.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const IpfsApi = require('ipfs-api'); const IPFSHTTPClient = require('ipfs-http-client');
// TODO: not great, breaks module isolation // TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher'); const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
const constants = require('embark-core/constants'); const constants = require('embark-core/constants');
@ -64,15 +64,15 @@ class IPFS {
}); });
} }
downloadIpfsApi(cb) { downloadIPFSHTTPClient(cb) {
this.events.request("version:get:ipfs-api", (ipfsApiVersion) => { this.events.request("version:get:ipfs-http-client", (ipfsApiVersion) => {
let currentIpfsApiVersion = require('../../../../package.json').dependencies["ipfs-api"]; let currentIPFSHTTPClientVersion = require('../../../../package.json').dependencies["ipfs-http-client"];
if (ipfsApiVersion === currentIpfsApiVersion) { if (ipfsApiVersion === currentIPFSHTTPClientVersion) {
const nodePath = embarkPath('node_modules'); const nodePath = embarkPath('node_modules');
const ipfsPath = require.resolve("ipfs-api", {paths: [nodePath]}); const ipfsPath = require.resolve("ipfs-http-client", {paths: [nodePath]});
return cb(null, ipfsPath); return cb(null, ipfsPath);
} }
this.events.request("version:getPackageLocation", "ipfs-api", ipfsApiVersion, (err, location) => { this.events.request("version:getPackageLocation", "ipfs-http-client", ipfsApiVersion, (err, location) => {
cb(err, dappPath(location)); cb(err, dappPath(location));
}); });
}); });
@ -131,19 +131,19 @@ class IPFS {
addStorageProviderToEmbarkJS() { addStorageProviderToEmbarkJS() {
if(this.addedToEmbarkJs) return; if(this.addedToEmbarkJs) return;
this.addedToEmbarkJs = true; this.addedToEmbarkJs = true;
this.events.request('version:downloadIfNeeded', 'ipfs-api', (err, location) => { this.events.request('version:downloadIfNeeded', 'ipfs-http-client', (err, location) => {
if (err) { if (err) {
this.logger.error(__('Error downloading IPFS API')); this.logger.error(__('Error downloading IPFS API'));
return this.logger.error(err.message || err); return this.logger.error(err.message || err);
} }
this.events.request('code-generator:ready', () => { this.events.request('code-generator:ready', () => {
this.events.request('code-generator:symlink:generate', location, 'ipfs-api', (err, _symlinkDest) => { this.events.request('code-generator:symlink:generate', location, 'ipfs-http-client', (err, _symlinkDest) => {
if (err) { if (err) {
this.logger.error(__('Error creating a symlink to IPFS API')); this.logger.error(__('Error creating a symlink to IPFS API'));
return this.logger.error(err.message || err); return this.logger.error(err.message || err);
} }
this.events.emit('runcode:register', 'IpfsApi', require('ipfs-api'), () => { this.events.emit('runcode:register', 'IPFSHTTPClient', require('ipfs-http-client'), () => {
let code = ""; let code = "";
code += "\nconst __embarkIPFS = require('embarkjs-ipfs')"; code += "\nconst __embarkIPFS = require('embarkjs-ipfs')";
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);"; code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);";
@ -161,7 +161,7 @@ class IPFS {
this.addedToConsole = true; this.addedToConsole = true;
const {host, port} = this._getNodeUrlConfig(); const {host, port} = this._getNodeUrlConfig();
let ipfs = IpfsApi(host, port); let ipfs = IPFSHTTPClient(host, port);
this.events.emit("runcode:register", "ipfs", ipfs); this.events.emit("runcode:register", "ipfs", ipfs);
} }

View File

@ -51,7 +51,7 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime-corejs2": "7.3.1", "@babel/runtime-corejs2": "7.3.1",
"ipfs-api": "17.2.4" "ipfs-http-client": "32.0.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "7.2.3", "@babel/cli": "7.2.3",

View File

@ -1,4 +1,4 @@
const IpfsApi = require('ipfs-api'); const IPFSHTTPClient = require('ipfs-http-client');
const __embarkIPFS = {}; const __embarkIPFS = {};
@ -10,7 +10,7 @@ __embarkIPFS.setProvider = function (options) {
try { try {
if (!options) { if (!options) {
self._config = options; self._config = options;
self._ipfsConnection = IpfsApi('localhost', '5001'); self._ipfsConnection = IPFSHTTPClient('localhost', '5001');
self._getUrl = "http://localhost:8080/ipfs/"; self._getUrl = "http://localhost:8080/ipfs/";
} else { } else {
const ipfsOptions = {host: options.host || options.server, protocol: 'http'}; const ipfsOptions = {host: options.host || options.server, protocol: 'http'};
@ -20,7 +20,7 @@ __embarkIPFS.setProvider = function (options) {
if (options.port && options.port !== 'false') { if (options.port && options.port !== 'false') {
ipfsOptions.port = options.port; ipfsOptions.port = options.port;
} }
self._ipfsConnection = IpfsApi(ipfsOptions); self._ipfsConnection = IPFSHTTPClient(ipfsOptions);
self._getUrl = options.getUrl || "http://localhost:8080/ipfs/"; self._getUrl = options.getUrl || "http://localhost:8080/ipfs/";
} }
resolve(self); resolve(self);
@ -54,7 +54,7 @@ __embarkIPFS.saveText = function (text) {
if (!self._ipfsConnection) { if (!self._ipfsConnection) {
return reject(new Error(NoConnectionError)); return reject(new Error(NoConnectionError));
} }
self._ipfsConnection.add(self._ipfsConnection.Buffer.from(text), function (err, result) { self._ipfsConnection.add(IPFSHTTPClient.Buffer.from(text), function (err, result) {
if (err) { if (err) {
return reject(err); return reject(err);
} }
@ -96,7 +96,7 @@ __embarkIPFS.uploadFile = function (inputSelector) {
} }
const reader = new FileReader(); const reader = new FileReader();
reader.onloadend = function () { reader.onloadend = function () {
const buffer = self._ipfsConnection.Buffer.from(reader.result); const buffer = IPFSHTTPClient.Buffer.from(reader.result);
self._ipfsConnection.add(buffer, function (err, result) { self._ipfsConnection.add(buffer, function (err, result) {
if (err) { if (err) {
return reject(err); return reject(err);

View File

@ -24,7 +24,7 @@ Every application [created with Embark](create_project.html) comes with an `emba
"versions": { "versions": {
"web3": "1.0.0-beta", "web3": "1.0.0-beta",
"solc": "0.4.25", "solc": "0.4.25",
"ipfs-api": "17.2.4" "ipfs-http-client": "32.0.1"
}, },
"plugins": { "plugins": {
}, },

View File

@ -27,7 +27,7 @@ module.exports = {
{"provider": "ipfs", "host": "localhost", "port": 5001, "getUrl": "http://localhost:8080/ipfs/"} {"provider": "ipfs", "host": "localhost", "port": 5001, "getUrl": "http://localhost:8080/ipfs/"}
], ],
"versions": { "versions": {
"ipfs-api": "17.2.4" "ipfs-http-client": "32.0.1"
} }
}, },
"development": { "development": {
@ -41,8 +41,8 @@ module.exports = {
The available options are: The available options are:
Option | Type: `default` | Value Option | Type: `default` | Value
--- | --- | --- --- | --- | ---
`enabled` | boolean: `true` | Enables or completely disables storage support `enabled` | boolean: `true` | Enables or completely disables storage support
`ipfs_bin` | string: `ipfs` | Name or desired path to the ipfs binary `ipfs_bin` | string: `ipfs` | Name or desired path to the ipfs binary
`available_providers` | array: `["ipfs", "swarm"]` | List of storages to be supported on the dapp. This will affect what's available with the EmbarkJS library on the dapp. `available_providers` | array: `["ipfs", "swarm"]` | List of storages to be supported on the dapp. This will affect what's available with the EmbarkJS library on the dapp.
@ -53,7 +53,7 @@ Option | Type: `default` | Value
`upload.port` | integer: `5001` | Port value used to interact with the storage provider for upload, i.e. `5001` (IPFS local node) or `8500` (Swarm local node) or `80` `upload.port` | integer: `5001` | Port value used to interact with the storage provider for upload, i.e. `5001` (IPFS local node) or `8500` (Swarm local node) or `80`
`upload.getUrl` | string: `http://localhost:8080/ipfs/` | Only for IPFS. This sets the file/document retrieval URL, which is different than the host/port combination used to interact with the IPFS API. `upload.getUrl` | string: `http://localhost:8080/ipfs/` | Only for IPFS. This sets the file/document retrieval URL, which is different than the host/port combination used to interact with the IPFS API.
`dappConnection` | | List of storage providers to attempt connection to in the dapp. Each provider process will be launched in a child process. Each connection listed will be tried in order on the dapp, until one is avaialable. Can also specify `$BZZ` to attempt to connect to an injected swarm object. `dappConnection` | | List of storage providers to attempt connection to in the dapp. Each provider process will be launched in a child process. Each connection listed will be tried in order on the dapp, until one is avaialable. Can also specify `$BZZ` to attempt to connect to an injected swarm object.
`dappConnection.provider` | string: `ipfs` | Desired provider to use for dapp storage. `dappConnection.provider` | string: `ipfs` | Desired provider to use for dapp storage.
`dappConnection.protocol` | string: `http` | Storage provider protocol used in the dapp, i.e. `http` or `https` `dappConnection.protocol` | string: `http` | Storage provider protocol used in the dapp, i.e. `http` or `https`
`dappConnection.host` | string | Host value used to interact with the storage provider in the dapp, i.e. `localhost` or `swarm-gateways.net` `dappConnection.host` | string | Host value used to interact with the storage provider in the dapp, i.e. `localhost` or `swarm-gateways.net`
`dappConnection.port` | integer | Port value used to interact with the storage provider in the dapp, i.e. `5001` (IPFS local node) or `8500` (Swarm local node) or `80`. Can specify `false` if a port should not be included in the connection URL (i.e. for a public gateway like `http://swarm-gateways.net`). `dappConnection.port` | integer | Port value used to interact with the storage provider in the dapp, i.e. `5001` (IPFS local node) or `8500` (Swarm local node) or `80`. Can specify `false` if a port should not be included in the connection URL (i.e. for a public gateway like `http://swarm-gateways.net`).

636
yarn.lock

File diff suppressed because it is too large Load Diff