merge: merge changes in BaaS

This commit is contained in:
Frank.R.Wu
2021-06-15 21:43:19 +08:00
parent c8758ecfdc
commit 12a1b701f7
7 changed files with 2166 additions and 1409 deletions

View File

@@ -156,7 +156,7 @@ function onSessionID(data) {
const loginParam = {
action: "login",
pubKey: global.sm2Key.publicKey,
signature: sm2.doSignature(global.session, global.sm2Key.privateKey,{hash:true,der:true})
signature: sm2.doSignature(global.session, global.sm2Key.privateKey, {hash: true, der: true})
};
global.wssocket.send(JSON.stringify(loginParam));
}
@@ -309,10 +309,10 @@ function onListContractProcess(data) {
mainVue.contracts = [];
var list = JSON.parse(data.data);
for (var i=0;i<list.length;i++){
if (list[i].contractStatus != "KILLED"){
mainVue.contracts.push(list[i]);
}
for (var i = 0; i < list.length; i++) {
if (list[i].contractStatus != "KILLED") {
mainVue.contracts.push(list[i]);
}
}
selectedContract.value = 0;
selectContractToExecute();
@@ -359,11 +359,11 @@ function onExecuteResult(obj) {
const data = obj;
$("#executeResultTitle")
.html(data.status + " (" + obj.executeTime + "ms) 未知格式");
if (data.result instanceof Object){
if (data.result instanceof Object) {
$("#executeResultTitle")
.html(data.status + " (" + obj.executeTime + "ms) JSON格式");
global.responseEditor.setValue(JSON.stringify(data.result));
} else if (typeof data.result == 'string'){
} else if (typeof data.result == 'string') {
$("#executeResultTitle")
.html(data.status + " (" + obj.executeTime + "ms) 字符串格式");
global.responseEditor.setValue(data.result);
@@ -394,7 +394,7 @@ function onExecuteResult(obj) {
function onGenerateReadme(obj) {
// console.log(obj.data);
myToast("生成文档结果",obj.data);
myToast("生成文档结果", obj.data);
}
function onHashResult(obj) {
@@ -460,8 +460,9 @@ function showDialog(title, cb, cancelcb) {
function init() {
console.log("[nodecenterManagement.js] init : ");
const urlParams = getRequestParameters();
initVue();
initGlobal();
initGlobal(urlParams);
initWSocket();
$('[data-toggle="tooltip"]').tooltip();
const scriptEditor = $("#scriptEditor");
@@ -474,17 +475,40 @@ function init() {
lineWrapping: true
});
global.scriptEditor.setSize("height", height);
}
function getRequestParameters() {
let arr = (location.search || "").replace(/^\?/, '').split("&");
let params = {};
for (let sd of arr) {
let data = sd.split("=");
if (data.length === 2) {
params[data[0]] = data[1];
if (location.href.indexOf("/BaaSOnlineIDE.html") !== -1) {
let params = location.href.replace(/[^#]*(#(\/)?|\?)/, '')
let url = location.href.replace(params, '')
while (!params) {
url = url.replace(/(#(\/)?|\?)$/, '')
params = url.replace(/[^#]*(#(\/)?|\?)/, '')
url = url.replace(params, '')
}
if (url.endsWith('#') || url.endsWith('#\/')) {
let sKey = Math.random().toString()
localStorage.setItem(sKey, params)
location.href = url.replace(/#(\/)?/, '?' + sKey)
} else {
let json = atob(localStorage.getItem(params))
try {
return JSON.parse(json);
} catch (e) {
localStorage.removeItem(params)
alert('链接失效!')
location.href = location.origin
}
}
} else {
let arr = (location.search || "").replace(/^\?/, '').split("&");
let params = {};
for (let sd of arr) {
let data = sd.split("=");
if (data.length === 2) {
params[data[0]] = data[1];
}
}
return params;
}
return params;
}

View File

@@ -3,7 +3,7 @@ function getDateDaysBefore(daysAgo) {
return new Date(dateStr).getTime() - daysAgo * 24 * 3600 * 1000;
}
const primaryColor = "#2E324C";
let primaryColor = "#2E324C";
// ======Vue start
let headerVue = "";
@@ -41,11 +41,17 @@ function initVue() {
if (!sm2Key.publicKey || !sm2Key.privateKey) {
this.sm2KeyStr = (JSON.stringify(global.sm2Key));
} else {
if (sm2Key.publicKey.search("\\.") != -1 || sm2Key.publicKey.search("\\.\\.") != -1 || sm2Key.publicKey.search("/") != -1 || sm2Key.publicKey.search("\\\\") != -1) {
if (sm2Key.publicKey.search("\\.") !== -1 ||
sm2Key.publicKey.search("\\.\\.") !== -1 ||
sm2Key.publicKey.search("/") !== -1 ||
sm2Key.publicKey.search("\\\\") !== -1) {
myToast("导入失败", "不是合法的公钥!");
return;
}
if (sm2Key.privateKey.search("\\.") != -1 || sm2Key.privateKey.search("\\.\\.") != -1 || sm2Key.privateKey.search("/") != -1 || sm2Key.privateKey.search("\\\\") != -1) {
if (sm2Key.privateKey.search("\\.") !== -1 ||
sm2Key.privateKey.search("\\.\\.") !== -1 ||
sm2Key.privateKey.search("/") !== -1 ||
sm2Key.privateKey.search("\\\\") !== -1) {
myToast("导入失败", "不是合法的私钥!");
return;
}
@@ -194,14 +200,23 @@ function initVue() {
// ======Vue done
function initGlobal() {
function initGlobal(urlParams) {
window.global = {};
global.sm2Key = localStorage.getItem("PrivKey");
global.result = "";
if (!global.sm2Key || global.sm2Key.length < 100) {
generate();
if (location.href.indexOf("/BaaSOnlineIDE.html") !== -1) {
global.isBaaS = true
primaryColor = "#08263a"
}
if (urlParams) {
global.urlparam = urlParams
global.sm2Key = urlParams.keys
} else {
global.sm2Key = JSON.parse(global.sm2Key);
global.sm2Key = localStorage.getItem("PrivKey");
if (!global.sm2Key || global.sm2Key.length < 100) {
generate();
} else {
global.sm2Key = JSON.parse(global.sm2Key);
}
}
headerVue.shortName = global.sm2Key.publicKey.substr(0, 5);
pubkeyDialogVue.sm2KeyStr = JSON.stringify(global.sm2Key);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -87,36 +87,34 @@ var genReadme = function () {
var sm2Key = JSON.parse(key.sm2Key);
for (c of mainVue.contracts) {
// 这里假设合约名同文件名
if (yjsName == c.name) {
var exportedFunction = c.exportedFunctions;
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') {
readmeFunc.args = anno.args[0];
}
else if (anno.type == 'Description') {
readmeFunc.description = anno.args[0];
}
else if (anno.type == 'Result') {
readmeFunc.result = anno.args[0];
}
}
ReadmeFunction.push(readmeFunc);
}
request.action = "generateReadme";
// 这里假设合约名同文件名
if (yjsName == c.name) {
var exportedFunction = c.exportedFunctions;
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') {
readmeFunc.args = anno.args[0];
} else if (anno.type == 'Description') {
readmeFunc.description = anno.args[0];
} else if (anno.type == 'Result') {
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;
}
request.contractID = c.id;
request.contractName = c.name;
request.pubkey = sm2Key.publicKey;
global.wssocket.send(JSON.stringify(request));
return;
}
}
myToast("生成文档失败", "请启动合约并检查合约与文件名是否一致!");
};
@@ -138,7 +136,7 @@ var genData = function () {
if ($('#gasLimit').val() == undefined || $('#gasLimit').val() == "") {
arg.gasLimit = '1000';
} else {
arg.gasLimit =$('#gasLimit').val();
arg.gasLimit = $('#gasLimit').val();
}
// console.log("[arg.gasLimit]"+arg.gasLimit);
request.pubkey = sm2Key.publicKey;
@@ -177,11 +175,12 @@ var importContractInstanceCodeByDOI = function () {
};
var openinClient = function () {
var path = document.location.pathname;
path = path.replace("/SCIDE","");
path = path.replace("/OnlineIDE.html","");
var url = path + "/client/bdwareclient.html?self=true&contract="
+ mainVue.contracts[selectedContract.value].id;
let url
if (global.isBaaS) {
url = `${location.origin}/client/BaaSClient.html${location.search}`;
} else {
url = `${location.origin}/client/bdwareclient.html?self=true&contract=${mainVue.contracts[selectedContract.value].id}`
}
window.open(url);
};
@@ -192,7 +191,7 @@ var stopAllContract = function () {
};
var selectContractToExecute = function () {
var value = selectedContractAtExecute.value;
if (value != undefined && value != "选择实例") {
if (!value && value !== "选择实例") {
var exportedFunction = mainVue.contracts[value].exportedFunctions;
mainVue.contractFunctions = exportedFunction;
@@ -220,7 +219,6 @@ var executeContract = function () {
var request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "_"
+ Math.floor(Math.random() * 10000);
@@ -233,12 +231,12 @@ var executeContract = function () {
if ($('#gasLimit').val() == undefined || $('#gasLimit').val() == "") {
arg.gasLimit = '1000';
} else {
arg.gasLimit =$('#gasLimit').val();
arg.gasLimit = $('#gasLimit').val();
}
// console.log("[arg.gasLimit]"+arg.gasLimit);
request.pubkey = sm2Key.publicKey;
request.signature = sm2.doSignature(request.contractID + "|" + arg.action
+ "|" + arg.arg + "|" + sm2Key.publicKey, sm2Key.privateKey,{hash:true,der:true});
+ "|" + arg.arg + "|" + sm2Key.publicKey, sm2Key.privateKey, {hash: true, der: true});
request.arg = JSON.stringify(arg);
localStorage.setItem("persisArg", JSON.stringify(request));
@@ -271,7 +269,7 @@ var executeContractWithDynamicResult = function () {
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});
global.sm2Key.privateKey, {hash: true, der: true});
localStorage.setItem("persisArg", JSON.stringify(request));
global.wssocket.send(JSON.stringify(request));
};

View File

@@ -76,9 +76,9 @@ var importContractInstanceCodeByDOI = function () {
};
var openinClient = function () {
var path = document.location.pathname;
path = path.replace("/SCIDE","");
path = path.replace("/OnlineIDE.html","");
var path = document.location.pathname;
path = path.replace("/SCIDE", "");
path = path.replace("/OnlineIDE.html", "");
var url = path + "/client/bdwareclient.html?self=true&contract="
+ mainVue.contracts[selectedContract.value].id;
window.open(url);
@@ -91,7 +91,7 @@ var stopAllContract = function () {
};
var selectContractToExecute = function () {
var value = selectedContractAtExecute.value;
if (value != undefined && value != "Select Instance") {
if (value && value !== "Select Instance") {
var exportedFunction = mainVue.contracts[value].exportedFunctions;
mainVue.contractFunctions = exportedFunction;
@@ -119,7 +119,6 @@ var executeContract = function () {
var request = {};
request.action = "executeContract";
request.requestID = new Date().getTime() + "_"
+ Math.floor(Math.random() * 10000);
@@ -131,14 +130,14 @@ var executeContract = function () {
arg.arg = executeContractArgInput.value;
//console.log("[global.withEvaluatesAnalysis]"+global.withEvaluatesAnalysis);
//if (global.withEvaluatesAnalysis != undefined) {
//console.log("test");
//console.log("test");
if ($('#gasLimit').val() == undefined || $('#gasLimit').val() == "") {
arg.gasLimit = '1000';
} else {
arg.gasLimit =$('#gasLimit').val();
arg.gasLimit = $('#gasLimit').val();
}
console.log("[arg.gasLimit]"+arg.gasLimit);
//request.withEvaluatesAnalysis = global.withEvaluatesAnalysis;
console.log("[arg.gasLimit]" + arg.gasLimit);
//request.withEvaluatesAnalysis = global.withEvaluatesAnalysis;
//}
request.pubkey = sm2Key.publicKey;
request.signature = sm2.doSignature(request.contractID + "|" + arg.action