From 14db4a8f6ccebcbd1225dfe32447ce2987d47816 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Wed, 29 Jun 2022 02:29:45 +0800 Subject: [PATCH] fix: _mul misuse bugs --- src/main/java/org/bdware/sc/ContractProcess.java | 4 ++-- src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java | 4 +++- src/main/java/org/bdware/sc/engine/DesktopEngine.java | 2 +- src/main/java/org/bdware/sc/handler/ContractHandler.java | 8 +++++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/bdware/sc/ContractProcess.java b/src/main/java/org/bdware/sc/ContractProcess.java index 014f66a..1d661ac 100644 --- a/src/main/java/org/bdware/sc/ContractProcess.java +++ b/src/main/java/org/bdware/sc/ContractProcess.java @@ -1165,8 +1165,8 @@ public class ContractProcess { return JsonUtil.toJson(ret); } - public String getContract() { - return JsonUtil.toJson(contract); + public Contract getContract() { + return contract; } public String getPID() { diff --git a/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java b/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java index e35bf5f..dafa882 100644 --- a/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java +++ b/src/main/java/org/bdware/sc/boundry/JavaScriptEntry.java @@ -5,6 +5,7 @@ import groovy.util.ScriptException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bdware.sc.ContractProcess; +import org.bdware.sc.bean.ContractExecType; import org.bdware.sc.bean.ContractRequest; import org.bdware.sc.conn.ResultCallback; import org.bdware.sc.conn.SocketGet; @@ -240,7 +241,8 @@ public class JavaScriptEntry { app.doSignature(keyPair); app.setRequesterDOI(doi); app.setFromDebug(isDebug); - if (numOfCopies > 1) { + ContractExecType type = ContractProcess.instance.getContract().getType(); + if (type.needSeq()) { app.setRequestID( String.format( "%d_%d_%d_%d_mul", diff --git a/src/main/java/org/bdware/sc/engine/DesktopEngine.java b/src/main/java/org/bdware/sc/engine/DesktopEngine.java index bd226c3..a0b38be 100644 --- a/src/main/java/org/bdware/sc/engine/DesktopEngine.java +++ b/src/main/java/org/bdware/sc/engine/DesktopEngine.java @@ -515,7 +515,7 @@ public class DesktopEngine extends JSEngine { List msgList = JavaScriptEntry.msgList; JavaScriptEntry.msgList = null; - if (!msgList.isEmpty()) { + if (msgList != null && !msgList.isEmpty()) { contractRes.events = msgList; contractRes.eventRelated = true; } diff --git a/src/main/java/org/bdware/sc/handler/ContractHandler.java b/src/main/java/org/bdware/sc/handler/ContractHandler.java index eae78fc..1990e83 100644 --- a/src/main/java/org/bdware/sc/handler/ContractHandler.java +++ b/src/main/java/org/bdware/sc/handler/ContractHandler.java @@ -104,8 +104,10 @@ public class ContractHandler extends MsgHandler implements Runnable { @Description("set members") public void setMembers(GetMessage msg, ResultCallback cb) { - cb.onResult(cs.setMembers(JsonUtil.fromJson(msg.arg,new TypeToken>(){}.getType()))); + cb.onResult(cs.setMembers(JsonUtil.fromJson(msg.arg, new TypeToken>() { + }.getType()))); } + @Description("get current contract name") public void getContractName(GetMessage msg, ResultCallback cb) { cb.onResult(cs.getContractName()); @@ -116,7 +118,7 @@ public class ContractHandler extends MsgHandler implements Runnable { cb.onResult(cs.setContract(JsonUtil.fromJson(msg.arg, Contract.class))); } - @Description(value = "execute contract",isAsync = true) + @Description(value = "execute contract", isAsync = true) public void executeContract(GetMessage msg, ResultCallback cb) { cb.onResult(cs.executeContract(msg.arg)); } @@ -232,7 +234,7 @@ public class ContractHandler extends MsgHandler implements Runnable { @Description("get contract") public void getContract(GetMessage msg, ResultCallback cb) { - cb.onResult(cs.getContract()); + cb.onResult(JsonUtil.toJson(cs.getContract())); } @Description("setPID")