Added ability of getBlockHeader control to send either height or hash

This commit is contained in:
Jakub Matys 2018-03-23 13:26:24 +01:00
parent d35dd77695
commit e8399cb485

View File

@ -102,17 +102,22 @@
} }
function getBlockHeader() { function getBlockHeader() {
var height = document.getElementById('getBlockHeaderHeight').value; var param = document.getElementById('getBlockHeaderParam').value;
lookupBlockHash(parseInt(height), function (result) { lookupBlockHash(isHash(param) ? param : parseInt(param), function (result) {
console.log('getBlockHeader sent successfully'); console.log('getBlockHeader sent successfully');
console.log(result); console.log(result);
document.getElementById('getBlockHeaderResult').innerText = JSON.stringify(result).replace(/,/g, ", "); document.getElementById('getBlockHeaderResult').innerText = JSON.stringify(result).replace(/,/g, ", ");
}); });
} }
function lookupBlockHash(height, f) { function isHash(str) {
var re = /[0-9A-Fa-f]{64}/g;
return re.test(str);
}
function lookupBlockHash(heightOrHash, f) {
const method = 'getBlockHeader'; const method = 'getBlockHeader';
const params = [height]; const params = [heightOrHash];
return socket.send({ method, params }, f); return socket.send({ method, params }, f);
} }
@ -277,7 +282,7 @@
<input class="btn btn-secondary" type="button" value="getBlockHeader" onclick="getBlockHeader()"> <input class="btn btn-secondary" type="button" value="getBlockHeader" onclick="getBlockHeader()">
</div> </div>
<div class="col-8"> <div class="col-8">
<input type="text" class="form-control" id="getBlockHeaderHeight" value="0"> <input type="text" class="form-control" id="getBlockHeaderParam" value="0">
</div> </div>
<div class="col"> <div class="col">
</div> </div>