demo now has more output and settings

This commit is contained in:
Kevin Froman 2020-09-28 01:02:48 +00:00
parent 1d53c5054f
commit 052a4742cf
3 changed files with 20 additions and 4 deletions

View File

@ -24,11 +24,15 @@ Contents:
<br> <br>
<textarea id="message"></textarea> <textarea id="message"></textarea>
<br> <br>
<input placeholder="Difficulty" id="difficulty" type="number">
<br><br>
<button id="generate">Generate Block</button> <button id="generate">Generate Block</button>
<br> <br>
<br> <br>
<h2>Output</h2> <h2>Output</h2>
<br> <br>
<textarea id="output" cols=75 rows=50></textarea> <input type="text" id="timeResult" placeholder="Time taken" readonly>
<br><br>
<textarea id="output" cols="75" rows="50" readonly></textarea>
</body> </body>
</html> </html>

16
main.js
View File

@ -1,25 +1,37 @@
var worker = new Worker("./powworker.js") var worker = new Worker("./powworker.js")
var startTime = 0;
function getEpoch(){
return Math.floor((new Date).getTime()/1000)
}
document.getElementById('generate').onclick = function(){ document.getElementById('generate').onclick = function(){
document.getElementById('generate').setAttribute("disabled", true)
document.getElementById('output').value = "computing..." document.getElementById('output').value = "computing..."
var metadata = { var metadata = {
"meta": { "meta": {
"type": document.getElementById("type") "type": document.getElementById("type").value
}, },
"time": 0 "time": getEpoch()
} }
// todo web workers // todo web workers
var data = document.getElementById('message').value var data = document.getElementById('message').value
var postData = { var postData = {
"data": data, "data": data,
"metadata": metadata, "metadata": metadata,
"difficulty": parseInt(document.getElementById("difficulty").value)
} }
startTime = getEpoch()
worker.postMessage(JSON.stringify(postData)) worker.postMessage(JSON.stringify(postData))
} }
worker.addEventListener('message', function(e) { worker.addEventListener('message', function(e) {
var finishTime = getEpoch() - startTime
document.getElementById('generate').removeAttribute("disabled")
document.getElementById('timeResult').value = finishTime + "s"
document.getElementById('output').value = doHashHex(e.data) + "\n" document.getElementById('output').value = doHashHex(e.data) + "\n"
document.getElementById('output').value += new TextDecoder("utf-8").decode(e.data) document.getElementById('output').value += new TextDecoder("utf-8").decode(e.data)
}) })

View File

@ -7,6 +7,6 @@ self.addEventListener('message', function(e) {
doPow( doPow(
data.metadata, data.metadata,
data.data, data.data,
2 data.difficulty
)); ));
}, false); }, false);