From 02f791f57853f375529c06ca1670e83ad45bb193 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Jul 2021 17:42:39 +0800 Subject: [PATCH] feat: enable gas calculation --- NodePortal.html | 3 ++- js/NodeContractInstances.js | 15 +++++++++++++-- js/OnlineIDE.js | 37 +++++++++++++++++-------------------- js/onlineide/rightmenu.js | 12 +++++++++--- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/NodePortal.html b/NodePortal.html index d806041..df3a3fb 100644 --- a/NodePortal.html +++ b/NodePortal.html @@ -503,7 +503,8 @@ 参数 - + +
0){ + request.gasLimit = gasLimit; + toSign+= "|" + gasLimit; + } + toSign+= "|" + global.sm2Key.publicKey; request.signature = sm2.doSignature( - `${request.contractID}|${operation}|${argDiv.value}|${global.sm2Key.publicKey}`, + toSign, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); @@ -423,7 +431,10 @@ function onExecuteResult(obj) { $("#responseArea")[0].value = result.result; } $("#responseID").html(`请求ID:${obj['responseID']}`); - $("#responseTime").html(`响应时间:${obj['executeTime']}ms${styleTail}`); + var gasInfo=""; + if (obj.executionGas!=undefined && obj.executionGas>0) + gasInfo="
"+obj.executionGas+"gas"; + $("#responseTime").html(`响应时间:${obj['executeTime']}ms${gasInfo}${styleTail}`); } catch (e) { $("#responseStatus").html("执行状态:Failed"); $("#responseArea")[0].value = obj.data; diff --git a/js/OnlineIDE.js b/js/OnlineIDE.js index 3701659..ea1f5b2 100644 --- a/js/OnlineIDE.js +++ b/js/OnlineIDE.js @@ -358,30 +358,27 @@ function initResponseAndOutputArea() { } function onExecuteResult(obj) { - const executeResultTitleEl = $("#executeResultTitle") + const executeResultTitleEl = $("#executeResultTitle"); const data = obj; - executeResultTitleEl - .html(`${data.status} (${obj['executeTime']}ms) 未知格式`); + var sytleTail = "未知格式"; if (data.result instanceof Object) { - executeResultTitleEl - .html(`${data.status} (${obj['executeTime']}ms) JSON格式`); - global.responseEditor.setValue(JSON.stringify(data.result)); + sytleTail = "JSON格式"; } else if (typeof data.result == 'string') { - executeResultTitleEl - .html(`${data.status} (${obj['executeTime']}ms) 字符串格式`); - global.responseEditor.setValue(data.result); - } else { - if (typeof data.result == 'number') { - executeResultTitleEl - .html(`${data.status} (${obj['executeTime']}ms) 数值格式`); - } else if (typeof data.result == 'boolean') { - executeResultTitleEl - .html(`${data.status} (${obj['executeTime']}ms) 布尔型格式`); - } - global.responseEditor.setValue(data.result.toString()); + styleTail = "字符串格式"; + } else if (typeof data.result == 'boolean'){ + styleTail = "布尔值格式"; + data.result = data.result.toString(); + }else if (typeof data.result == 'number'){ + styleTail = "数值格式"; + data.result = data.result.toString(); } - - // console.log(data); + var gasInfo = ""; + if (data.executionGas!=undefined && data.executionGas>0) + gasInfo =" "+data.executionGas+"gas"; + global.responseEditor.setValue(data.result); + executeResultTitleEl + .html(`${data.status} (${obj['executeTime']}ms)${gasInfo} ${styleTail}`); + // console.log(data); const totalLines = global.responseEditor.lineCount(); global.responseEditor.autoFormatRange({ diff --git a/js/onlineide/rightmenu.js b/js/onlineide/rightmenu.js index bf354dc..22759c8 100644 --- a/js/onlineide/rightmenu.js +++ b/js/onlineide/rightmenu.js @@ -218,11 +218,17 @@ function executeContract() { request.contractID = contract.id; request.operation = contract.exportedFunctions[selectedFunction.value].functionName; const arg = executeContractArgInput.value; - const gasLimit = $('#gasLimit').val() - request.gasLimit = gasLimit ? gasLimit : '1000' + const gasLimit = $('#gasLimit').val()/1; request.pubkey = sm2Key.publicKey; + var toSign = request.contractID + "|" + + request.operation + "|" + arg ; + if (gasLimit>0){ + request.gasLimit = gasLimit; + toSign+= "|" + gasLimit; + } + toSign+= "|" + sm2Key.publicKey; request.signature = sm2.doSignature( - `${request.contractID}|${request.operation}|${arg}|${sm2Key.publicKey}`, + toSign, sm2Key.privateKey, {hash: true, der: true}); request.arg = arg;