fix: fix test-app, contracts index file and reload on change (#1892)

* fix: fix test-app, contracts index file and reload on change

* fix(@embark/cmd_controller): fix missing nodes

Was removed by accident

* feat(@embark/demo): add favicon to embark demo

* chore(@embark/cockpit): change favicon to new Embark logo

* fix(@embark/embarkjs-ens): fix ENS config for embarkjs-ens

* remove comments
This commit is contained in:
Jonathan Rainville 2019-09-11 12:31:57 -04:00 committed by Iuri Matias
parent 3fe5b93a1f
commit ee634c8403
33 changed files with 326 additions and 267 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
</browserconfig>

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -0,0 +1,25 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="260.000000pt" height="260.000000pt" viewBox="0 0 260.000000 260.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.11, written by Peter Selinger 2001-2013
</metadata>
<g transform="translate(0.000000,260.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M0 1300 l0 -1300 347 0 c345 0 380 3 445 36 14 8 37 14 50 14 15 0
32 11 46 30 33 44 75 62 136 58 50 -3 52 -2 94 44 50 54 77 126 87 236 7 61 5
74 -12 99 -11 15 -37 59 -56 97 -20 38 -39 62 -41 55 -4 -12 -33 -136 -68
-296 -9 -37 -17 -53 -28 -53 -18 0 -53 134 -112 429 -37 182 -36 189 43 346
47 93 51 107 60 206 15 181 53 309 141 481 47 93 130 217 189 286 l29 33 0
-426 c0 -360 2 -429 15 -441 8 -8 39 -52 70 -98 76 -115 77 -125 17 -416 l-49
-235 38 -3 37 -3 7 -67 c11 -113 33 -178 77 -223 21 -22 43 -51 48 -64 6 -16
17 -25 30 -25 26 0 57 -16 86 -42 14 -13 24 -16 29 -9 3 6 21 11 40 11 25 0
39 -7 55 -27 l22 -28 364 -3 364 -3 0 1300 0 1301 -1300 0 -1300 0 0 -1300z
m1787 -257 c56 -121 55 -147 -23 -493 -49 -217 -53 -230 -69 -230 -8 0 -15 3
-15 8 0 4 -18 81 -41 172 -22 91 -40 170 -40 175 -1 6 13 46 30 90 42 106 71
231 78 333 l6 82 20 -32 c11 -18 35 -65 54 -105z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,19 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-256x256.png",
"sizes": "256x256",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}

View File

@ -1,6 +1,13 @@
<html>
<head>
<title>Embark - SimpleStorage Demo</title>
<link rel="apple-touch-icon" sizes="180x180" href="images/app/images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/app/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/app/images/favicon-16x16.png">
<link rel="manifest" href="images/app/images/site.webmanifest">
<link rel="mask-icon" href="images/app/images/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body class="container">
<div id="app">

View File

@ -1,16 +1,15 @@
<html>
<head>
<title>Embark - SimpleStorage Demo</title>
<!-- <link rel="stylesheet" href="css/app.css"> -->
<!--<script src="js/jquery.js"></script> -->
<!-- <script src="js/bootstrap.js"></script> -->
<link rel="stylesheet" href="css/app.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
</head>
<body class="container">
<div id="root"></div>
<h3>Embark - Usage Example</h3>
<h1>Embark - Usage Example</h1>
<ul class="nav nav-tabs" role="tablist" id="myTabs">
<li role="presentation" class="active"><a href="#blockchain" aria-controls="blockchain" role="tab" data-toggle="tab">Blockchain</a></li>

View File

@ -1,27 +0,0 @@
import { Component } from 'react';
import SimpleStorage from '../../embarkArtifacts/contracts/SimpleStorage';
window.SimpleStorage = SimpleStorage;
class App extends Component {
action() {
console.log("calling...");
SimpleStorage.methods.get().call(function(err, value) {
alert(value);
});
}
render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title" onClick={() => this.action() }>Welcome to React</h1>
</header>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
}
}
export default App;

View File

@ -1,3 +1,3 @@
body {
background-color: black;
h1 {
background-color: #ccc;
}

View File

@ -1,195 +1,142 @@
/*global web3*/
import EmbarkJS from 'Embark/EmbarkJS';
import {SimpleStorage, Test, SimpleStorageTest} from '../../embarkArtifacts/contracts';
window.SimpleStorageTest = SimpleStorageTest;
// import {SimpleStorage} from '../../embarkArtifacts/contracts';
import $ from 'jquery';
import SimpleStorage from '../../embarkArtifacts/contracts/SimpleStorage.js';
// import web3 from '../../embarkArtifacts/contracts/web3_init';
// window.web3 = web3;
window.SimpleStorage = SimpleStorage;
import EmbarkJS from '../../embarkArtifacts/embarkjs.js';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';
import 'bootstrap/dist/js/bootstrap.min.js';
window.EmbarkJS = EmbarkJS;
window.SimpleStorage = SimpleStorage;
window.Test = Test;
$("#blockchain button.set").click(function() {
var value = parseInt($("#blockchain input.text").val(), 10);
var addToLog = function(id, txt) {
$(id + " .logs").append("<br>" + txt);
};
// ===========================
// Blockchain example
// ===========================
$(document).ready(function() {
EmbarkJS.onReady((err) => {
if (err) {
console.error(err);
}
});
$("#blockchain button.set").click(function() {
var value = parseInt($("#blockchain input.text").val(), 10);
SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000});
addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000})");
});
$("#blockchain button.get").click(function() {
SimpleStorage.methods.get().call(function(err, value) {
$("#blockchain .value").html(value);
});
addToLog("#blockchain", "SimpleStorage.methods.get(console.log)");
});
SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000});
});
// TODO check why from not set
$("#blockchain button.get").click(function() {
SimpleStorage.methods.get().call({from: web3.eth.defaultAccount}, function(err, value) {
console.log('GET', err, value);
$("#blockchain .value").html(value);
// ===========================
// Storage (IPFS) example
// ===========================
$(document).ready(function() {
$("#storage .error").hide();
$("#status-storage").addClass('status-online');
$("#storage-controls").show();
$("#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) { })");
})
.catch(function(err) {
if (err) {
console.log("IPFS saveText Error => " + err.message);
}
});
});
$("#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) { })");
})
.catch(function(err) {
if (err) {
console.log("IPFS get Error => " + err.message);
}
});
});
$("#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) { })");
})
.catch(function(err) {
if (err) {
console.log("IPFS uploadFile Error => " + err.message);
}
});
});
$("#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() {
$("#communication .error").hide();
$("#communication .errorVersion").hide();
if (EmbarkJS.Messages.providerName === 'whisper') {
EmbarkJS.Messages.getWhisperVersion(function(err, _version) {
if (err) {
$("#communication .error").show();
$("#communication-controls").hide();
$("#status-communication").addClass('status-offline');
} else {
EmbarkJS.Messages.setProvider('whisper');
$("#status-communication").addClass('status-online');
}
});
}
$("#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]}).subscribe(function({data: 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 + "'})");
});
});
// /*global web3*/
// import React from 'react';
// import EmbarkJS from 'Embark/EmbarkJS';
// import {SimpleStorage, Test, SimpleStorageTest} from '../../embarkArtifacts/contracts';
//
// window.SimpleStorageTest = SimpleStorageTest;
//
// import ReactDOM from 'react-dom';
//
// import $ from 'jquery';
// import 'bootstrap/dist/css/bootstrap.css';
// import 'bootstrap/dist/css/bootstrap-theme.css';
// import 'bootstrap/dist/js/bootstrap.min.js';
//
// window.EmbarkJS = EmbarkJS;
// window.SimpleStorage = SimpleStorage;
// window.Test = Test;
// //window.Assert = Assert;
//
// window.React = React;
//
// import './foo.css';
//
// import App from './app.js';
//
// ReactDOM.render(<App />, document.getElementById('root'));
//
// var addToLog = function(id, txt) {
// $(id + " .logs").append("<br>" + txt);
// };
//
// // ===========================
// // Blockchain example
// // ===========================
// $(document).ready(function() {
// EmbarkJS.onReady((err) => {
// if (err) {
// console.error(err);
// }
// });
//
// console.log([1,2,3].map(v => v + 1));
//
// $("#blockchain button.set").click(function() {
// var value = parseInt($("#blockchain input.text").val(), 10);
//
// SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000});
// addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount, gas: 5300000})");
// });
//
// $("#blockchain button.get").click(function() {
// SimpleStorage.methods.get().call(function(err, value) {
// $("#blockchain .value").html(value);
// });
// addToLog("#blockchain", "SimpleStorage.methods.get(console.log)");
// });
//
// });
//
// // ===========================
// // Storage (IPFS) example
// // ===========================
// $(document).ready(function() {
// // automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
// //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
//
// $("#storage .error").hide();
// //EmbarkJS.Storage.ipfsConnection.version()
// // .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();
// // }
// // });
//
// $("#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) { })");
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS saveText Error => " + err.message);
// }
// });
// });
//
// $("#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) { })");
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS get Error => " + err.message);
// }
// });
// });
//
// $("#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) { })");
// })
// .catch(function(err) {
// if(err){
// console.log("IPFS uploadFile Error => " + err.message);
// }
// });
// });
//
// $("#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() {
//
// $("#communication .error").hide();
// $("#communication .errorVersion").hide();
// if (EmbarkJS.Messages.providerName === 'whisper') {
// EmbarkJS.Messages.getWhisperVersion(function(err, _version) {
// if (err) {
// $("#communication .error").show();
// $("#communication-controls").hide();
// $("#status-communication").addClass('status-offline');
// } else {
// EmbarkJS.Messages.setProvider('whisper');
// $("#status-communication").addClass('status-online');
// }
// });
// }
//
// $("#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]}).subscribe(function({data: 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 + "'})");
// });
//
// });
//

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
</browserconfig>

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -9,8 +9,10 @@
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="icon" type="image/png" href="%PUBLIC_URL%/logo-16.png?v=0.0.5" sizes="16x16" />
<link rel="icon" type="image/png" href="%PUBLIC_URL%/logo-32.png?v=0.0.5" sizes="32x32" />
<link rel="apple-touch-icon" sizes="180x180" href="%PUBLIC_URL%/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="%PUBLIC_URL%/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="%PUBLIC_URL%/favicon-16x16.png">
<link rel="mask-icon" href="%PUBLIC_URL%/safari-pinned-tab.svg" color="#5bbad5">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -0,0 +1,25 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="260.000000pt" height="260.000000pt" viewBox="0 0 260.000000 260.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.11, written by Peter Selinger 2001-2013
</metadata>
<g transform="translate(0.000000,260.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M0 1300 l0 -1300 347 0 c345 0 380 3 445 36 14 8 37 14 50 14 15 0
32 11 46 30 33 44 75 62 136 58 50 -3 52 -2 94 44 50 54 77 126 87 236 7 61 5
74 -12 99 -11 15 -37 59 -56 97 -20 38 -39 62 -41 55 -4 -12 -33 -136 -68
-296 -9 -37 -17 -53 -28 -53 -18 0 -53 134 -112 429 -37 182 -36 189 43 346
47 93 51 107 60 206 15 181 53 309 141 481 47 93 130 217 189 286 l29 33 0
-426 c0 -360 2 -429 15 -441 8 -8 39 -52 70 -98 76 -115 77 -125 17 -416 l-49
-235 38 -3 37 -3 7 -67 c11 -113 33 -178 77 -223 21 -22 43 -51 48 -64 6 -16
17 -25 30 -25 26 0 57 -16 86 -42 14 -13 24 -16 29 -9 3 6 21 11 40 11 25 0
39 -7 55 -27 l22 -28 364 -3 364 -3 0 1300 0 1301 -1300 0 -1300 0 0 -1300z
m1787 -257 c56 -121 55 -147 -23 -493 -49 -217 -53 -230 -69 -230 -8 0 -15 3
-15 8 0 4 -18 81 -41 172 -22 91 -40 170 -40 175 -1 6 13 46 30 90 42 106 71
231 78 333 l6 82 20 -32 c11 -18 35 -65 54 -105z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -70,7 +70,7 @@ class EmbarkController {
});
});
}
simulator(options) {
simulator(_options) {
// this.context = options.context || [constants.contexts.simulator, constants.contexts.blockchain];
// let simulator = new Simulator({
// blockchainConfig: this.config.blockchainConfig,
@ -169,6 +169,11 @@ simulator(options) {
plugin.registerActionForEvent("embark:engine:started", async (_params, cb) => {
try {
await engine.events.request2("blockchain:node:start", engine.config.blockchainConfig);
await Promise.all([
engine.events.request2("storage:node:start", engine.config.storageConfig),
engine.events.request2("communication:node:start", engine.config.communicationConfig),
engine.events.request2("namesystem:node:start", engine.config.namesystemConfig)
]);
} catch (e) {
return cb(e);
}
@ -757,7 +762,7 @@ simulator(options) {
}
], (err, passes, fails) => {
if(err) {
engine.logger.error(`Error occurred while running tests: ${ err.message || err}`);
engine.logger.error(`Error occurred while running tests: ${err.message || err}`);
}
process.exit(err || (fails > 0) ? 1 : 0);

View File

@ -3,42 +3,53 @@ import EmbarkJS from 'embarkjs';
<% for (let pluginName in (plugins['messages'] || [])) { %>
const __embark<%- pluginName %> = require('<%- plugins['messages'][pluginName] %>');
EmbarkJS.Messages.registerProvider('<%- pluginName %>', __embark<%- pluginName %>.default || __embark<%- pluginName %>);
<% }; %>
<% } %>
<% for (let pluginName in (plugins['storage'] || [])) { %>
const __embark<%- pluginName %> = require('<%- plugins['storage'][pluginName] %>');
EmbarkJS.Storage.registerProvider('<%- pluginName %>', __embark<%- pluginName %>.default || __embark<%- pluginName %>);
<% }; %>
<% } %>
<% for (let pluginName in (plugins['blockchain'] || [])) { %>
const __embark<%- pluginName %> = require('<%- plugins['blockchain'][pluginName] %>');
EmbarkJS.Blockchain.registerProvider('<%- pluginName %>', __embark<%- pluginName %>.default || __embark<%- pluginName %>);
<% }; %>
<% } %>
<% for (let pluginName in (plugins['names'] || [])) { %>
const __embark<%- pluginName %> = require('<%- plugins['names'][pluginName] %>');
EmbarkJS.Names.registerProvider('<%- pluginName %>', __embark<%- pluginName %>.default || __embark<%- pluginName %>);
<% }; %>
<% } %>
<% if (plugins['messages'] && Object.values(plugins['messages']).length > 0) { %>
const communicationConfig = require('./config/communication.json');
EmbarkJS.Messages.setProvider(communicationConfig.provider, communicationConfig.connection);
<% }; %>
<% } %>
<% if (plugins['storage'] && Object.values(plugins['storage']).length > 0) { %>
const storageConfig = require('./config/storage.json');
EmbarkJS.Storage.setProviders(storageConfig.dappConnection);
<% }; %>
<% } %>
<% if (plugins['blockchain'] && Object.values(plugins['blockchain']).length > 0) { %>
const blockchainConfig = require('./config/blockchain.json');
EmbarkJS.Blockchain.setProvider(blockchainConfig.provider, {});
EmbarkJS.Blockchain.connect(blockchainConfig, (err) => {if (err) { console.error(err); } });
<% }; %>
<% } %>
<% if (plugins['names'] && Object.values(plugins['names']).length > 0) { %>
const namesConfig = require('./config/namesystem.json');
EmbarkJS.Names.setProvider(namesConfig.provider, namesConfig);
<% }; %>
<% } %>
<% if (hasWebserver) { %>
if (typeof WebSocket !== 'undefined') {
const ws = new WebSocket(`${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.hostname}:${location.port}`);
ws.addEventListener('message', (evt) => {
if (evt.data === 'outputDone') {
location.reload(true);
}
});
}
<% } %>
export default EmbarkJS;

View File

@ -14,6 +14,7 @@ class EmbarkJS {
this.embarkConfig = embark.config.embarkConfig;
this.events = embark.events;
this.logger = embark.logger;
this.contractArtifacts = {};
this.events.request("runcode:whitelist", 'embarkjs', () => {
this.registerEmbarkJS();
@ -35,6 +36,7 @@ class EmbarkJS {
this.events.setCommandHandler("embarkjs:contract:runInVm", this.runInVm.bind(this));
embark.registerActionForEvent("pipeline:generateAll:before", this.addEmbarkJSArtifact.bind(this));
embark.registerActionForEvent("pipeline:generateAll:before", this.addContractIndexArtifact.bind(this));
}
async registerEmbarkJS() {
@ -64,7 +66,7 @@ class EmbarkJS {
}
addEmbarkJSArtifact(_params, cb) {
let embarkjsCode = Templates.embarkjs_artifact({ plugins: this.embarkJSPlugins });
const embarkjsCode = Templates.embarkjs_artifact({ plugins: this.embarkJSPlugins, hasWebserver: this.embark.config.webServerConfig.enabled });
// TODO: generate a .node file
this.events.request("pipeline:register", {
@ -96,6 +98,7 @@ class EmbarkJS {
async addContractArtifact(contract, cb) {
const abi = JSON.stringify(contract.abiDefinition);
const gasLimit = 6000000;
this.contractArtifacts[contract.className] = contract.className + '.js';
const contractCode = Templates.embarkjs_contract_artifact({ className: contract.className, abi: abi, contract: contract, gasLimit: gasLimit });
@ -107,6 +110,21 @@ class EmbarkJS {
}, cb);
}
async addContractIndexArtifact(_options, cb) {
let indexCode = 'module.exports = {';
Object.keys(this.contractArtifacts).forEach(className => {
indexCode += `\n"${className}": require('./${this.contractArtifacts[className]}').default,`;
});
indexCode += `\n};`;
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'contracts'],
file: 'index.js',
format: 'js',
content: indexCode
}, cb);
}
async runInVm(contract, cb) {
const abi = contract.abiDefinition;
const gasLimit = 6000000;

View File

@ -162,35 +162,40 @@ __embarkENS.setProvider = function(config) {
self.ready = false;
// FIXME EmbarkJS.onReady doesn't work. Possibility of a race condition
EmbarkJS.Blockchain.blockchainConnector.getNetworkId()
.then((id) => {
const registryAddress = self.registryAddresses[id] || config.registryAddress;
self._isAvailable = true;
self.ens = new EmbarkJS.Blockchain.Contract({
abi: config.registryAbi,
address: registryAddress,
web3: EmbarkJS.Blockchain.blockchainConnector.getInstance()
EmbarkJS.onReady(err => {
if (err) {
throw new Error(err);
}
EmbarkJS.Blockchain.blockchainConnector.getNetworkId()
.then((id) => {
const registryAddress = self.registryAddresses[id] || config.registryAddress;
self._isAvailable = true;
self.ens = new EmbarkJS.Blockchain.Contract({
abi: config.registryAbi,
address: registryAddress,
web3: EmbarkJS.Blockchain.blockchainConnector.getInstance()
});
self.registrar = new EmbarkJS.Blockchain.Contract({
abi: config.registrarAbi,
address: config.registrarAddress,
web3: EmbarkJS.Blockchain.blockchainConnector.getInstance()
});
self.resolver = new EmbarkJS.Blockchain.Contract({
abi: config.resolverAbi,
address: config.resolverAddress,
web3: EmbarkJS.Blockchain.blockchainConnector.getInstance()
});
self.ready = true;
})
.catch(err => {
self.ready = true;
if (err.message.indexOf('Provider not set or invalid') > -1) {
console.warn(ERROR_MESSAGE);
return;
}
console.error(err);
});
self.registrar = new EmbarkJS.Blockchain.Contract({
abi: config.registrarAbi,
address: config.registrarAddress,
web3: EmbarkJS.Blockchain.blockchainConnector.getInstance()
});
self.resolver = new EmbarkJS.Blockchain.Contract({
abi: config.resolverAbi,
address: config.resolverAddress,
web3: EmbarkJS.Blockchain.blockchainConnector.getInstance()
});
self.ready = true;
})
.catch(err => {
self.ready = true;
if (err.message.indexOf('Provider not set or invalid') > -1) {
console.warn(ERROR_MESSAGE);
return;
}
console.error(err);
});
});
};
__embarkENS.waitForProviderReady = function() {

View File

@ -28,12 +28,16 @@ export default class Namesystem {
embark.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this));
}
addArtifactFile(_params, cb) {
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'namesystem.json',
format: 'json',
content: this.namesystemConfig
}, cb);
async addArtifactFile(_params, cb) {
// FIXME this shouldn't be done as the stack component calls the plugins
// FIXME this will be refactored along with the ENS plugin refactor
this.events.request("ens:config", (config) => {
this.events.request("pipeline:register", {
path: [this.embarkConfig.generationDir, 'config'],
file: 'namesystem.json',
format: 'json',
content: Object.assign({}, this.namesystemConfig, config)
}, cb);
});
}
}

View File

@ -21198,6 +21198,7 @@ websocket-extensions@>=0.1.1:
dependencies:
debug "^2.2.0"
es5-ext "^0.10.50"
gulp "^4.0.2"
nan "^2.14.0"
typedarray-to-buffer "^3.1.5"
yaeti "^0.0.6"