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

Commit 0424284

Browse files
author
Paul D Handy
committed
webgl: fallback to ccurl
1 parent 4ff533a commit 0424284

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

app/js/ccurl-interface.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
var ffi = require('ffi');
22
var isInitialized = false;
33

4-
const libcurl = require('curl.lib.js');
5-
libcurl.init();
4+
let libcurl = require('curl.lib.js');
5+
let webglAvailable = false;
6+
try {
7+
libcurl.init();
8+
webglAvailable = true;
9+
} catch (e) {}
610
const MAX_TIMESTAMP_VALUE = (Math.pow(3,27) - 1) / 2;
711

812
var ccurlProvider = function(ccurlPath) {
@@ -162,7 +166,20 @@ var ccurlHashing = function(libccurl, trunkTransaction, branchTransaction, minWe
162166
var newTrytes = iotaObj.utils.transactionTrytes(txObject);
163167

164168
switch (connection.ccurl) {
165-
case 1: {
169+
case 0: {
170+
libcurl.pow({trytes: newTrytes, minWeight: minWeightMagnitude}).then(function(nonce) {
171+
var returnedTrytes = newTrytes.substr(0, 2673-81).concat(nonce);
172+
var newTxObject= iotaObj.utils.transactionObject(returnedTrytes);
173+
174+
// Assign the previousTxHash to this tx
175+
var txHash = newTxObject.hash;
176+
previousTxHash = txHash;
177+
178+
finalBundleTrytes.push(returnedTrytes);
179+
callback(null);
180+
}).catch(callback);
181+
}
182+
default: {
166183
// cCurl updates the nonce as well as the transaction hash
167184
libccurl.ccurl_pow.async(newTrytes, minWeightMagnitude, function(error, returnedTrytes) {
168185

@@ -182,20 +199,6 @@ var ccurlHashing = function(libccurl, trunkTransaction, branchTransaction, minWe
182199

183200
return callback(null);
184201
});
185-
break;
186-
}
187-
default: {
188-
libcurl.pow({trytes: newTrytes, minWeight: minWeightMagnitude}).then(function(nonce) {
189-
var returnedTrytes = newTrytes.substr(0, 2673-81).concat(nonce);
190-
var newTxObject= iotaObj.utils.transactionObject(returnedTrytes);
191-
192-
// Assign the previousTxHash to this tx
193-
var txHash = newTxObject.hash;
194-
previousTxHash = txHash;
195-
196-
finalBundleTrytes.push(returnedTrytes);
197-
callback(null);
198-
}).catch(callback);
199202
}
200203
}
201204
}

app/js/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ String.prototype.escapeHTML = function() {
1616
});
1717
}
1818

19+
let webglAvailable = false;
20+
try {
21+
require('curl.lib.js').init();
22+
webglAvailable = true;
23+
} catch (e) {}
24+
25+
1926
var UI = (function(UI, undefined) {
2027
var showQuitAlert = false;
2128
var isInitialized = false;
@@ -598,11 +605,10 @@ var UI = (function(UI, undefined) {
598605
config.minWeightMagnitude = parseInt(document.getElementById("server_config_min_weight_magnitude").value, 10);
599606

600607
var selectCurl = document.getElementById("server_config_curl_implementation_select")
601-
if (selectCurl) {
602-
config.ccurl = selectCurl.options[selectCurl.selectedIndex].value === 'ccurl' ? 1 : 0;
603-
}
604-
else {
605-
config.ccurl = 0;
608+
if (selectCurl && webglAvailable) {
609+
config.ccurl = selectCurl.options[selectCurl.selectedIndex].value === 'ccurl' ? 1 : 0;
610+
} else {
611+
config.ccurl = 1;
606612
}
607613

608614
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"url": "https://github.com/iotaledger/wallet"
2929
},
3030
"dependencies": {
31-
"curl.lib.js": "^1.0.21",
31+
"curl.lib.js": "^1.0.22",
3232
"ffi": "^2.2.0",
3333
"fs-extra": "^1.0.0",
3434
"glob": "^7.1.2",

package.testnet.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"url": "https://github.com/iotaledger/wallet"
2929
},
3030
"dependencies": {
31-
"curl.lib.js": "^1.0.21",
31+
"curl.lib.js": "^1.0.22",
3232
"ffi": "^2.2.0",
3333
"fs-extra": "^1.0.0",
3434
"glob": "^7.1.2",

0 commit comments

Comments
 (0)