2016-08-18 11:45:08 +00:00
|
|
|
/*globals $, SimpleStorage, document*/
|
|
|
|
|
2017-01-26 11:29:17 +00:00
|
|
|
var addToLog = function(id, txt) {
|
|
|
|
$(id + " .logs").append("<br>" + txt);
|
2016-08-18 11:45:08 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 11:29:17 +00:00
|
|
|
// ===========================
|
|
|
|
// Blockchain example
|
|
|
|
// ===========================
|
2015-05-24 13:07:19 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
2017-01-26 11:29:17 +00:00
|
|
|
$("#blockchain button.set").click(function() {
|
|
|
|
var value = parseInt($("#blockchain input.text").val(), 10);
|
2015-05-24 13:07:19 +00:00
|
|
|
SimpleStorage.set(value);
|
2017-01-26 11:29:17 +00:00
|
|
|
addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
|
2015-05-24 13:07:19 +00:00
|
|
|
});
|
|
|
|
|
2017-01-26 11:29:17 +00:00
|
|
|
$("#blockchain button.get").click(function() {
|
2016-08-18 11:45:08 +00:00
|
|
|
SimpleStorage.get().then(function(value) {
|
2017-01-26 11:29:17 +00:00
|
|
|
$("#blockchain .value").html(value.toNumber());
|
2016-08-18 11:45:08 +00:00
|
|
|
});
|
2017-01-26 11:29:17 +00:00
|
|
|
addToLog("#blockchain", "SimpleStorage.get()");
|
2015-05-24 13:07:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2017-01-26 11:29:17 +00:00
|
|
|
|
|
|
|
// ===========================
|
|
|
|
// Storage (IPFS) example
|
|
|
|
// ===========================
|
|
|
|
$(document).ready(function() {
|
2017-03-01 04:29:16 +00:00
|
|
|
// automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
|
|
|
|
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
2017-01-26 11:29:17 +00:00
|
|
|
|
2017-02-17 23:11:20 +00:00
|
|
|
$("#storage .error").hide();
|
|
|
|
EmbarkJS.Storage.ipfsConnection.ping()
|
|
|
|
.then(function(){
|
|
|
|
$("#status-storage").addClass('status-online');
|
|
|
|
$("#storage-controls").show();
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
if(err){
|
|
|
|
console.log("IPFS Connection Error => " + err.message);
|
|
|
|
$("#storage .error").show();
|
|
|
|
$("#status-storage").addClass('status-offline');
|
|
|
|
$("#storage-controls").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-26 11:29:17 +00:00
|
|
|
$("#storage button.setIpfsText").click(function() {
|
|
|
|
var value = $("#storage input.ipfsText").val();
|
|
|
|
EmbarkJS.Storage.saveText(value).then(function(hash) {
|
|
|
|
$("span.textHash").html(hash);
|
|
|
|
$("input.textHash").val(hash);
|
|
|
|
});
|
|
|
|
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#storage button.loadIpfsHash").click(function() {
|
|
|
|
var value = $("#storage input.textHash").val();
|
|
|
|
EmbarkJS.Storage.get(value).then(function(content) {
|
|
|
|
$("span.ipfsText").html(content);
|
|
|
|
});
|
|
|
|
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#storage button.uploadFile").click(function() {
|
|
|
|
var input = $("#storage input[type=file]");
|
|
|
|
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
|
|
|
|
$("span.fileIpfsHash").html(hash);
|
|
|
|
$("input.fileIpfsHash").val(hash);
|
|
|
|
});
|
|
|
|
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#storage button.loadIpfsFile").click(function() {
|
|
|
|
var hash = $("#storage input.fileIpfsHash").val();
|
|
|
|
var url = EmbarkJS.Storage.getUrl(hash);
|
|
|
|
var link = '<a href="' + url + '" target="_blank">' + url + '</a>';
|
|
|
|
$("span.ipfsFileUrl").html(link);
|
|
|
|
$(".ipfsImage").attr('src', url);
|
|
|
|
addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// ===========================
|
|
|
|
// Communication (Whisper) example
|
|
|
|
// ===========================
|
|
|
|
$(document).ready(function() {
|
2017-01-27 00:18:53 +00:00
|
|
|
|
|
|
|
$("#communication .error").hide();
|
|
|
|
web3.version.getWhisper(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
$("#communication .error").show();
|
2017-02-16 20:52:03 +00:00
|
|
|
$("#communication-controls").hide();
|
|
|
|
+ $("#status-communication").addClass('status-offline');
|
2017-01-27 00:18:53 +00:00
|
|
|
} else {
|
|
|
|
EmbarkJS.Messages.setProvider('whisper');
|
2017-02-16 20:52:03 +00:00
|
|
|
$("#status-communication").addClass('status-online');
|
2017-01-27 00:18:53 +00:00
|
|
|
}
|
|
|
|
});
|
2017-01-26 11:29:17 +00:00
|
|
|
|
|
|
|
$("#communication button.listenToChannel").click(function() {
|
|
|
|
var channel = $("#communication .listen input.channel").val();
|
|
|
|
$("#communication #subscribeList").append("<br> subscribed to " + channel + " now try sending a message");
|
|
|
|
EmbarkJS.Messages.listenTo({topic: [channel]}).then(function(message) {
|
|
|
|
$("#communication #messagesList").append("<br> channel: " + channel + " message: " + message);
|
|
|
|
});
|
|
|
|
addToLog("#communication", "EmbarkJS.Messages.listenTo({topic: ['" + channel + "']}).then(function(message) {})");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#communication button.sendMessage").click(function() {
|
|
|
|
var channel = $("#communication .send input.channel").val();
|
|
|
|
var message = $("#communication .send input.message").val();
|
|
|
|
EmbarkJS.Messages.sendMessage({topic: channel, data: message});
|
|
|
|
addToLog("#communication", "EmbarkJS.Messages.sendMessage({topic: '" + channel + "', data: '" + message + "'})");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|