Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 30c724d

Browse files
author
domschiener
committed
Merge branch 'dev'
2 parents 952462f + 87632af commit 30c724d

34 files changed

+1196
-642
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
npm install -g bower
1717
```
1818

19+
#### Windows Users Only
20+
21+
Run the following command as Administrator:
22+
23+
```
24+
npm install -g --production windows-build-tools
25+
```
26+
1927
#### Compiling
2028

2129
If you wish to compile the app, install the following also:

app/css/style.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ body.new-user-active #new-user {
304304
font-weight: bold;
305305
}
306306

307-
#status-bar-milestone, #status-bar-solid-milestone {
307+
body.full-node #status-bar-milestone, body.full-node #status-bar-solid-milestone {
308308
cursor: pointer;
309309
}
310310

@@ -537,4 +537,8 @@ body.new-user-active #new-user {
537537
height: 1.1rem;
538538
background: #fff;
539539
cursor: pointer;
540+
}
541+
542+
.error {
543+
color: red;
540544
}

app/js/ccurl-interface.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
var ffi = require('ffi');
2+
3+
var ccurlProvider = function(ccurlPath) {
4+
5+
if (!ccurlPath) ccurlPath = __dirname;
6+
7+
var fullPath = ccurlPath + '/libccurl';
8+
9+
// Define libccurl to be used for finding the nonce
10+
return ffi.Library(fullPath, {
11+
ccurl_pow : [ 'string', [ 'string', 'int'] ]
12+
});
13+
}
14+
15+
var ccurlHashing = function(libccurl, trunkTransaction, branchTransaction, minWeightMagnitude, trytes, callback) {
16+
17+
// inputValidator: Check if correct hash
18+
if (!iota.validate.isHash(trunkTransaction)) {
19+
20+
return callback(new Error("Invalid trunkTransaction"));
21+
}
22+
23+
// inputValidator: Check if correct hash
24+
if (!iota.validate.isHash(branchTransaction)) {
25+
26+
return callback(new Error("Invalid branchTransaction"));
27+
}
28+
29+
// inputValidator: Check if int
30+
if (!iota.validate.isInt(minWeightMagnitude)) {
31+
32+
return callback(new Error("Invalid minWeightMagnitude"));
33+
}
34+
35+
// inputValidator: Check if array of trytes
36+
// if (!iota.validate.isArrayOfTrytes(trytes)) {
37+
//
38+
// return callback(new Error("Invalid trytes supplied"));
39+
// }
40+
41+
var finalBundleTrytes = [];
42+
var previousTxHash;
43+
var i = 0;
44+
45+
function loopTrytes() {
46+
47+
getBundleTrytes(trytes[i], function(error) {
48+
49+
if (error) {
50+
51+
return callback(error);
52+
53+
} else {
54+
55+
i++;
56+
57+
if (i < trytes.length) {
58+
59+
loopTrytes();
60+
61+
} else {
62+
63+
// reverse the order so that it's ascending from currentIndex
64+
return callback(null, finalBundleTrytes.reverse());
65+
66+
}
67+
}
68+
});
69+
}
70+
71+
function getBundleTrytes(thisTrytes, callback) {
72+
// PROCESS LOGIC:
73+
// Start with last index transaction
74+
// Assign it the trunk / branch which the user has supplied
75+
// IF there is a bundle, chain the bundle transactions via
76+
// trunkTransaction together
77+
78+
// If this is the first transaction, to be processed
79+
// Make sure that it's the last in the bundle and then
80+
// assign it the supplied trunk and branch transactions
81+
if (!previousTxHash) {
82+
83+
var txObject = iota.utils.transactionObject(thisTrytes);
84+
85+
// Check if last transaction in the bundle
86+
if (txObject.lastIndex !== txObject.currentIndex) {
87+
return callback(new Error("Wrong bundle order. The bundle should be ordered in descending order from currentIndex"));
88+
}
89+
90+
txObject.trunkTransaction = trunkTransaction;
91+
txObject.branchTransaction = branchTransaction;
92+
93+
var newTrytes = iota.utils.transactionTrytes(txObject);
94+
95+
// cCurl updates the nonce as well as the transaction hash
96+
libccurl.ccurl_pow.async(newTrytes, minWeightMagnitude, function(error, returnedTrytes) {
97+
98+
if (error) {
99+
return callback(error);
100+
}
101+
102+
var newTxObject= iota.utils.transactionObject(returnedTrytes);
103+
104+
// Assign the previousTxHash to this tx
105+
var txHash = newTxObject.hash;
106+
previousTxHash = txHash;
107+
108+
finalBundleTrytes.push(returnedTrytes);
109+
110+
return callback(null);
111+
});
112+
113+
} else {
114+
115+
var txObject = iota.utils.transactionObject(thisTrytes);
116+
117+
// Chain the bundle together via the trunkTransaction (previous tx in the bundle)
118+
// Assign the supplied trunkTransaciton as branchTransaction
119+
txObject.trunkTransaction = previousTxHash;
120+
txObject.branchTransaction = trunkTransaction;
121+
122+
var newTrytes = iota.utils.transactionTrytes(txObject);
123+
124+
// cCurl updates the nonce as well as the transaction hash
125+
libccurl.ccurl_pow.async(newTrytes, minWeightMagnitude, function(error, returnedTrytes) {
126+
127+
if (error) {
128+
129+
return callback(error);
130+
}
131+
132+
var newTxObject= iota.utils.transactionObject(returnedTrytes);
133+
134+
// Assign the previousTxHash to this tx
135+
var txHash = newTxObject.hash;
136+
previousTxHash = txHash;
137+
138+
finalBundleTrytes.push(returnedTrytes);
139+
140+
return callback(null);
141+
});
142+
}
143+
}
144+
145+
loopTrytes();
146+
}
147+
148+
module.exports = {
149+
'ccurlProvider': ccurlProvider,
150+
'ccurlHashing': ccurlHashing
151+
}

app/js/index.js

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var UI = (function(UI, undefined) {
2121
var callNodeStarted = false;
2222
var serverLogLines = 0;
2323
var webviewIsLoaded = false;
24+
var lightWallet = false;
2425
var webview;
2526

2627
UI.initialize = function() {
@@ -33,6 +34,7 @@ var UI = (function(UI, undefined) {
3334
var params = new URLSearchParams(location.search.slice(1));
3435
showStatusBar = params.get("showStatus") == 1;
3536
isFirstRun = params.get("isFirstRun") == 1;
37+
lightWallet = parseInt(params.get("lightWallet"), 10) == 1;
3638
}
3739

3840
if (isFirstRun) {
@@ -50,13 +52,17 @@ var UI = (function(UI, undefined) {
5052
callNodeStarted = false;
5153
}
5254

53-
document.getElementById("status-bar-milestone").addEventListener("click", function(e) {
54-
electron.ipcRenderer.send("showServerLog");
55-
});
55+
if (!lightWallet) {
56+
document.body.className += " full-node";
57+
document.getElementById("status-bar-milestone").addEventListener("click", function(e) {
58+
electron.ipcRenderer.send("showServerLog");
59+
});
60+
61+
document.getElementById("status-bar-solid-milestone").addEventListener("click", function(e) {
62+
electron.ipcRenderer.send("showServerLog");
63+
});
64+
}
5665

57-
document.getElementById("status-bar-solid-milestone").addEventListener("click", function(e) {
58-
electron.ipcRenderer.send("showServerLog");
59-
});
6066

6167
document.getElementById("new-user").addEventListener("click", function(e) {
6268
UI.sendToWebview("openHelpMenu");
@@ -115,16 +121,6 @@ var UI = (function(UI, undefined) {
115121
return false;
116122
},false);
117123

118-
webview.addEventListener("drop",function(e, b) {
119-
if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files[0] && e.dataTransfer.files[0].path) {
120-
if (String(e.dataTransfer.files[0].path).match(/IRI.*\.jar$/i)) {
121-
electron.ipcRenderer.send("upgradeIRI", e.dataTransfer.files[0].path);
122-
}
123-
}
124-
e.preventDefault();
125-
return false;
126-
},false);
127-
128124
//also "dom-ready"
129125
webview.addEventListener("did-finish-load", UI.webviewDidFinishLoad());
130126

@@ -349,13 +345,10 @@ var UI = (function(UI, undefined) {
349345
*/
350346

351347
modal.setContent("<h1>Preferences</h1>" +
352-
"<div class='input-group input-group'><label>Java Arguments:</label>" +
353-
"<input type='text' name='java_args' id='preferences_java_args' placeholder='Command Line Parameters' value='" + (settings.javaArgs ? String(settings.javaArgs).escapeHTML() : "") + "' /></div>" +
354348
(process.platform != "linux" ? "<div class='input-group input-group-last'><label class='label--checkbox'><input type='checkbox' name='open_at_login' id='preferences_open_at_login' class='checkbox' value='1'" + (settings.openAtLogin ? " checked='checked'" : "") + " />Open at Login</label>" : ""));
355349

356350
modal.addFooterBtn("Save", "tingle-btn tingle-btn--primary", function() {
357351
var settings = {};
358-
settings.javaArgs = String(document.getElementById("preferences_java_args").value).trim();
359352

360353
if (process.platform != "linux") {
361354
settings.openAtLogin = document.getElementById("preferences_open_at_login").checked;
@@ -419,7 +412,7 @@ var UI = (function(UI, undefined) {
419412
var modalContent = document.querySelector(".tingle-modal-box__content");
420413
modalContent.appendChild(close);
421414

422-
var el = document.getElementById("server_config_port");
415+
var el = document.getElementById(configuration.lightWallet ? "server_config_host" : "server_config_port");
423416

424417
var temp = el.value;
425418
el.value = "";
@@ -428,22 +421,51 @@ var UI = (function(UI, undefined) {
428421
}
429422
});
430423

431-
modal.setContent("<h1>Server Config</h1>" +
432-
"<div class='input-group'><label>Server Port:</label>" +
433-
"<input type='number' min='1024' name='port' id='server_config_port' placeholder='' value='" + (configuration.port ? String(configuration.port).escapeHTML() : "14265") + "' /></div>" +
434-
"<div class='input-group'><label>Depth:</label>" +
435-
"<input type='number' min='1' name='depth' id='server_config_depth' placeholder='' value='" + (configuration.depth ? String(configuration.depth).escapeHTML() : "3") + "' /></div>" +
436-
"<div class='input-group'><label>Min Weight Magnitude:</label>" +
437-
"<input type='number' min='" + (configuration.testNet ? "13" : "18") + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + (configuration.minWeightMagnitude ? String(configuration.minWeightMagnitude).escapeHTML() : (configuration.testNet ? "13": "18")) + "' /></div>" +
438-
"<div class='input-group input-group'><label>Neighboring Nodes:</label>" +
439-
"<textarea name='neighboring_nodes' id='server_config_neighboring_nodes' style='width:100%;height:150px;' placeholder='Add nodes in the following format (one per line):\r\n\r\nudp://ip:12345'>" + String(configuration.nodes).escapeHTML() + "</textarea></div>");
424+
var content = "";
425+
426+
if (configuration.lightWallet) {
427+
content = "<h1>Node Config</h1>" +
428+
"<div class='input-group'><label>Host: <span class='error' id='host-error'></span></label>" +
429+
"<input type='text' id='server_config_host' placeholder='' value='" + (configuration.lightWalletHost ? String(configuration.lightWalletHost).escapeHTML() + (configuration.lightWalletPort ? ":" + String(configuration.lightWalletPort).escapeHTML() : "") : "") + "' /></div>" +
430+
"<div class='input-group'><label>Min Weight Magnitude:</label>" +
431+
"<input type='number' min='" + (configuration.testNet ? "13" : "18") + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + (configuration.minWeightMagnitude ? String(configuration.minWeightMagnitude).escapeHTML() : (configuration.testNet ? "13": "18")) + "' /></div>";
432+
} else {
433+
content = "<h1>Node Config</h1>" +
434+
"<div class='input-group'><label>Node Port:</label>" +
435+
"<input type='number' min='1024' name='port' id='server_config_port' placeholder='' value='" + (configuration.port ? String(configuration.port).escapeHTML() : "14265") + "' /></div>" +
436+
"<div class='input-group'><label>Depth:</label>" +
437+
"<input type='number' min='1' name='depth' id='server_config_depth' placeholder='' value='" + (configuration.depth ? String(configuration.depth).escapeHTML() : "3") + "' /></div>" +
438+
"<div class='input-group'><label>Min Weight Magnitude:</label>" +
439+
"<input type='number' min='" + (configuration.testNet ? "13" : "18") + "' name='min_weight_magnitude' id='server_config_min_weight_magnitude' placeholder='' value='" + (configuration.minWeightMagnitude ? String(configuration.minWeightMagnitude).escapeHTML() : (configuration.testNet ? "13": "18")) + "' /></div>" +
440+
"<div class='input-group input-group'><label>Neighboring Nodes:</label>" +
441+
"<textarea name='neighboring_nodes' id='server_config_neighboring_nodes' style='width:100%;height:150px;' placeholder='Add nodes in the following format (one per line):\r\n\r\nudp://ip:12345'>" + String(configuration.nodes).escapeHTML() + "</textarea></div>";
442+
}
443+
444+
modal.setContent(content);
440445

441446
modal.addFooterBtn("Save", "tingle-btn tingle-btn--primary", function() {
442-
var config = {};
443-
config.port = parseInt(document.getElementById("server_config_port").value, 10);
444-
config.depth = parseInt(document.getElementById("server_config_depth").value, 10);
445-
config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
446-
config.nodes = document.getElementById("server_config_neighboring_nodes").value;
447+
var config = {};
448+
449+
config.lightWallet = configuration.lightWallet;
450+
451+
if (configuration.lightWallet) {
452+
var res = String(document.getElementById("server_config_host").value).match(/^(https?:\/\/.*):([0-9]+)$/i);
453+
454+
if (!res) {
455+
document.getElementById("host-error").style.display = "inline";
456+
document.getElementById("host-error").innerHTML = "Invalid!";
457+
return;
458+
}
459+
460+
config.lightWalletHost = res[1];
461+
config.lightWalletPort = res[2];
462+
config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
463+
} else {
464+
config.port = parseInt(document.getElementById("server_config_port").value, 10);
465+
config.depth = parseInt(document.getElementById("server_config_depth").value, 10);
466+
config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
467+
config.nodes = document.getElementById("server_config_neighboring_nodes").value;
468+
}
447469

448470
modal.close();
449471

@@ -629,9 +651,9 @@ var UI = (function(UI, undefined) {
629651
}
630652
}
631653

632-
UI.notify = function(type, message) {
654+
UI.notify = function(type, message, options) {
633655
if (webviewIsLoaded && webview) {
634-
webview.send("notify", type, message);
656+
webview.send("notify", type, message, options);
635657
}
636658
}
637659

@@ -643,7 +665,9 @@ var UI = (function(UI, undefined) {
643665
if (url == "config" || url == "configuration" || url == "setup") {
644666
electron.ipcRenderer.send("editNodeConfiguration");
645667
} else if (url == "log") {
646-
electron.ipcRenderer.send("showServerLog");
668+
if (!lightWallet) {
669+
electron.ipcRenderer.send("showServerLog");
670+
}
647671
} else if (url == "nodeinfo" || url == "node") {
648672
UI.sendToWebview("showNodeInfo");
649673
} else if (url == "peers") {
@@ -652,12 +676,16 @@ var UI = (function(UI, undefined) {
652676
UI.sendToWebview("showNetworkSpammer");
653677
} else if (url == "generateseed" || url == "seed") {
654678
UI.sendToWebview("generateSeed");
679+
} else if (url == "claim") {
680+
UI.sendToWebview("showClaimProcess");
655681
} else if (url == "faq") {
656682
UI.sendToWebview("faq");
657683
} else {
658684
var match = url.match(/(?:addnode|addneighbou?r)\/(.*)/i);
659685
if (match && match[1] && match[1].charAt(0) != "-") {
660-
UI.addNeighborNode(match[1]);
686+
if (!lightWallet) {
687+
UI.addNeighborNode(match[1]);
688+
}
661689
} else {
662690
UI.sendToWebview("handleURL", url);
663691
}
@@ -799,6 +827,10 @@ electron.ipcRenderer.on("showClaimProcess", function() {
799827
UI.sendToWebview("showClaimProcess");
800828
});
801829

830+
electron.ipcRenderer.on("addAndRemoveNeighbors", function(event, addedNodes, removedNodes) {
831+
UI.sendToWebview("addAndRemoveNeighbors", {"add": addedNodes, "remove": removedNodes});
832+
});
833+
802834
electron.ipcRenderer.on("editNodeConfiguration", function(event, serverConfiguration) {
803835
UI.editNodeConfiguration(serverConfiguration);
804836
});
@@ -817,8 +849,8 @@ electron.ipcRenderer.on("hoverAmountStop", function() {
817849
UI.updateStatusBar({"hoverAmount": -1});
818850
});
819851

820-
electron.ipcRenderer.on("notify", function(event, type, msg) {
821-
UI.notify(type, msg);
852+
electron.ipcRenderer.on("notify", function(event, type, message, options) {
853+
UI.notify(type, message, options);
822854
});
823855

824856
electron.ipcRenderer.on("relaunch", UI.relaunch);

0 commit comments

Comments
 (0)