From a8abd5344679cf02287302b0dd6523b5e6dc01c3 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Mon, 1 Nov 2021 15:12:50 +0800 Subject: [PATCH] refactor: prune unused code --- .../org/bdware/sc/engine/DesktopEngine.java | 6 +-- .../org/bdware/sc/engine/SyncMechUtil.java | 48 ++++--------------- .../bdware/sc/handler/ContractHandler.java | 4 +- 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/bdware/sc/engine/DesktopEngine.java b/src/main/java/org/bdware/sc/engine/DesktopEngine.java index be7c44e..0d9fb3b 100644 --- a/src/main/java/org/bdware/sc/engine/DesktopEngine.java +++ b/src/main/java/org/bdware/sc/engine/DesktopEngine.java @@ -264,9 +264,9 @@ public class DesktopEngine extends JSEngine { for (String topic : contractNode.events.keySet()) { compileEventFunction(topic, topic, contractNode.events.get(topic)); } - for (String log : contractNode.logs.keySet()) { - String topic = HashUtil.sha3(contract.getID() + log); - compileEventFunction(log, topic, contractNode.logs.get(log)); + for (String logName : contractNode.logs.keySet()) { + String topic = HashUtil.sha3(contract.getID(), logName); + compileEventFunction(logName, topic, contractNode.logs.get(logName)); } for (ClassNode cn : contractNode.getClzs()) { try { diff --git a/src/main/java/org/bdware/sc/engine/SyncMechUtil.java b/src/main/java/org/bdware/sc/engine/SyncMechUtil.java index 1ffe897..319e0b4 100644 --- a/src/main/java/org/bdware/sc/engine/SyncMechUtil.java +++ b/src/main/java/org/bdware/sc/engine/SyncMechUtil.java @@ -109,47 +109,19 @@ public class SyncMechUtil { } public void clearAllFiles() { - File file = new File(syncDir); - if (file.isDirectory()) { - String[] children = file.list(); - for (int i = 0; i < children.length; i++) { - File temp = new File(file, children[i]); - temp.delete(); - } - } + cleanDirectory(syncDir); + cleanDirectory(crDir); + cleanDirectory(memoryDir); + cleanDirectory(traceDir); + cleanDirectory(transDir); + } - file = new File(crDir); + private void cleanDirectory(String path) { + File file = new File(path); if (file.isDirectory()) { String[] children = file.list(); - for (int i = 0; i < children.length; i++) { - File temp = new File(file, children[i]); - temp.delete(); - } - } - - file = new File(memoryDir); - if (file.isDirectory()) { - String[] children = file.list(); - for (int i = 0; i < children.length; i++) { - File temp = new File(file, children[i]); - temp.delete(); - } - } - - file = new File(traceDir); - if (file.isDirectory()) { - String[] children = file.list(); - for (int i = 0; i < children.length; i++) { - File temp = new File(file, children[i]); - temp.delete(); - } - } - - file = new File(transDir); - if (file.isDirectory()) { - String[] children = file.list(); - for (int i = 0; i < children.length; i++) { - File temp = new File(file, children[i]); + for (String child : children) { + File temp = new File(file, child); temp.delete(); } } diff --git a/src/main/java/org/bdware/sc/handler/ContractHandler.java b/src/main/java/org/bdware/sc/handler/ContractHandler.java index 1158c6c..f46ae76 100644 --- a/src/main/java/org/bdware/sc/handler/ContractHandler.java +++ b/src/main/java/org/bdware/sc/handler/ContractHandler.java @@ -127,7 +127,7 @@ public class ContractHandler extends MsgHandler implements Runnable { cb.onResult(result); } - @Description("get functionEvaluates ") + @Description("get functionEvaluates") public void functionEvaluates(GetMessage msg, ResultCallback cb) { cb.onResult(cs.evaluatesAnalysis(msg.arg)); } @@ -137,7 +137,7 @@ public class ContractHandler extends MsgHandler implements Runnable { cb.onResult(cs.getMemorySet()); } - @Description("get logType ") + @Description("get logType") public void getLogType(GetMessage msg, ResultCallback cb) { cb.onResult(cs.getLogType(msg.arg)); }