bdcontract-web-ide/js/onlineide/rightmenu.js

316 lines
11 KiB
JavaScript
Raw Permalink Normal View History

function expandOrCollapse() {
const outputNavEl = $("#outputNav")
if (outputNavEl.hasClass("col-2")) {
outputNavEl.removeClass("col-2").addClass("col-6");
$("#mainBox").removeClass("col-8").addClass("col-4");
$("#expand").html("收起");
} else {
outputNavEl.removeClass("col-6").addClass("col-2");
$("#mainBox").removeClass("col-4").addClass("col-8");
$("#expand").html("展开");
}
}
function listContracts() {
global.wssocket.send(JSON.stringify({
action: 'listContractProcess',
filters: 2
}));
}
function startContract() {
const key = pubkeyDialogVue.sm2KeyList[pubkeyDialogVue.selectedSM2Key];
const sm2Key = JSON.parse(key.sm2Key);
const projectId = $("#selectedProject")[0].value;
const project = global.projects[projectId];
startResult.innerText = "正在启动合约:" + project;
const request = {};
request.action = "startContract";
request.isPrivate = $("#privateprojecttab").hasClass("active");
request.owner = sm2Key.publicKey;
request.requestID = new Date().getTime() + "";
// request.contractid = $("#tabdiv")[0].value;
// request.script = global.scriptEditor.getValue();
request.path = "/" + project + "/mainfest.json";
localStorage.setItem("persisStatus", JSON.stringify(request));
{
request.signature = sm2.doSignature("Fixed|" + request.path + "|"
+ sm2Key.publicKey, sm2Key.privateKey);
request.script = "empty";
}
global.wssocket.send(JSON.stringify(request));
}
2022-09-02 13:26:21 +00:00
function startContractAsDebug(isDebug) {
const key = pubkeyDialogVue.sm2KeyList[pubkeyDialogVue.selectedSM2Key];
const sm2Key = JSON.parse(key.sm2Key);
const projectId = $("#selectedProject")[0].value;
const project = global.projects[projectId];
startResult.innerText = "正在以调试模式启动合约:" + project;
const request = {};
2022-09-02 13:26:21 +00:00
request.action = "startContract";
request.isPrivate = $("#privateprojecttab").hasClass("active");
2022-09-02 13:26:21 +00:00
if (createParam.value !='') {
request.createParam = createParam.value;
$("#createParam").css("color","");
if (autoConvertStr.value=='on') {
try{
request.createParam = JSON.parse(request.createParam);
$("#createParam").css("color","");
}catch(e){
console.log(e);
$("#createParam").css("color","red");
alert("Create Param not JSON Format");
return;
}
}else{
}
}
request.isDebug = isDebug;
if (remoteDebugPort.value !='') {
request.remoteDebugPort = remoteDebugPort.value;
}
request.owner = sm2Key.publicKey;
request.requestID = new Date().getTime() + "";
// request.contractid = $("#tabdiv")[0].value;
// request.script = global.scriptEditor.getValue();
request.path = "/" + project + "/mainfest.json";
localStorage.setItem("persisStatus", JSON.stringify(request));
{
request.signature = sm2.doSignature("Fixed|" + request.path + "|"
+ sm2Key.publicKey, sm2Key.privateKey);
request.script = "empty";
}
global.wssocket.send(JSON.stringify(request));
}
function stopContract() {
global.wssocket.send(JSON.stringify({
action: 'killContractProcess',
requestID: new Date().getTime().toString(),
name: mainVue.contracts[selectedContract.value].name,
id: mainVue.contracts[selectedContract.value].id
}));
}
function genReadme() {
const request = {
isPrivate: global.currentFile.isPrivate,
path: global.currentFile.path
};
const tmpIndex = request.path.lastIndexOf('/');
const yjsName = request.path.substring(tmpIndex + 1, request.path.length - 4);
request.path = request.path.substring(0, tmpIndex);
const key = pubkeyDialogVue.sm2KeyList[pubkeyDialogVue.selectedSM2Key];
const sm2Key = JSON.parse(key.sm2Key);
for (const c of mainVue.contracts) {
2021-06-15 13:43:19 +00:00
// 这里假设合约名同文件名
if (yjsName === c.name) {
const exportedFunction = c.exportedFunctions;
2021-06-15 13:43:19 +00:00
ReadmeFunction = [];
for (let f of exportedFunction) {
let description = "暂无描述";
let readmeFunc = {};
readmeFunc.functionName = f.functionName;
readmeFunc.description = description;
for (let anno of f.annotations) {
if (anno.type === 'Param') {
2021-06-15 13:43:19 +00:00
readmeFunc.args = anno.args[0];
} else if (anno.type === 'Description') {
2021-06-15 13:43:19 +00:00
readmeFunc.description = anno.args[0];
} else if (anno.type === 'Result') {
2021-06-15 13:43:19 +00:00
readmeFunc.result = anno.args[0];
}
}
ReadmeFunction.push(readmeFunc);
}
request.action = "generateReadme";
request.contractID = c.id;
request.contractName = c.name;
request.pubkey = sm2Key.publicKey;
global.wssocket.send(JSON.stringify(request));
return;
}
}
myToast("生成文档失败", "请启动合约并检查合约与文件名是否一致!");
}
function genData() {
const key = pubkeyDialogVue.sm2KeyList[pubkeyDialogVue.selectedSM2Key];
const sm2Key = JSON.parse(key.sm2Key);
const value = selectedContract.value;
if (value && value !== "选择合约实例") {
const request = {};
request.action = "generateDataFromRM";
request.requestID = `${new Date().getTime()}_${Math.floor(Math.random() * 10000)}`;
const contract = mainVue.contracts[selectedContract.value];
request.isPrivate = $("#privateprojecttab").hasClass("active");
request.contractID = contract.id;
request.contractName = mainVue.contracts[selectedContract.value].name;
request.pubkey = sm2Key.publicKey;
request.signature = sm2.doSignature(
`${request.contractID}|${arg.action}|${arg.arg}|${sm2Key.publicKey}`,
sm2Key.privateKey,
{hash: true, der: true});
const gasLimit = $('#gasLimit').val()
request.arg = JSON.stringify({
gasLimit: gasLimit ? gasLimit : '1000'
});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
}
}
function queryContractInstanceDOI() {
global.wssocket.send(JSON.stringify({
action: "queryContractInstanceDOI",
requestID: new Date().getTime().toString(),
name: mainVue.contracts[selectedContract.value].name,
id: mainVue.contracts[selectedContract.value].id
}));
}
function queryContractInstanceInfoByDOI() {
global.wssocket.send(JSON.stringify({
action: 'queryContractInstanceInfoByDOI',
requestID: new Date().getTime().toString(),
doi: contractInstanceDOIInput.value
}));
}
function importContractInstanceCodeByDOI() {
global.wssocket.send(JSON.stringify({
action: "importContractInstanceCodeByDOI",
requestID: new Date().getTime().toString(),
doi: contractInstanceDOIInput.value
}));
}
function openInClient() {
2021-10-26 06:17:31 +00:00
let path = document.location.pathname.lastIndexOf("/ide");
2021-12-11 11:15:13 +00:00
if (path > 0)
2021-10-26 06:17:31 +00:00
path = document.location.pathname.substr(0, path + 1);
else path = "/";
window.open(isBaaS ?
2021-10-26 06:17:31 +00:00
`${location.origin}${path}client/BaaSClient.html${location.search}` :
`${location.origin}${path}client/bdwareclient.html?self=true&` +
`contract=${mainVue.contracts[selectedContract.value].id}`);
}
function stopAllContract() {
global.wssocket.send(JSON.stringify({
action: 'killAllContract'
}));
}
function selectContractToExecute() {
const value = selectedContractAtExecute.value;
if (value && value !== "选择实例" && mainVue.contracts[value]) {
mainVue.contractFunctions = mainVue.contracts[value].exportedFunctions;
global.wssocket.send(JSON.stringify({
action: "connectTo",
name: mainVue.contracts[value].name,
id: mainVue.contracts[value].id
}));
}
}
function executeContract() {
if (!selectedFunction.value) {
myToast("调用合约失败", "请选择合约方法");
return;
}
if (!selectedContractAtExecute.value) {
myToast("调用合约失败", "请选择合约");
return;
}
const key = pubkeyDialogVue.sm2KeyList[pubkeyDialogVue.selectedSM2Key];
const sm2Key = JSON.parse(key.sm2Key);
const request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "_"
+ Math.floor(Math.random() * 10000);
const contract = mainVue.contracts[selectedContractAtExecute.value];
request.contractID = contract.id;
2021-06-29 09:12:04 +00:00
request.operation = contract.exportedFunctions[selectedFunction.value].functionName;
const arg = executeContractArgInput.value;
2021-12-11 11:15:13 +00:00
const gasLimit = $('#gasLimit').val() / 1;
request.pubkey = sm2Key.publicKey;
2021-12-11 11:15:13 +00:00
let toSign = request.contractID + "|"
+ request.operation + "|" + arg;
if (gasLimit > 0) {
request.gasLimit = gasLimit;
toSign += "|" + gasLimit;
2021-07-01 09:42:39 +00:00
}
2021-12-11 11:15:13 +00:00
toSign += "|" + sm2Key.publicKey;
request.signature = sm2.doSignature(
2021-07-01 09:42:39 +00:00
toSign,
sm2Key.privateKey,
{hash: true, der: true});
2021-06-29 09:12:04 +00:00
request.arg = arg;
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
}
function executeContractWithDynamicResult() {
if (!selectedFunction.value) {
myToast("调用合约失败", "请选择合约方法");
return;
}
if (!selectedContractAtExecute.value) {
myToast("调用合约失败", "请选择合约");
return;
}
console.log("executeContractWithDynamicResult");
const request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "";
const contract = mainVue.contracts[selectedContractAtExecute.value];
request.contractName = contract.id;
const arg = {
action: contract.exportedFunctions[selectedFunction.value].functionName,
arg: executeContractArgInput.value
};
request.withDyanmicAnalysis = true;
request.arg = "{\"action\":\"" + arg.action + "\",\"arg\":\"" + arg.arg
+ "\"}";
request.pubkey = global.sm2Key.publicKey;
request.signature = sm2.doSignature(
`${request.contractID}|${arg.action}|${arg.arg}|${global.sm2Key.publicKey}`,
global.sm2Key.privateKey,
{hash: true, der: true});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
}
function testEvaluates() {
if (!selectedFunction.value) {
myToast("调用合约失败", "请选择合约方法");
return;
}
if (!selectedContractAtExecute.value) {
myToast("调用合约失败", "请选择合约");
return;
}
console.log("Evaluates");
const contract = mainVue.contracts[selectedContractAtExecute.value];
global.wssocket.send(JSON.stringify({
action: "evaluates",
contractName: contract.id,
functionName: contract.exportedFunctions[selectedFunction.value].functionName,
args: executeContractArgInput.value
}));
}