Permalink
Browse files

Added missing files for local PoW

  • Loading branch information...
jaimehgb committed Feb 9, 2018
1 parent e5b56c6 commit 55c03e936699bbad0e8ad5e09933275b7ce60f96
@@ -8,7 +8,9 @@ elixir(function(mix) {
'../../../node_modules/scrollreveal/src/scrollreveal.js',
'../../../node_modules/jquery-toast-plugin/dist/jquery.toast.min.js',
'resources/assets/js/creative.js',
'Logger.js'
'Logger.js',
'pow.js',
'startThreads.js'
], 'public/js/app.js')
.browserify('custom.js')
.styles([
@@ -28,5 +30,8 @@ elixir(function(mix) {
.copy('vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.svg', 'public/fonts/glyphicons-halflings-regular.svg')
.copy('vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.ttf', 'public/fonts/glyphicons-halflings-regular.ttf')
.copy('vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff', 'public/fonts/glyphicons-halflings-regular.woff')
.copy('vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff2', 'public/fonts/glyphicons-halflings-regular.woff2');
.copy('vendor/twbs/bootstrap/fonts/glyphicons-halflings-regular.woff2', 'public/fonts/glyphicons-halflings-regular.woff2')
.copy('resources/assets/js/thread.js', 'public/js/thread.js')
.copy('resources/assets/js/pow.js', 'public/js/pow.js')
.copy('resources/assets/js/pow.wasm', 'public/pow.wasm');
});
BIN +43.8 KB public/pow.wasm
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -0,0 +1,44 @@
var pow_initiate = function(threads, worker_path) {
if (typeof worker_path == 'undefined') { worker_path = ''; }
if (isNaN(threads)) { threads = self.navigator.hardwareConcurrency - 1; }
var workers = [];
for (let i = 0; i < threads; i++) {
workers[i] = new Worker(worker_path + 'thread.js');
}
return workers;
}
var pow_start = function(workers, hash) {
if ((hash instanceof Uint8Array) && (hash.length == 32)) {
var threads = workers.length;
for (let i = 0; i < threads; i++) {
workers[i].postMessage(hash);
}
}
}
var pow_terminate = function(workers) {
var threads = workers.length;
for (let i = 0; i < threads; i++) {
workers[i].terminate();
}
}
var pow_callback = function(workers, hash, ready, callback) {
if ( (hash.length == 64) && (typeof callback == 'function')) {
var threads = workers.length;
for (let i = 0; i < threads; i++) {
workers[i].onmessage = function(e) {
result = e.data;
if(result == 'ready') {
workers[i].postMessage(hash);
ready();
} else if (result !== false && result != "0000000000000000") {
pow_terminate (workers);
callback (result);
}
else workers[i].postMessage(hash);
}
}
}
}
@@ -0,0 +1,24 @@
self.importScripts('pow.js');
var ready = false;
Module['onRuntimeInitialized'] = function() {
postMessage('ready');
}
onmessage = function(ev)
{
var PoW = Module.cwrap("launchPoW", 'string', ['string']);
var hash = ev.data;
//let generate = Module.ccall("launchPoW", 'string', ['string'], hash);
let generate = PoW(hash);
if (generate != "0000000000000000") {
console.log(generate +" found");
postMessage(generate); // Worker return
}
else
{
postMessage(false);
}
}

0 comments on commit 55c03e9

Please sign in to comment.