const CONSENSUS_TABLE = { 0: '无', 1: 'PBFT', 2: 'RAFT', 3: 'Single' }; const RESPONSE_TYPE_TABLE = { 0: 'ALL', 1: 'MOST', 2: 'FIRST' }; function loadContractInstances(event) { console.log("loadContractInstances" + event); listContractProcess(); } function listContractProcess(event) { console.log("listContractProcess" + event); setTimeout(function () { global.wssocket.send(JSON.stringify({ action: 'listContractProcess', // data: event, // 1 << 0: INIT, 1 << 1: RUNNING, 1 << 2: HANGED, 1 << 3: KILLED, 0: ALL filters: global.myRole && global.myRole.indexOf('NodeManager') > -1 ? 0 : 7 })); global.wssocket.send(JSON.stringify({ action: 'listLeakContractProcess' })); }, 300); } function onListContractProcess1(obj) { console.log("+++++++++=" + obj.data.length); const table = JSON.parse(obj.data); global.contractList = table; drawContractInstanceStatusPie(table); // drawContractInstanceTimesPie(table); drawContractInstanceTypeTimesPie(table); drawConInfoTable(table); console.log(table); $("#selectContractInstance").html(""); const x = document.getElementById("selectContractInstance"); x.options.length = 0; x.add(new Option("选择...", " ")); global.permissionNameMap = {}; for (let i = 0; i < table.length; i++) { if (table[i]['contractStatus'] !== 'RUNNING') { continue; } let option = document.createElement("option"); option.text = table[i].name; console.log(table[i].name); global.permissionNameMap[table[i].id] = table[i]['contractPermission']; // option.value=table[i].id; option.value = table[i].id; x.add(option, null); } } function drawConInfoTable(table) { const ciTabDiv = $("#ciTabDiv"); if (ciTabDiv.css("height") === "0px") { console.log("drawConInfoTabDiv: ignore"); return; } var dtLang = { "sProcessing": "处理中...", "lengthMenu": '显示 项结果', "sZeroRecords": "没有匹配结果", "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项", "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项", "sInfoFiltered": "(由 _MAX_ 项结果过滤)", "sInfoPostFix": "", "sSearch": "搜索:", "sUrl": "", "sEmptyTable": "表中数据为空", "sLoadingRecords": "载入中...", "sInfoThousands": ",", "oPaginate": { "sFirst": "首页", "sPrevious": "上页", "sNext": "下页", "sLast": "末页" }, "oAria": { "sSortAscending": ": 以升序排列此列", "sSortDescending": ": 以降序排列此列" } }; const tableHead = ``; const tableTail = "
序号 ID 名称 状态 端口 类型 次数 流量 内存 管理
"; console.log("drawConInfoTable"); let html = tableHead; for (let i = 0; i < table.length; i++) { html += ` ${i + 1} ${table[i].id} ${table[i].name} ${table[i]['contractStatus']} ${table[i].port || '-'} ${table[i].type} ${table[i].times} ${table[i]['traffic'] || '-'} ${table[i].storage || '-'} ` } html += tableTail; html = "
合约实例列表
" + ""+html; ciTabDiv.html(html); $("#ciTabDivTab").DataTable( { "language": dtLang, "rowCallback": function (row, data, displayNum, displayIndex, dataIndex) { }, "headerCallback": function (thead/*, data, start, end, display*/) { $(thead).css("background", primaryColor); $(thead).css("color", "white"); $(thead).children().css("background", primaryColor); $(thead).children().css("color", "white"); }, scrollCollapse: false, paging: true, pageLength: 10, order: [[0, 'desc']], "columnDefs": [ { "targets": 1, "render": function (data/*, type, row, meta*/) { if (data.length > 8) return "" + data.substring(0, 8) + " ..."; else return data; } },] }); } function stopContractByID(contractID) { $("#dialogBodyDiv").html("是否停止合约,ContractID:" + contractID); showDialog("请确认", function () { global.wssocket.send(JSON.stringify({ action: 'killContractProcess', requestID: new Date().getTime().toString(), id: contractID })); }); } function pruneKilledContract() { $("#dialogBodyDiv").html("是否清除已停合约" ); showDialog("请确认", function () { global.wssocket.send(JSON.stringify({ action: 'pruneKilledContract', requestID: new Date().getTime().toString() })); setTimeout(listContractProcess,1000); }); } function restartContractByID(contractID) { $("#dialogBodyDiv").html("是否重启合约,ContractID:" + contractID); showDialog("请确认", function () { global.wssocket.send(JSON.stringify({ action: 'restartContractProcess', requestID: new Date().getTime().toString(), id: contractID })); }); } function drawContractInstanceStatusPie(table) { const ciStatusPieDiv = $("#ciStatusPieDiv") if (ciStatusPieDiv.css("height") === "0px") { console.log("drawContractInstanceStatusPie: ignore"); return; } $(ciStatusPieDiv).html( "
"); const result = {}; for (let i = 0; i < table.length; i++) { const obj = table[i]; if (!result[obj['contractStatus']]) { result[obj['contractStatus']] = 1; } else result[obj['contractStatus']]++; } global.result = result; const dataList = []; const valDataList = []; for (const key in result) { dataList.push(key); valDataList.push({ name: key, value: result[key] }); } const myChart = echarts.init($("#ciStatusPieDivCanv")[0], 'walden'); const option222 = { tooltip: { trigger: 'item', formatter: '{a}
{b}: {c} ({d}%)' }, legend: { orient: 'vertical', left: 10, data: dataList }, series: [{ name: '合约实例状态', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { normal: { show: false, position: 'center' }, emphasis: { show: true, textStyle: { fontSize: '15', fontWeight: 'bold' } } }, labelLine: { normal: { show: false } }, data: valDataList }] }; myChart.setOption(option222); } function drawContractInstanceTimesPie(table) { const ciTimesPieDiv = $("#ciTimesPieDiv"); if (ciTimesPieDiv.css("height") === "0px") { console.log("drawContractInstanceTimesPie: ignore"); return; } ciTimesPieDiv.html( "
"); const result = {}; for (let i = 0; i < table.length; i++) { const obj = table[i]; result[obj.name] = obj.times; } global.result = result; const dataList = []; const valDataList = []; for (const key in result) { dataList.push(key); valDataList.push({ name: key, value: result[key] }); } const myChart = echarts.init($("#ciTimesPieDivCanv")[0], 'walden'); const option222 = { tooltip: { trigger: 'item', formatter: '{a}
{b}: {c} ({d}%)' }, legend: { orient: 'vertical', left: 10, data: dataList }, series: [{ name: '实例调用次数', type: 'pie', radius: ['50%', '70%'], avoidLabelOverlap: false, label: { normal: { show: false, position: 'center' }, emphasis: { show: true, textStyle: { fontSize: '15', fontWeight: 'bold' } } }, labelLine: { normal: { show: false } }, data: valDataList }] }; myChart.setOption(option222); } function changeContractInstance(obj) { let i; console.log(obj); global.contractInstance = obj; console.log(typeof (obj)); showPermissionList(global.contractInstance); let contract; for (i = 0; i < global.contractList.length; i++) { if (global.contractList[i].id === obj) { contract = global.contractList[i]; global.instance = contract; global.instanceName = contract.name; global.instanceSequencing = contract.type; global.useP2P = contract.useP2P; listMemoryFiles(contract.name); getSyncType(contract.name); break; } } $("#selectContractFunction").html(""); const x = document.getElementById("selectContractFunction"); x.options.length = 0; x.add(new Option("选择方法...", " ")); console.log("contract ", contract); for (i = 0; i < contract['exportedFunctions'].length; i++) { const option = document.createElement("option"); option.text = contract['exportedFunctions'][i].functionName; option.value = contract['exportedFunctions'][i].functionName; x.add(option, null); } } function changeMemoryFiles(obj) { console.log(obj); global.memoryFile = obj; } function executeContractWithDynamicResult() { const argDiv = $("#arg")[0] console.log("executeContractWithDynamicResult"); const request = {}; request.action = "executeContract"; request.requestID = new Date().getTime() + ""; request.contractName = global.contractInstance; request.sequencing = global.instanceSequencing; request.useP2P = global.useP2P; request.isDebug = executeContractAsDebug.checked; const operation = $("#selectContractFunction")[0].value; if (operation === " " && !operation) { myToast("执行合约", "请选择合约方法!"); return; } request.arg = `{"action":"${operation}","arg":"${argDiv.value}"}`; request.pubkey = global.sm2Key.publicKey; request.withDyanmicAnalysis = true; request.signature = sm2.doSignature( `${request.contractID}|${operation}|${argDiv.value}|${global.sm2Key.publicKey}`, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); global.wssocket.send(JSON.stringify(request)); } function executeContract() { const argDiv = $('#arg')[0]; const request = {}; request.action = "executeContract"; request.requestID = new Date().getTime() + ""; request.contractID = global.contractInstance; const operation = $("#selectContractFunction")[0].value; if (operation === " " && !operation) { myToast("执行合约", "请选择合约方法!"); return; } request.operation = operation; request.arg = argDiv.value; request.pubkey = global.sm2Key.publicKey; request.isDebug = executeContractAsDebug.checked; console.log(request.arg); const gasLimit = $('#gasLimit').val() / 1; var toSign = request.contractID + "|" + request.operation + "|" + request.arg; if (gasLimit > 0) { request.gasLimit = gasLimit; toSign += "|" + gasLimit; } toSign += "|" + global.sm2Key.publicKey; request.signature = sm2.doSignature( toSign, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); global.wssocket.send(JSON.stringify(request)); } function onExecuteResult(obj) { console.log("onExecuteResult obj.data", obj.data); try { const result = obj; let styleTail = "
字符串格式"; $("#responseStatus").html("执行状态:" + result.status); if (result['analysis']) { $("#responseArea")[0].value = "执行结果:" + result.result + "\n动态分析结果:" + result['analysis']; } else { if (result.result instanceof Object) { $("#responseArea")[0].value = JSON.stringify(result.result); styleTail = "
JSON格式"; } else $("#responseArea")[0].value = result.result; } $("#responseID").html(`请求ID:${obj['responseID']}`); 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; $("#responseID").html(`请求ID:${obj['responseID']}`); $("#responseTime").html(`响应时间:${obj['executeTime']}ms`); } } function getMask() { const argDiv = $('#maskArg')[0]; const request = {}; request.action = "getMask"; request.requestID = new Date().getTime() + ""; request.contractID = global.contractInstance; const operation = $("#selectContractFunction")[0].value; if (operation === " " && !operation) { myToast("执行合约", "请选择合约方法!"); return; } //request.operation = operation; request.arg = argDiv.value; 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( toSign, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); global.wssocket.send(JSON.stringify(request)); } function setMask() { const argDiv = $('#maskArg')[0]; const request = {}; request.action = "setMask"; request.requestID = new Date().getTime() + ""; request.contractID = global.contractInstance; const operation = $("#selectContractFunction")[0].value; if (operation === " " && !operation) { myToast("执行合约", "请选择合约方法!"); return; } //request.operation = operation; request.arg = argDiv.value; 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( toSign, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); global.wssocket.send(JSON.stringify(request)); } function onGetMask(obj) { console.log("onGetMask obj.data", obj.data); try { const result = obj; $("#maskResponseArea")[0].value = JSON.stringify(obj.data); } catch (e) { $("#maskResponseArea")[0].value = JSON.stringify(obj.data); } } function getMock() { const argDiv = $('#mockArg')[0]; const request = {}; request.action = "getMock"; request.requestID = new Date().getTime() + ""; request.contractID = global.contractInstance; const operation = $("#selectContractFunction")[0].value; if (operation === " " && !operation) { myToast("执行合约", "请选择合约方法!"); return; } //request.operation = operation; request.arg = argDiv.value; 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( toSign, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); global.wssocket.send(JSON.stringify(request)); } function setMock() { const argDiv = $('#mockArg')[0]; const request = {}; request.action = "setMock"; request.requestID = new Date().getTime() + ""; request.contractID = global.contractInstance; const operation = $("#selectContractFunction")[0].value; if (operation === " " && !operation) { myToast("执行合约", "请选择合约方法!"); return; } //request.operation = operation; request.arg = argDiv.value; 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( toSign, global.sm2Key.privateKey, {hash: true, der: true}); localStorage.setItem("persisArg", JSON.stringify(request)); global.wssocket.send(JSON.stringify(request)); } function onGetMock(obj) { console.log("onGetMask obj.data", obj.data); try { const result = obj; $("#mockResponseArea")[0].value = JSON.stringify(obj.data); } catch (e) { $("#mockResponseArea")[0].value = JSON.stringify(obj.data); } } function onHashResult(obj) { $("#hashResult").html("数链指纹:" + obj.data); } function drawCPTable(table) { console.log("drawCPTable"); global.contractprocess = table.data; if ($("#ciTabDiv").css("height") === "0px") { console.log("drawCPTableDiv: ignore"); return; } var dtLang = { "sProcessing": "处理中...", "lengthMenu": '显示 项结果', "sZeroRecords": "没有匹配结果", "sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项", "sInfoEmpty": "显示第 0 至 0 项结果,共 0 项", "sInfoFiltered": "(由 _MAX_ 项结果过滤)", "sInfoPostFix": "", "sSearch": "搜索:", "sUrl": "", "sEmptyTable": "表中数据为空", "sLoadingRecords": "载入中...", "sInfoThousands": ",", "oPaginate": { "sFirst": "首页", "sPrevious": "上页", "sNext": "下页", "sLast": "末页" }, "oAria": { "sSortAscending": ": 以升序排列此列", "sSortDescending": ": 以降序排列此列" } }; const tableHead = ``; const tableTail = "
序号 PID 是否泄漏 启动时间 CPUUser CPUSyss resident memory 管理
"; table = table.data; console.log("drawConInfoTable"); let html = tableHead; for (let i = 0; i < table.length; i++) { html += ` ${i + 1} ${table[i].pid} ${table[i]['isLeak']} ${new Date(table[i]['cpuStart']).toLocaleString()} ${table[i]['cpuTotal']} ${table[i]['cpuSys']} ${(table[i]['resident'] / (1024 * 1024)).toFixed(2)}MB ${(table[i]['memsize'] / (1024 * 1024)).toFixed(2)}MB ` } html += tableTail; html = `
合约进程列表
${html}`; $("#cpTabDiv").html(html); $("#cpTabDivTab").DataTable( { "language": dtLang, "rowCallback": function (row, data, displayNum, displayIndex, dataIndex) { }, "headerCallback": function (thead/*, data, start, end, display*/) { $(thead).css("background", primaryColor); $(thead).css("color", "white"); $(thead).children().css("background", primaryColor); $(thead).children().css("color", "white"); }, scrollCollapse: false, paging: true, pageLength: 10, order: [[0, 'desc']], "columnDefs": [ { "targets": 1, "render": function (data/*, type, row, meta*/) { if (data.length > 10) // return "" // + data.substring(0, 10) // + " ..."; return data; else return data; } },] }); } function stopContractByPID(pid) { $("#dialogBodyDiv").html("是否停止PID:" + pid); showDialog("请确认", function () { global.wssocket.send(JSON.stringify({ action: 'killProcessByPID', pid: pid })); global.wssocket.send(JSON.stringify({ action: 'listLeakContractProcess' })); }); }