You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
const useCapture = true; // capture, bubbling: false
|
|
|
|
button = document.getElementsByTagName('button')[0];
|
|
button.addEventListener('click',hashcash,false);
|
|
button.addEventListener('submit',hashcash,false);
|
|
console.log(button)
|
|
|
|
function hashcash(ev) {
|
|
console.log('hashcash.ev: %o',ev);
|
|
let algo = document.getElementsByName('algo')[0].value;
|
|
let data = document.getElementsByName('data')[0].value;
|
|
let nonce = document.getElementsByName('nonce')[0].value || '12131054600136590020';
|
|
let dif = document.getElementsByName('dif')[0].value;
|
|
let url = api_url + `hashcash?a=${algo}&b=${data}&n=${nonce}&d=${dif}`
|
|
document.getElementById('pow').innerText = 'no-proof';
|
|
let promised = fetch(url).
|
|
then(resp => resp.json()).
|
|
then(obj => {
|
|
console.log('pow.hashcash.obj:',obj);
|
|
document.getElementsByName('hashcash')[0].innerText = '0x'+obj.hash;
|
|
document.getElementsId('pow').innerText = obj.pow;
|
|
|
|
}).
|
|
catch(console.error);
|
|
}
|
|
|
|
let url = api_url + 'config';
|
|
|
|
let promised = fetch(url).
|
|
then(resp => resp.json()).
|
|
then(obj => {
|
|
console.log('pow.obj.config:',obj.config);
|
|
let dif = obj.config.difficulty
|
|
console.log('pow.dif:',dif);
|
|
let elem = document.getElementById('dif');
|
|
elem.innerText = dif;
|
|
//let buf = elem.innerHTML; buf = buf.replace(':dif',dif); elem.innerHTML = buf;
|
|
elem = document.getElementsByName('dif')[0];
|
|
elem.value = dif;
|
|
return obj.config
|
|
}).
|
|
catch(console.error)
|
|
|