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>
<textarea id="message"></textarea>
<br>
<input placeholder="Difficulty" id="difficulty" type="number">
<br><br>
<button id="generate">Generate Block</button>
<br>
<br>
<h2>Output</h2>
<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>
</html>

16
main.js
View File

@ -1,25 +1,37 @@
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').setAttribute("disabled", true)
document.getElementById('output').value = "computing..."
var metadata = {
"meta": {
"type": document.getElementById("type")
"type": document.getElementById("type").value
},
"time": 0
"time": getEpoch()
}
// todo web workers
var data = document.getElementById('message').value
var postData = {
"data": data,
"metadata": metadata,
"difficulty": parseInt(document.getElementById("difficulty").value)
}
startTime = getEpoch()
worker.postMessage(JSON.stringify(postData))
}
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 += new TextDecoder("utf-8").decode(e.data)
})

View File

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