mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-12 06:54:58 +00:00
Merge pull request #254 from nogueian/develop
Refactored EmbarkJS to allow multiple storage providers
This commit is contained in:
commit
65c5006d0e
@ -32,6 +32,9 @@ $(document).ready(function() {
|
|||||||
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
||||||
|
|
||||||
$("#storage .error").hide();
|
$("#storage .error").hide();
|
||||||
|
EmbarkJS.Storage.setProvider('ipfs')
|
||||||
|
.then(function(){
|
||||||
|
console.log('Provider set to IPFS');
|
||||||
EmbarkJS.Storage.ipfsConnection.ping()
|
EmbarkJS.Storage.ipfsConnection.ping()
|
||||||
.then(function(){
|
.then(function(){
|
||||||
$("#status-storage").addClass('status-online');
|
$("#status-storage").addClass('status-online');
|
||||||
@ -45,6 +48,13 @@ $(document).ready(function() {
|
|||||||
$("#storage-controls").hide();
|
$("#storage-controls").hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err){
|
||||||
|
console.log('Failed to set IPFS as Provider:', err.message);
|
||||||
|
$("#storage .error").show();
|
||||||
|
$("#status-storage").addClass('status-offline');
|
||||||
|
$("#storage-controls").hide();
|
||||||
|
});
|
||||||
|
|
||||||
$("#storage button.setIpfsText").click(function() {
|
$("#storage button.setIpfsText").click(function() {
|
||||||
var value = $("#storage input.ipfsText").val();
|
var value = $("#storage input.ipfsText").val();
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"embark": "^2.4.0",
|
"embark": "^2.4.1",
|
||||||
"mocha": "^2.2.5"
|
"mocha": "^2.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,11 @@ var EmbarkJS =
|
|||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
//var Ipfs = require('./ipfs.js');
|
//var Ipfs = require('./ipfs.js');
|
||||||
|
|
||||||
var EmbarkJS = {
|
//=========================================================
|
||||||
};
|
// Embark Smart Contracts
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
var EmbarkJS = {};
|
||||||
|
|
||||||
EmbarkJS.Contract = function(options) {
|
EmbarkJS.Contract = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -196,7 +199,11 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else if (transaction.address !== undefined) {
|
} else if (transaction.address !== undefined) {
|
||||||
resolve(new EmbarkJS.Contract({abi: self.abi, code: self.code, address: transaction.address}));
|
resolve(new EmbarkJS.Contract({
|
||||||
|
abi: self.abi,
|
||||||
|
code: self.code,
|
||||||
|
address: transaction.address
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -210,33 +217,78 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage = {
|
//=========================================================
|
||||||
IPFS : 'ipfs'
|
// Embark Storage
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
EmbarkJS.Storage = {};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.Providers = {
|
||||||
|
IPFS: 'ipfs',
|
||||||
|
SWARM: 'swarm'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.IPFS = {};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.saveText = function(text) {
|
||||||
|
return this.currentStorage.saveText(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.get = function(hash) {
|
||||||
|
return this.currentStorage.get(hash);
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
||||||
|
return this.currentStorage.uploadFile(inputSelector);
|
||||||
|
}
|
||||||
|
|
||||||
|
EmbarkJS.Storage.getUrl = function(hash) {
|
||||||
|
return this.currentStorage.getUrl(hash);
|
||||||
|
}
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||||
if (provider.toLowerCase() === EmbarkJS.Storage.IPFS) {
|
var self = this;
|
||||||
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
if (provider.toLowerCase() === EmbarkJS.Storage.Providers.IPFS) {
|
||||||
//I don't think currentStorage is used anywhere, this might not be needed
|
//I don't think currentStorage is used anywhere, this might not be needed
|
||||||
//for now until additional storage providers are supported. But keeping it
|
//for now until additional storage providers are supported. But keeping it
|
||||||
//anyways
|
//anyways
|
||||||
this.currentStorage = EmbarkJS.Storage.IPFS;
|
self.currentStorage = EmbarkJS.Storage.IPFS;
|
||||||
|
|
||||||
|
try {
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
this.ipfsConnection = IpfsApi('localhost', '5001');
|
self.ipfsConnection = IpfsApi('localhost', '5001');
|
||||||
} else {
|
} else {
|
||||||
this.ipfsConnection = IpfsApi(options.server, options.port);
|
self.ipfsConnection = IpfsApi(options.server, options.port);
|
||||||
}
|
}
|
||||||
|
resolve(self);
|
||||||
|
} catch (err) {
|
||||||
|
self.ipfsConnection = null;
|
||||||
|
reject(new Error('Failed to connect to IPFS'));
|
||||||
|
}
|
||||||
|
} else if (provider.toLowerCase() === EmbarkJS.Storage.SWARM) {
|
||||||
|
reject('Swarm not implemented');
|
||||||
|
// TODO Implement Swarm
|
||||||
|
// this.currentStorage = EmbarkJS.Storage.SWARM;
|
||||||
|
// if (options === undefined) {
|
||||||
|
// //Connect to default Swarm node
|
||||||
|
// } else {
|
||||||
|
// //Connect using options
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
throw Error('Unknown storage provider');
|
reject('Unknown storage provider');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.saveText = function(text) {
|
EmbarkJS.Storage.IPFS.saveText = function(text) {
|
||||||
var self = this;
|
|
||||||
if (!this.ipfsConnection) {
|
|
||||||
this.setProvider('ipfs');
|
|
||||||
}
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
self.ipfsConnection.add((new self.ipfsConnection.Buffer(text)), function(err, result) {
|
if (!EmbarkJS.Storage.ipfsConnection) {
|
||||||
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
|
reject(connectionError);
|
||||||
|
}
|
||||||
|
EmbarkJS.Storage.ipfsConnection.add((new EmbarkJS.Storage.ipfsConnection.Buffer(text)), function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@ -248,24 +300,41 @@ EmbarkJS.Storage.saveText = function(text) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
EmbarkJS.Storage.IPFS.get = function(hash) {
|
||||||
var self = this;
|
// TODO: detect type, then convert if needed
|
||||||
|
//var ipfsHash = web3.toAscii(hash);
|
||||||
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
if (!EmbarkJS.Storage.ipfsConnection) {
|
||||||
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
|
reject(connectionError);
|
||||||
|
}
|
||||||
|
EmbarkJS.Storage.ipfsConnection.object.get([hash]).then(function(node) {
|
||||||
|
resolve(node.data);
|
||||||
|
}).catch(function(err) {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.IPFS.uploadFile = function(inputSelector) {
|
||||||
var file = inputSelector[0].files[0];
|
var file = inputSelector[0].files[0];
|
||||||
|
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
throw new Error('no file found');
|
throw new Error('no file found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.ipfsConnection) {
|
|
||||||
this.setProvider('ipfs');
|
|
||||||
}
|
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
if (!EmbarkJS.Storage.ipfsConnection) {
|
||||||
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
|
reject(connectionError);
|
||||||
|
}
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onloadend = function() {
|
reader.onloadend = function() {
|
||||||
var fileContent = reader.result;
|
var fileContent = reader.result;
|
||||||
var buffer = self.ipfsConnection.Buffer.from(fileContent);
|
var buffer = EmbarkJS.Storage.ipfsConnection.Buffer.from(fileContent);
|
||||||
self.ipfsConnection.add(buffer, function(err, result) {
|
EmbarkJS.Storage.ipfsConnection.add(buffer, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@ -279,33 +348,17 @@ EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.get = function(hash) {
|
EmbarkJS.Storage.IPFS.getUrl = function(hash) {
|
||||||
var self = this;
|
|
||||||
// TODO: detect type, then convert if needed
|
|
||||||
//var ipfsHash = web3.toAscii(hash);
|
|
||||||
if (!this.ipfsConnection) {
|
|
||||||
this.setProvider('ipfs');
|
|
||||||
}
|
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
|
||||||
self.ipfsConnection.object.get([hash]).then(function(node) {
|
|
||||||
resolve(node.data);
|
|
||||||
}).catch(function (err){
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Storage.getUrl = function(hash) {
|
|
||||||
//var ipfsHash = web3.toAscii(hash);
|
//var ipfsHash = web3.toAscii(hash);
|
||||||
|
|
||||||
return 'http://localhost:8080/ipfs/' + hash;
|
return 'http://localhost:8080/ipfs/' + hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages = {
|
//=========================================================
|
||||||
};
|
// Embark Messaging
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
EmbarkJS.Messages = {};
|
||||||
|
|
||||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -336,7 +389,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
|
|||||||
this.currentMessages.orbit = new Orbit(ipfs);
|
this.currentMessages.orbit = new Orbit(ipfs);
|
||||||
this.currentMessages.orbit.connect(web3.eth.accounts[0]);
|
this.currentMessages.orbit.connect(web3.eth.accounts[0]);
|
||||||
} else {
|
} else {
|
||||||
throw Error('unknown provider');
|
throw Error('Unknown message provider');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -348,8 +401,7 @@ EmbarkJS.Messages.listenTo = function(options) {
|
|||||||
return this.currentMessages.listenTo(options);
|
return this.currentMessages.listenTo(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.Whisper = {
|
EmbarkJS.Messages.Whisper = {};
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
|
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
|
||||||
var topics = options.topic || options.topics;
|
var topics = options.topic || options.topics;
|
||||||
@ -448,8 +500,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.Orbit = {
|
EmbarkJS.Messages.Orbit = {};
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
||||||
var topics = options.topic || options.topics;
|
var topics = options.topic || options.topics;
|
||||||
|
153
js/embark.js
153
js/embark.js
@ -1,8 +1,11 @@
|
|||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
//var Ipfs = require('./ipfs.js');
|
//var Ipfs = require('./ipfs.js');
|
||||||
|
|
||||||
var EmbarkJS = {
|
//=========================================================
|
||||||
};
|
// Embark Smart Contracts
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
var EmbarkJS = {};
|
||||||
|
|
||||||
EmbarkJS.Contract = function(options) {
|
EmbarkJS.Contract = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -123,7 +126,11 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else if (transaction.address !== undefined) {
|
} else if (transaction.address !== undefined) {
|
||||||
resolve(new EmbarkJS.Contract({abi: self.abi, code: self.code, address: transaction.address}));
|
resolve(new EmbarkJS.Contract({
|
||||||
|
abi: self.abi,
|
||||||
|
code: self.code,
|
||||||
|
address: transaction.address
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,33 +144,78 @@ EmbarkJS.Contract.prototype.deploy = function(args, _options) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage = {
|
//=========================================================
|
||||||
IPFS : 'ipfs'
|
// Embark Storage
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
EmbarkJS.Storage = {};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.Providers = {
|
||||||
|
IPFS: 'ipfs',
|
||||||
|
SWARM: 'swarm'
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.IPFS = {};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.saveText = function(text) {
|
||||||
|
return this.currentStorage.saveText(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.get = function(hash) {
|
||||||
|
return this.currentStorage.get(hash);
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
||||||
|
return this.currentStorage.uploadFile(inputSelector);
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.getUrl = function(hash) {
|
||||||
|
return this.currentStorage.getUrl(hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.setProvider = function(provider, options) {
|
EmbarkJS.Storage.setProvider = function(provider, options) {
|
||||||
if (provider.toLowerCase() === EmbarkJS.Storage.IPFS) {
|
var self = this;
|
||||||
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
if (provider.toLowerCase() === EmbarkJS.Storage.Providers.IPFS) {
|
||||||
//I don't think currentStorage is used anywhere, this might not be needed
|
//I don't think currentStorage is used anywhere, this might not be needed
|
||||||
//for now until additional storage providers are supported. But keeping it
|
//for now until additional storage providers are supported. But keeping it
|
||||||
//anyways
|
//anyways
|
||||||
this.currentStorage = EmbarkJS.Storage.IPFS;
|
self.currentStorage = EmbarkJS.Storage.IPFS;
|
||||||
|
|
||||||
|
try {
|
||||||
if (options === undefined) {
|
if (options === undefined) {
|
||||||
this.ipfsConnection = IpfsApi('localhost', '5001');
|
self.ipfsConnection = IpfsApi('localhost', '5001');
|
||||||
} else {
|
} else {
|
||||||
this.ipfsConnection = IpfsApi(options.server, options.port);
|
self.ipfsConnection = IpfsApi(options.server, options.port);
|
||||||
}
|
}
|
||||||
|
resolve(self);
|
||||||
|
} catch (err) {
|
||||||
|
self.ipfsConnection = null;
|
||||||
|
reject(new Error('Failed to connect to IPFS'));
|
||||||
|
}
|
||||||
|
} else if (provider.toLowerCase() === EmbarkJS.Storage.SWARM) {
|
||||||
|
reject('Swarm not implemented');
|
||||||
|
// TODO Implement Swarm
|
||||||
|
// this.currentStorage = EmbarkJS.Storage.SWARM;
|
||||||
|
// if (options === undefined) {
|
||||||
|
// //Connect to default Swarm node
|
||||||
|
// } else {
|
||||||
|
// //Connect using options
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
throw Error('Unknown storage provider');
|
reject('Unknown storage provider');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.saveText = function(text) {
|
EmbarkJS.Storage.IPFS.saveText = function(text) {
|
||||||
var self = this;
|
|
||||||
if (!this.ipfsConnection) {
|
|
||||||
this.setProvider('ipfs');
|
|
||||||
}
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
self.ipfsConnection.add((new self.ipfsConnection.Buffer(text)), function(err, result) {
|
if (!EmbarkJS.Storage.ipfsConnection) {
|
||||||
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
|
reject(connectionError);
|
||||||
|
}
|
||||||
|
EmbarkJS.Storage.ipfsConnection.add((new EmbarkJS.Storage.ipfsConnection.Buffer(text)), function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@ -175,24 +227,41 @@ EmbarkJS.Storage.saveText = function(text) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
EmbarkJS.Storage.IPFS.get = function(hash) {
|
||||||
var self = this;
|
// TODO: detect type, then convert if needed
|
||||||
|
//var ipfsHash = web3.toAscii(hash);
|
||||||
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
if (!EmbarkJS.Storage.ipfsConnection) {
|
||||||
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
|
reject(connectionError);
|
||||||
|
}
|
||||||
|
EmbarkJS.Storage.ipfsConnection.object.get([hash]).then(function(node) {
|
||||||
|
resolve(node.data);
|
||||||
|
}).catch(function(err) {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
EmbarkJS.Storage.IPFS.uploadFile = function(inputSelector) {
|
||||||
var file = inputSelector[0].files[0];
|
var file = inputSelector[0].files[0];
|
||||||
|
|
||||||
if (file === undefined) {
|
if (file === undefined) {
|
||||||
throw new Error('no file found');
|
throw new Error('no file found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.ipfsConnection) {
|
|
||||||
this.setProvider('ipfs');
|
|
||||||
}
|
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
|
if (!EmbarkJS.Storage.ipfsConnection) {
|
||||||
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Storage.setProvider()');
|
||||||
|
reject(connectionError);
|
||||||
|
}
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onloadend = function() {
|
reader.onloadend = function() {
|
||||||
var fileContent = reader.result;
|
var fileContent = reader.result;
|
||||||
var buffer = self.ipfsConnection.Buffer.from(fileContent);
|
var buffer = EmbarkJS.Storage.ipfsConnection.Buffer.from(fileContent);
|
||||||
self.ipfsConnection.add(buffer, function(err, result) {
|
EmbarkJS.Storage.ipfsConnection.add(buffer, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@ -206,33 +275,17 @@ EmbarkJS.Storage.uploadFile = function(inputSelector) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Storage.get = function(hash) {
|
EmbarkJS.Storage.IPFS.getUrl = function(hash) {
|
||||||
var self = this;
|
|
||||||
// TODO: detect type, then convert if needed
|
|
||||||
//var ipfsHash = web3.toAscii(hash);
|
|
||||||
if (!this.ipfsConnection) {
|
|
||||||
this.setProvider('ipfs');
|
|
||||||
}
|
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
|
||||||
self.ipfsConnection.object.get([hash]).then(function(node) {
|
|
||||||
resolve(node.data);
|
|
||||||
}).catch(function (err){
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Storage.getUrl = function(hash) {
|
|
||||||
//var ipfsHash = web3.toAscii(hash);
|
//var ipfsHash = web3.toAscii(hash);
|
||||||
|
|
||||||
return 'http://localhost:8080/ipfs/' + hash;
|
return 'http://localhost:8080/ipfs/' + hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages = {
|
//=========================================================
|
||||||
};
|
// Embark Messaging
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
EmbarkJS.Messages = {};
|
||||||
|
|
||||||
EmbarkJS.Messages.setProvider = function(provider, options) {
|
EmbarkJS.Messages.setProvider = function(provider, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -263,7 +316,7 @@ EmbarkJS.Messages.setProvider = function(provider, options) {
|
|||||||
this.currentMessages.orbit = new Orbit(ipfs);
|
this.currentMessages.orbit = new Orbit(ipfs);
|
||||||
this.currentMessages.orbit.connect(web3.eth.accounts[0]);
|
this.currentMessages.orbit.connect(web3.eth.accounts[0]);
|
||||||
} else {
|
} else {
|
||||||
throw Error('unknown provider');
|
throw Error('Unknown message provider');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -275,8 +328,7 @@ EmbarkJS.Messages.listenTo = function(options) {
|
|||||||
return this.currentMessages.listenTo(options);
|
return this.currentMessages.listenTo(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.Whisper = {
|
EmbarkJS.Messages.Whisper = {};
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
|
EmbarkJS.Messages.Whisper.sendMessage = function(options) {
|
||||||
var topics = options.topic || options.topics;
|
var topics = options.topic || options.topics;
|
||||||
@ -375,8 +427,7 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Messages.Orbit = {
|
EmbarkJS.Messages.Orbit = {};
|
||||||
};
|
|
||||||
|
|
||||||
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
EmbarkJS.Messages.Orbit.sendMessage = function(options) {
|
||||||
var topics = options.topic || options.topics;
|
var topics = options.topic || options.topics;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user