var nodeUrl = ''; function doLoadBalance(base58SenderAccountAddress, elementAccountbalance) { if(base58SenderAccountAddress == '') { elementAccountbalance.val(''); return; } var nodeUrl = $("#nodeUrl").val(); $.post( nodeUrl + "/index/api.html", { type: "get", apiurl: "/addresses/balance/" + base58SenderAccountAddress } ) .done(function( data ) { if(data.type == 'success'){ var balanceOfAccount = data.result; elementAccountbalance.val(addCommas(balanceOfAccount)); } if(data.type == 'apicallerror'){ $("#output").val(parseError(data.errordetail)); elementAccountbalance.val(''); } }) .fail(function() { $("#output").val( "error" ); }); } function doLoadInfoForName(name, elementNameInfo) { if(name == '') { elementNameInfo.val(''); return; } if( name.toLowerCase() != name ) { elementNameInfo.val('You must use lowercase letters.'); return; } var nodeUrl = $("#nodeUrl").val(); $.post( nodeUrl + "/index/api.html", { type: "get", apiurl: "/names/" + encodeURIComponent(name) } ) .done(function( data ) { if(data.type == 'success'){ var info = JSON.parse(data.result); elementNameInfo.val("Registered by " + info.owner); } if(data.type == 'apicallerror'){ if(parseError(data.errordetail) == 'name does not exist') { elementNameInfo.val('Name is free. You can register it.'); } else { elementNameInfo.val(parseError(data.errordetail)); } } }) .fail(function() { $("#output").val( "error" ); }); } function doNowTime() { var date = new Date(); $('#datetime').val(date.toLocaleDateString() + ' ' + date.toLocaleTimeString()); $('#timestamp').val(date.getTime()); } function sleep(ms) { ms += new Date().getTime(); while (new Date() < ms){} } function addCommas(str) { strbuf = str.toString(); if( strbuf.indexOf('.') == -1) { return strbuf.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1,'); } return strbuf.replace(/(\d)(?=(\d\d\d)+([^\d]))/g, '$1,'); } function removeAllexceptDotAndNumbers (str) { return str.replace(/[^.0-9]/g,""); } function removeAllexceptNumbers(str) { return str.replace(/[^0-9]/g,""); } function getTextCursorPosition(ele) { return ele.prop("selectionStart"); } function setTextCursorPosition(ele, pos) { ele.prop("selectionStart", pos); ele.prop("selectionEnd", pos); } function parseError(error) { try { var error = JSON.parse(error); message = error.message; } catch (e) { message = error; } return message; } function doProcess(txRaw) { if(!txRaw) { return; } $.ajax({ type: 'post', headers: { "X-FORWARDED-FOR": '127.0.0.1', //If your header name has spaces or any other char not appropriate }, dataType: 'json', url: nodeUrl + "/index/api.html", data :{ type: 'post', apiurl: '/transactions/process', json: txRaw }, success: function(data) { if(data.type == 'apicallerror') { document.getElementById('result').innerHTML = "