mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-23 04:28:19 +00:00
Storage config improvements start. Adjusted the config and have started to support those improvements through the codebase.
Currently stuck on starting multiple storage servcies at once. Might need a change in storage config spec. WIP.
This commit is contained in:
parent
0cb79d84a0
commit
942a57aa3a
12
js/embark.js
12
js/embark.js
@ -230,6 +230,18 @@ EmbarkJS.Storage.setProvider = function(provider, options) {
|
|||||||
return providerObj.setProvider(options);
|
return providerObj.setProvider(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.setProviders = function(provider, dappConnOptions) {
|
||||||
|
let providerObj = this.Providers[provider];
|
||||||
|
|
||||||
|
if (!providerObj) {
|
||||||
|
throw new Error('Unknown storage provider');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentStorage = providerObj;
|
||||||
|
|
||||||
|
return providerObj.setProviders(dappConnOptions);
|
||||||
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.isAvailable = function(){
|
EmbarkJS.Storage.isAvailable = function(){
|
||||||
if (!this.currentStorage) {
|
if (!this.currentStorage) {
|
||||||
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
throw new Error('Storage provider not set; e.g EmbarkJS.Storage.setProvider("ipfs")');
|
||||||
|
@ -135,6 +135,7 @@ class Engine {
|
|||||||
plugins: this.plugins
|
plugins: this.plugins
|
||||||
});
|
});
|
||||||
this.events.on('code-generator-ready', function () {
|
this.events.on('code-generator-ready', function () {
|
||||||
|
console.log('CODE GENERATOR READY EVENT FIRED');
|
||||||
self.events.request('code', function (abi, contractsJSON) {
|
self.events.request('code', function (abi, contractsJSON) {
|
||||||
pipeline.build(abi, contractsJSON, null, () => {
|
pipeline.build(abi, contractsJSON, null, () => {
|
||||||
if (self.watch) {
|
if (self.watch) {
|
||||||
@ -263,24 +264,18 @@ class Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
storageService(_options) {
|
storageService(_options) {
|
||||||
this.registerModule('storage', {
|
this.registerModule('ipfs', {
|
||||||
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||||
host: _options.host,
|
host: _options.host,
|
||||||
port: _options.port
|
port: _options.port
|
||||||
});
|
});
|
||||||
// this.registerModule('ipfs', {
|
this.registerModule('swarm', {
|
||||||
// addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
||||||
// storageConfig: this.config.storageConfig,
|
storageConfig: this.config.storageConfig,
|
||||||
// host: _options.host,
|
// TODO: this should not be needed and should be deducted from the config instead
|
||||||
// port: _options.port
|
// the eth provider is not necessary the same as the swarm one
|
||||||
// });
|
bzz: this.blockchain.web3.bzz
|
||||||
// this.registerModule('swarm', {
|
});
|
||||||
// addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor),
|
|
||||||
// storageConfig: this.config.storageConfig,
|
|
||||||
// // TODO: this should not be needed and should be deducted from the config instead
|
|
||||||
// // the eth provider is not necessary the same as the swarm one
|
|
||||||
// bzz: this.blockchain.web3.bzz
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
web3Service(options) {
|
web3Service(options) {
|
||||||
|
@ -132,6 +132,9 @@
|
|||||||
"IPFS node detected": "IPFS node detected",
|
"IPFS node detected": "IPFS node detected",
|
||||||
"Webserver is offline": "Webserver is offline",
|
"Webserver is offline": "Webserver is offline",
|
||||||
"DApp path length is too long: \"": "DApp path length is too long: \"",
|
"DApp path length is too long: \"": "DApp path length is too long: \"",
|
||||||
|
"This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.": "This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less."
|
||||||
|
"no contracts found": "no contracts found",
|
||||||
|
"DApp path length is too long: \"": "DApp path length is too long: \"",
|
||||||
"This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.": "This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.",
|
"This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.": "This is known to cause issues with some applications, please consider reducing your DApp path's length to 66 characters or less.",
|
||||||
"deploying to swarm!": "deploying to swarm!",
|
"deploying to swarm!": "deploying to swarm!",
|
||||||
"adding %s to swarm": "adding %s to swarm",
|
"adding %s to swarm": "adding %s to swarm",
|
||||||
|
@ -162,6 +162,7 @@ class Embark {
|
|||||||
engine.startService('storage');
|
engine.startService('storage');
|
||||||
engine.startService("codeGenerator");
|
engine.startService("codeGenerator");
|
||||||
engine.startService("namingSystem");
|
engine.startService("namingSystem");
|
||||||
|
|
||||||
engine.events.on('check:backOnline:Ethereum', function () {
|
engine.events.on('check:backOnline:Ethereum', function () {
|
||||||
engine.logger.info(__('Ethereum node detected') + '..');
|
engine.logger.info(__('Ethereum node detected') + '..');
|
||||||
engine.config.reloadConfig();
|
engine.config.reloadConfig();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import IpfsApi from 'ipfs-api';
|
import IpfsApi from 'ipfs-api';
|
||||||
|
//import {some} from 'p-iteration';
|
||||||
|
|
||||||
let __embarkIPFS = {};
|
let __embarkIPFS = {};
|
||||||
|
|
||||||
@ -24,13 +25,36 @@ __embarkIPFS.setProvider = function (options) {
|
|||||||
resolve(self);
|
resolve(self);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
self._ipfsConnection = null;
|
self.ipfsConnection = null;
|
||||||
reject(new Error('Failed to connect to IPFS'));
|
reject(new Error('Failed to connect to IPFS'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__embarkIPFS.setProviders = async function (dappConnOptions) {
|
||||||
|
var self = this;
|
||||||
|
try {
|
||||||
|
let workingConnFound = await some(dappConnOptions, async (dappConn) => {
|
||||||
|
if(dappConn === '$BZZ' || dappConn.provider !== 'ipfs') return false; // swarm has no bearing for ipfs plugin, continue
|
||||||
|
else {
|
||||||
|
// set the provider then check the connection, if true, use that provider, else, check next provider
|
||||||
|
try{
|
||||||
|
await self.setProvider(dappConn);
|
||||||
|
return await self.isAvailable();
|
||||||
|
} catch(err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!workingConnFound) throw new Error('Could not connect to IPFS using any of the dappConnections in the storage config');
|
||||||
|
else return self;
|
||||||
|
} catch (err) {
|
||||||
|
self.ipfsConnection = null;
|
||||||
|
throw new Error('Failed to connect to IPFS: ' + err.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
__embarkIPFS.saveText = function (text) {
|
__embarkIPFS.saveText = function (text) {
|
||||||
const self = this;
|
const self = this;
|
||||||
var promise = new Promise(function (resolve, reject) {
|
var promise = new Promise(function (resolve, reject) {
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
let UploadIPFS = require('./upload.js');
|
||||||
|
let utils = require('../../utils/utils.js');
|
||||||
|
let fs = require('../../core/fs.js');
|
||||||
|
let RunCode = require('../../coderunner/runCode');
|
||||||
|
let IpfsApi = require('ipfs-api');
|
||||||
|
const _ = require('underscore');
|
||||||
const UploadIPFS = require('./upload.js');
|
const UploadIPFS = require('./upload.js');
|
||||||
const utils = require('../../utils/utils.js');
|
const utils = require('../../utils/utils.js');
|
||||||
const fs = require('../../core/fs.js');
|
const fs = require('../../core/fs.js');
|
||||||
@ -109,12 +115,12 @@ class IPFS {
|
|||||||
this.embark.addCodeToEmbarkJS(code);
|
this.embark.addCodeToEmbarkJS(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// addSetProvider() {
|
addSetProvider() {
|
||||||
// let code = "\nEmbarkJS.Storage.setProviders('ipfs'," + JSON.stringify(this.storageConfig.dappConnection) + ");";
|
let code = "\nEmbarkJS.Storage.setProviders('ipfs'," + JSON.stringify(this.storageConfig.dappConnection) + ");";
|
||||||
|
|
||||||
// let shouldInit = (storageConfig) => {
|
let shouldInit = (storageConfig) => {
|
||||||
// return (this.storageConfig.dappConnection !== undefined && this.storageConfig.dappConnection.some((dappConn) => dappConn.provider === 'ipfs') && storageConfig.enabled === true);
|
return (this.storageConfig.dappConnection !== undefined && this.storageConfig.dappConnection.some((dappConn) => dappConn.provider === 'ipfs') && storageConfig.enabled === true);
|
||||||
// };
|
};
|
||||||
|
|
||||||
// this.embark.addProviderInit('storage', code, shouldInit);
|
// this.embark.addProviderInit('storage', code, shouldInit);
|
||||||
// }
|
// }
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
/*global web3 */
|
/*global web3 */
|
||||||
let __embarkSwarm = {};
|
let __embarkSwarm = {};
|
||||||
const bytes = require("eth-lib/lib/bytes");
|
const bytes = require("eth-lib/lib/bytes");
|
||||||
|
import {some} from 'p-iteration';
|
||||||
|
|
||||||
__embarkSwarm.setProvider = function (options) {
|
__embarkSwarm.setProvider = function (options) {
|
||||||
let protocol = options.protocol || 'http';
|
this.bzz = web3.bzz;
|
||||||
let port = options.port ? `:${options.port}` : '';
|
this.protocol = options.protocol || 'http';
|
||||||
|
this.connectUrl = `${this.protocol}://${options.host}:${options.port}`;
|
||||||
|
this.connectError = new Error(`Cannot connect to Swarm node on ${this.connectUrl}`);
|
||||||
|
//this._getUrl = options.getUrl || `${this.connectUrl}/bzzr:/`;
|
||||||
|
|
||||||
this._config = options;
|
this._config = options;
|
||||||
this._connectUrl = `${protocol}://${options.host}${port}`;
|
this._connectUrl = `${protocol}://${options.host}${port}`;
|
||||||
@ -12,8 +16,8 @@ __embarkSwarm.setProvider = function (options) {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
if (!web3.bzz.currentProvider && !options.useOnlyGivenProvider) {
|
if (!this.bzz.currentProvider) {
|
||||||
web3.bzz.setProvider(this._connectUrl);
|
this.bzz.setProvider(this.connectUrl);
|
||||||
}
|
}
|
||||||
else if(options.useOnlyGivenProvider && web3.bzz.givenProvider !== null){
|
else if(options.useOnlyGivenProvider && web3.bzz.givenProvider !== null){
|
||||||
web3.bzz.setProvider(web3.bzz.givenProvider);
|
web3.bzz.setProvider(web3.bzz.givenProvider);
|
||||||
@ -26,6 +30,28 @@ __embarkSwarm.setProvider = function (options) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__embarkSwarm.setProviders = async function (dappConnOptions) {
|
||||||
|
var self = this;
|
||||||
|
try {
|
||||||
|
let workingConnFound = await some(dappConnOptions, async (dappConn) => {
|
||||||
|
if(dappConn === '$BZZ'){
|
||||||
|
return self.isAvailable();
|
||||||
|
}
|
||||||
|
else if(dappConn.provider === 'swarm')
|
||||||
|
{
|
||||||
|
// set the provider then check the connection, if true, use that provider, else, check next provider
|
||||||
|
await self.setProvider(dappConn);
|
||||||
|
return self.isAvailable();
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
});
|
||||||
|
if(!workingConnFound) throw new Error('Could not connect to Swarm using any of the dappConnections in the storage config');
|
||||||
|
else return self;
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error('Failed to connect to Swarm: ' + err.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
__embarkSwarm.isAvailable = function () {
|
__embarkSwarm.isAvailable = function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// if web3 swarm object doesn't exist
|
// if web3 swarm object doesn't exist
|
||||||
|
@ -10,6 +10,9 @@ class Swarm {
|
|||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
this.storageConfig = options.storageConfig;
|
this.storageConfig = options.storageConfig;
|
||||||
|
this.host = options.host || options.storageConfig.upload.host;
|
||||||
|
this.port = options.port || options.storageConfig.upload.port;
|
||||||
|
this.protocol = options.protocol || options.storageConfig.upload.protocol;
|
||||||
this.addCheck = options.addCheck;
|
this.addCheck = options.addCheck;
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
|
|
||||||
@ -24,6 +27,12 @@ class Swarm {
|
|||||||
this.bzz = new Web3Bzz(this.providerUrl);
|
this.bzz = new Web3Bzz(this.providerUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initSwarmProvider(){
|
||||||
|
if(!this.bzz.currentProvider) {
|
||||||
|
this.bzz.setProvider(`${this.protocol}://${this.host}:${this.port}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commandlineDeploy() {
|
commandlineDeploy() {
|
||||||
this.upload_swarm = new UploadSwarm({
|
this.upload_swarm = new UploadSwarm({
|
||||||
buildDir: this.buildDir || 'dist/',
|
buildDir: this.buildDir || 'dist/',
|
||||||
@ -73,7 +82,7 @@ class Swarm {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addProviderToEmbarkJS() {
|
addSwarmToEmbarkJS() {
|
||||||
let self = this;
|
let self = this;
|
||||||
// TODO: make this a shouldAdd condition
|
// TODO: make this a shouldAdd condition
|
||||||
if (this.storageConfig === {}) {
|
if (this.storageConfig === {}) {
|
||||||
@ -99,6 +108,16 @@ class Swarm {
|
|||||||
|
|
||||||
this.embark.addCodeToEmbarkJS(code);
|
this.embark.addCodeToEmbarkJS(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addSetProvider() {
|
||||||
|
let code = "\nEmbarkJS.Storage.setProviders('swarm'," + JSON.stringify(this.storageConfig.dappConnection) + ");";
|
||||||
|
|
||||||
|
let shouldInit = (storageConfig) => {
|
||||||
|
return (this.storageConfig.dappConnection !== undefined && this.storageConfig.dappConnection.some((dappConn) => dappConn.provider === 'swarm') && storageConfig.enabled === true);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.embark.addProviderInit('storage', code, shouldInit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Swarm;
|
module.exports = Swarm;
|
||||||
|
@ -20,10 +20,10 @@
|
|||||||
"development": {
|
"development": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"upload": {
|
"upload": {
|
||||||
"provider": "swarm",
|
"provider": "ipfs",
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 8500,
|
"port": 5001,
|
||||||
"getUrl": "http://localhost:8500/bzzr:/"
|
"getUrl": "http://localhost:8080/ipfs/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"livenet": {
|
"livenet": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user