feat: enable gas calculation
This commit is contained in:
parent
59d54cb2b5
commit
02f791f578
@ -503,7 +503,8 @@
|
||||
<span class="input-group-text">参数</span>
|
||||
</div>
|
||||
|
||||
<input type="text" class="form-control" id="arg">
|
||||
<input type="text" class="form-control" placeholder="输入参数" id="arg">
|
||||
<input type="text" class="form-control col-2" placeholder="输入gas" id="gasLimit">
|
||||
<div class="input-group-append">
|
||||
<div class="input-group-text">
|
||||
<input type="checkbox" id="executeContractAsDebug"
|
||||
|
@ -398,8 +398,16 @@ function executeContract() {
|
||||
request.pubkey = global.sm2Key.publicKey;
|
||||
request.isDebug = executeContractAsDebug.checked;
|
||||
console.log(request.arg);
|
||||
const gasLimit = $('#gasLimit').val()/1;
|
||||
var toSign = request.contractID + "|"
|
||||
+ request.operation + "|" + arg ;
|
||||
if (gasLimit>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="<br>"+obj.executionGas+"gas";
|
||||
$("#responseTime").html(`响应时间:${obj['executeTime']}ms${gasInfo}${styleTail}`);
|
||||
} catch (e) {
|
||||
$("#responseStatus").html("执行状态:Failed");
|
||||
$("#responseArea")[0].value = obj.data;
|
||||
|
@ -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({
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user