var loadContractInstances = function (event) {
console.log("loadContractInstances" + event);
listContractProcess();
};
var listContractProcess = function (event) {
console.log("listContractProcess" + event);
setTimeout(function () {
var param = {};
param.action = "listContractProcess";
// param.data = event;
param.fromNodePortal = true;
global.wssocket.send(JSON.stringify(param));
var request2 = {};
request2.action = "listLeakContractProcess";
global.wssocket.send(JSON.stringify(request2));
}, 300);
};
var onListContractProcess1 = function (obj) {
console.log("+++++++++=" + obj.data);
var table = JSON.parse(obj.data);
global.contractList = table;
drawContractInstanceStatusPie(table);
// drawContractInstanceTimesPie(table);
drawContractInstanceTypeTimesPie(table);
drawciTable(table);
console.log(table);
$("#selectContractInstance").html("");
var x = document.getElementById("selectContractInstance");
x.options.length = 0;
x.add(new Option("选择...", " "));
global.permissionNameMap = {};
for (var i = 0; i < table.length; i++) {
if (table[i].contractStatus == "KILLED") {
continue;
}
var 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);
}
};
var drawciTable = function (table) {
if ($("#ciTabDiv").css("height") == "0px") {
console.log("drawciTabDiv: 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": ": 以降序排列此列"
}
};
var tableHead = "
序号 | ID | 名称 | 状态 | 端口 | 类型 | 通讯 | 共识 | 统计 | 次数 | 流量 | 内存 | 管理 |
";
var tableTail = "
";
console.log("drawciTable");
var html = tableHead;
for (var i = 0; i < table.length; i++) {
html += "";
html += (i + 1);
html += " | ";
html += table[i].id;
html += " | ";
html += "" + table[i].name + ">";
html += " | ";
html += table[i].contractStatus;
html += " | ";
html += table[i].port;
html += " | ";
html += table[i].type;
html += " | ";
html += table[i].networkType == 0 ? "TCP" : "P2P";
html += " | ";
var consensusType;
switch (table[i].consensusType) {
case 0:
consensusType = "无";
break;
case 1:
consensusType = "PBFT";
break;
case 2:
consensusType = "RAFT";
break;
case 3:
consensusType = "Single";
break;
}
html += consensusType;
html += " | ";
var responseType;
switch (table[i].responseType) {
case 0:
responseType = "ALL";
break;
case 1:
responseType = "MOST";
break;
case 2:
responseType = "FIRST";
break;
}
html += responseType;
html += " | ";
html += table[i].times;
table[i].port;
html += " | ";
html += table[i].traffic;
html += " | ";
html += table[i].storage;
html += " | ";
html += ""
//table[i].resultCheck;
// html += " | ";
// html += "";
html += " |
";
}
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;
}
},]
});
};
var stopContractByID = function (contractID) {
$("#dialogBodyDiv").html("是否停止合约,ContractID:" + contractID);
showDialog("请确认", function () {
var request = {};
request.action = "killContractProcess";
request.requestID = new Date().getTime() + "";
request.id = contractID;
global.wssocket.send(JSON.stringify(request));
});
};
var drawContractInstanceStatusPie = function (table) {
if ($("#ciStatusPieDiv").css("height") == "0px") {
console.log("drawContractInstanceStatusPie: ignore");
return;
}
$("#ciStatusPieDiv")
.html(
"");
var result = {};
for (var i = 0; i < table.length; i++) {
var obj = table[i];
if (result[obj.contractStatus] == undefined) {
result[obj.contractStatus] = 1;
} else
result[obj.contractStatus]++;
}
global.result = result;
var dataList = [];
var valDataList = [];
for (var key in result) {
dataList.push(key);
var l = {};
l.name = key
l.value = result[key];
valDataList.push(l);
}
var myChart = echarts.init($("#ciStatusPieDivCanv")[0], 'walden');
var 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);
};
var drawContractInstanceTimesPie = function (table) {
if ($("#ciTimesPieDiv").css("height") == "0px") {
console.log("drawContractInstanceTimesPie: ignore");
return;
}
$("#ciTimesPieDiv")
.html(
"");
var result = {};
for (var i = 0; i < table.length; i++) {
var obj = table[i];
result[obj.name] = obj.times;
}
global.result = result;
var dataList = [];
var valDataList = [];
for (var key in result) {
dataList.push(key);
var l = {};
l.name = key
l.value = result[key];
valDataList.push(l);
}
var myChart = echarts.init($("#ciTimesPieDivCanv")[0], 'walden');
var 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);
};
var changeContractInstance = function (obj) {
console.log(obj);
global.contractInstance = obj;
console.log(typeof (obj));
showPermissionList(global.contractInstance);
var contract;
for (var 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("");
var x = document.getElementById("selectContractFunction");
x.options.length = 0;
x.add(new Option("选择方法...", " "));
console.log("contract ", contract);
for (var i = 0; i < contract.exportedFunctions.length; i++) {
var option = document.createElement("option");
option.text = contract.exportedFunctions[i].functionName;
option.value = contract.exportedFunctions[i].functionName;
x.add(option, null);
}
};
var changeMemeryFiles = function (obj) {
console.log(obj);
global.memoryFile = obj;
};
var executeContractWithDynamicResult = function () {
console.log("executeContractWithDynamicResult");
var 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;
var operation = $("#selectContractFunction")[0].value;
if (operation == " " && operation == undefined) {
myToast("执行合约", "请选择合约方法!");
return;
}
request.arg = "{\"action\":\"" + operation + "\",\"arg\":\""
+ $("#arg")[0].value + "\"}";
request.pubkey = global.sm2Key.publicKey;
request.withDyanmicAnalysis = true;
request.signature = sm2.doSignature(request.contractID + "|" + operation
+ "|" + $("#arg")[0].value + "|" + global.sm2Key.publicKey,
global.sm2Key.privateKey, {hash: true, der: true});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
};
var executeContract = function () {
var request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "";
request.contractID = global.contractInstance;
var operation = $("#selectContractFunction")[0].value;
if (operation == " " && operation == undefined) {
myToast("执行合约", "请选择合约方法!");
return;
}
request.operation = operation;
request.arg = $("#arg")[0].value;
request.pubkey = global.sm2Key.publicKey;
request.isDebug = executeContractAsDebug.checked;
console.log(request.arg);
request.signature = sm2.doSignature(request.contractID + "|" + operation
+ "|" + $("#arg")[0].value + "|" + global.sm2Key.publicKey,
global.sm2Key.privateKey, {hash: true, der: true});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
};
var onExecuteResult = function (obj) {
console.log("onExecuteResult obj.data", obj.data);
try {
var result = obj;
var styleTail = "
字符串格式";
$("#responseStatus").html("执行状态:" + result.status);
if (result.analysis != undefined) {
$("#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);
$("#responseTime").html("响应时间:" + obj.executeTime + ("ms") + styleTail);
} catch (e) {
$("#responseStatus").html("执行状态:Fail");
$("#responseArea")[0].value = obj.data;
$("#responseID").html("请求ID:" + obj.responseID);
$("#responseTime").html("响应时间:" + obj.executeTime + ("ms"));
}
};
var onHashResult = function (obj) {
$("#hashResult").html("数链指纹:" + obj.data);
};
var drawCPTable = function (table) {
console.log("drawCPTable");
global.contractprocess = table.data;
if ($("#ciTabDiv").css("height") == "0px") {
console.log("drawciTabDiv: 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": ": 以降序排列此列"
}
};
var tableHead = "序号 | PID | 是否泄漏 | 启动时间 | CPUUser | CPUSyss | resident | memory | 管理 |
";
var tableTail = "
";
table = table.data;
console.log("drawciTable");
var html = tableHead;
for (var i = 0; i < table.length; i++) {
html += "";
html += (i + 1);
html += " | ";
html += table[i].pid;
html += " | ";
html += table[i].isLeak;
html += " | ";
html += new Date(table[i].cpuStart).toLocaleString();
html += " | ";
html += table[i].cpuTotal;
html += " | ";
html += table[i].cpuSys;
html += " | ";
html += ((table[i].resident) / (1024 * 1024)).toFixed(2) + "MB";
html += " | ";
html += ((table[i].memsize) / (1024 * 1024)).toFixed(2) + "MB";
html += " | ";
html += ""
//table[i].resultCheck;
// html += " | ";
// html += "";
html += " |
";
}
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;
}
},]
});
};
var stopContractByPID = function (pid) {
$("#dialogBodyDiv").html("是否停止PID:" + pid);
showDialog("请确认", function () {
var request = {};
request.action = "killProcessByPID";
request.pid = pid;
global.wssocket.send(JSON.stringify(request));
var request2 = {};
request2.action = "listLeakContractProcess";
global.wssocket.send(JSON.stringify(request2));
});
};