feat: enable gas calculation

This commit is contained in:
root
2021-07-01 17:42:39 +08:00
parent cb5ebfc072
commit 821ea0eeda
2 changed files with 45 additions and 6 deletions

View File

@@ -401,6 +401,7 @@ function changeAppInternal(requireRendering) {
+ " <select id=\"selectAction\" onchange=\"showDescription()\" class=\"custom-select\" style=\"-webkit-appearance: none;\"><option value=\"-1\">选择方法</option></select> \n"
+ " </div>\n"
+ " <input type=\"text\" class=\"form-control\" id=\"argInput\" placeholder=\"填写参数\" >\n"
+ " <input type=\"text\" class=\"form-control col-2\" id=\"gasInput\" placeholder=\"填写gas\" >\n"
+ " <div class=\"input-group-append input-group-text\">\n"
+ "<input type=\"checkbox\" id=\"executeContractAsDebug\" aria-label=\"Checkbox for isDebug\" data-toggle=\"tooltip\" title=\"模拟调用\"></input>"
@@ -473,14 +474,21 @@ function triggerExecuteCurrentContract() {
console.log(funNode);
const argInput = $("#argInput");
var contract = global.currentContract;
executeContract(contract.id, funNode.functionName, argInput[0].value,
var gas = $("#gasInput")[0].value/1;
executeContractWithGas(contract.id, funNode.functionName, argInput[0].value,gas,
fillResultInternal, executeContractAsDebug.checked);
const iHtml = "/SCIDE/SCManager?action=executeContract&contractID="
var iHtml = "/SCIDE/SCManager?action=executeContract&contractID="
+ global.currentContract.name + "&operation="
+ funNode.functionName + "&arg=" + argInput[0].value
+ "&pubkey=" + global.sm2Key.publicKey + "&signature=";
const toSign = global.currentContract.name + "|" + funNode.functionName + "|"
+ argInput[0].value + "|" + global.sm2Key.publicKey;
+ funNode.functionName + "&arg=" + argInput[0].value;
var toSign = global.currentContract.name + "|" + funNode.functionName + "|"
+ argInput[0].value ;
if (gas>0){
toSign+="|"+gas;
iHtml+="&gasLimit="+gas;
}
iHtml+= "&pubkey=" + global.sm2Key.publicKey + "&signature=";
toSign+= "|" + global.sm2Key.publicKey;
const signature = sm2.doSignature(toSign, global.sm2Key.privateKey, {hash: true, der: true});
let urlPre = $("#urlInput")[0].value;
if (urlPre.startsWith("ws")) {
@@ -520,6 +528,9 @@ function fillResultInternal(result, data) {
global.responseCollector[data.responseID].push(data);
$("#statusSpan")[0].innerHTML = result.status;
$("#timeSpan")[0].innerHTML = "调用耗时:" + data.executeTime + "(ms)";
if (data.executionGas !=undefined && data.executionGas>0)
$("#timeSpan")[0].innerHTML+="<br> "+data.executionGas+"(gas)";
$("#timeSpan")[0].innerHTML
if (result.result instanceof Object) {
$("#responseArea")[0].value = JSON.stringify(result.result);
$("#timeSpan")[0].innerHTML += "<br> JSON格式";