Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dapps/templates/boilerplate/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"versions": {
"web3": "1.0.0-beta",
"solc": "0.5.0",
"ipfs-api": "17.2.4"
"ipfs-http-client": "32.0.1"
},
"plugins": {
"embarkjs-connector-web3": {}
Expand Down
2 changes: 1 addition & 1 deletion dapps/templates/demo/app/components/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Storage extends React.Component {
!this.props.enabled ?
<React.Fragment>
<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>
</React.Fragment> : ''
}
Expand Down
2 changes: 1 addition & 1 deletion dapps/templates/demo/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"versions": {
"web3": "1.0.0-beta",
"solc": "0.5.0",
"ipfs-api": "17.2.4"
"ipfs-http-client": "32.0.1"
},
"plugins": {
"embarkjs-connector-web3": {}
Expand Down
2 changes: 1 addition & 1 deletion dapps/tests/app/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3> 3. Contract Calls </h3>
</div>
</div>
<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">

<h3>Save text to IPFS</h3>
Expand Down
2 changes: 1 addition & 1 deletion dapps/tests/app/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"versions": {
"solc": "0.4.25",
"web3": "1.0.0-beta",
"ipfs-api": "17.2.7"
"ipfs-http-client": "32.0.1"
},
"plugins": {
"embark-dapp-test-service": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/embark-code-runner/src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class VM {
"eth-ens-namehash",
"swarm-api",
"embarkjs-whisper",
"ipfs-api",
"ipfs-http-client",
"embarkjs-ipfs",
"embarkjs-swarm",
"rxjs",
Expand Down
30 changes: 28 additions & 2 deletions packages/embark-library-manager/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { __ } from 'embark-i18n';
import { dappPath, embarkPath } from 'embark-utils';
var Npm = require('./npm.js');

const DEPRECATIONS = {
'ipfs-api': 'ipfs-http-client'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! As part of the deprecation logic do we need to pair this with a default version of ipfs-http-client to use in case ipfs-api is found in embark.json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question!

This will use the default version for the replacement, so it'll forward the call to version:get:ipfs-http-client. That version comes from this.versions:

https://github.com/embark-framework/embark/pull/1647/files#diff-354526adef3a786756303636f591fd48R36

This would then be registered and used here:

https://github.com/embark-framework/embark/pull/1647/files#diff-354526adef3a786756303636f591fd48R80

};

class LibraryManager {

constructor(embark, {useDashboard}) {
this.embark = embark;
this.logger = embark.logger;
this.config = embark.config;
this.contractsConfig = this.config.contractsConfig;
this.storageConfig = this.config.storageConfig;
Expand All @@ -24,11 +29,11 @@ class LibraryManager {

let solcVersionInConfig = this.contractsConfig.versions.solc;
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['web3'] = web3VersionInConfig;
this.versions['ipfs-api'] = ipfsApiVersion;
this.versions['ipfs-http-client'] = ipfsHttpClientVersion;

Object.keys(this.versions).forEach(versionKey => {
const newVersion = this.versions[versionKey].trim();
Expand Down Expand Up @@ -78,6 +83,14 @@ class LibraryManager {
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) {
Expand All @@ -95,14 +108,27 @@ class LibraryManager {
}

listenToCommandsToGetLibrary() {
const self = this;
let npm = new Npm({logger: this.embark.logger, useDashboard: this.useDashboard});
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);
});
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.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));
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/embark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"hosted-git-info": "2.7.1",
"http-proxy": "1.17.0",
"http-shutdown": "1.2.0",
"ipfs-api": "17.2.4",
"ipfs-http-client": "32.0.1",
"istanbul": "0.4.5",
"json-parse-better-errors": "1.0.2",
"live-plugin-manager-git-fix": "0.12.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/embark/src/lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Config.prototype.loadExternalContractsFiles = 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 = {
"default": {
Expand Down
22 changes: 11 additions & 11 deletions packages/embark/src/lib/modules/ipfs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { __ } from 'embark-i18n';
const UploadIPFS = require('./upload.js');
const utils = require('../../utils/utils.js');
const IpfsApi = require('ipfs-api');
const IPFSHTTPClient = require('ipfs-http-client');
// TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
const constants = require('embark-core/constants');
Expand Down Expand Up @@ -64,15 +64,15 @@ class IPFS {
});
}

downloadIpfsApi(cb) {
this.events.request("version:get:ipfs-api", (ipfsApiVersion) => {
let currentIpfsApiVersion = require('../../../../package.json').dependencies["ipfs-api"];
if (ipfsApiVersion === currentIpfsApiVersion) {
downloadIPFSHTTPClient(cb) {
this.events.request("version:get:ipfs-http-client", (ipfsApiVersion) => {
let currentIPFSHTTPClientVersion = require('../../../../package.json').dependencies["ipfs-http-client"];
if (ipfsApiVersion === currentIPFSHTTPClientVersion) {
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);
}
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));
});
});
Expand Down Expand Up @@ -131,19 +131,19 @@ class IPFS {
addStorageProviderToEmbarkJS() {
if(this.addedToEmbarkJs) return;
this.addedToEmbarkJs = true;
this.events.request('version:downloadIfNeeded', 'ipfs-api', (err, location) => {
this.events.request('version:downloadIfNeeded', 'ipfs-http-client', (err, location) => {
if (err) {
this.logger.error(__('Error downloading IPFS API'));
return this.logger.error(err.message || err);
}
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) {
this.logger.error(__('Error creating a symlink to IPFS API'));
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 = "";
code += "\nconst __embarkIPFS = require('embarkjs-ipfs')";
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);";
Expand All @@ -161,7 +161,7 @@ class IPFS {
this.addedToConsole = true;

const {host, port} = this._getNodeUrlConfig();
let ipfs = IpfsApi(host, port);
let ipfs = IPFSHTTPClient(host, port);
this.events.emit("runcode:register", "ipfs", ipfs);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/embarkjs-ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"ipfs-api": "17.2.4"
"ipfs-http-client": "32.0.1"
},
"devDependencies": {
"@babel/cli": "7.2.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/embarkjs-ipfs/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IpfsApi = require('ipfs-api');
const IPFSHTTPClient = require('ipfs-http-client');

const __embarkIPFS = {};

Expand All @@ -10,7 +10,7 @@ __embarkIPFS.setProvider = function (options) {
try {
if (!options) {
self._config = options;
self._ipfsConnection = IpfsApi('localhost', '5001');
self._ipfsConnection = IPFSHTTPClient('localhost', '5001');
self._getUrl = "http://localhost:8080/ipfs/";
} else {
const ipfsOptions = {host: options.host || options.server, protocol: 'http'};
Expand All @@ -20,7 +20,7 @@ __embarkIPFS.setProvider = function (options) {
if (options.port && options.port !== 'false') {
ipfsOptions.port = options.port;
}
self._ipfsConnection = IpfsApi(ipfsOptions);
self._ipfsConnection = IPFSHTTPClient(ipfsOptions);
self._getUrl = options.getUrl || "http://localhost:8080/ipfs/";
}
resolve(self);
Expand Down Expand Up @@ -54,7 +54,7 @@ __embarkIPFS.saveText = function (text) {
if (!self._ipfsConnection) {
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) {
return reject(err);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ __embarkIPFS.uploadFile = function (inputSelector) {
}
const reader = new FileReader();
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) {
if (err) {
return reject(err);
Expand Down
2 changes: 1 addition & 1 deletion site/source/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Every application [created with Embark](create_project.html) comes with an `emba
"versions": {
"web3": "1.0.0-beta",
"solc": "0.4.25",
"ipfs-api": "17.2.4"
"ipfs-http-client": "32.0.1"
},
"plugins": {
},
Expand Down
8 changes: 4 additions & 4 deletions site/source/docs/storage_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
{"provider": "ipfs", "host": "localhost", "port": 5001, "getUrl": "http://localhost:8080/ipfs/"}
],
"versions": {
"ipfs-api": "17.2.4"
"ipfs-http-client": "32.0.1"
}
},
"development": {
Expand All @@ -41,8 +41,8 @@ module.exports = {

The available options are:

Option | Type: `default` | Value
--- | --- | ---
Option | Type: `default` | Value
--- | --- | ---
`enabled` | boolean: `true` | Enables or completely disables storage support
`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.
Expand All @@ -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.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.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.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`).
Expand Down
Loading