From 4dfca5a4a0cce40ab736f4f5ffcefe6b73109875 Mon Sep 17 00:00:00 2001 From: "haoeliu@foxmail.com" Date: Tue, 15 Nov 2022 11:50:13 +0800 Subject: [PATCH] add DoipOperation relevant update --- .../base/org/bdware/sc/node/ContractNode.java | 24 +++++++++++++++++++ .../base/org/bdware/sc/node/FunctionNode.java | 10 ++++++++ src/main/base/org/bdware/sc/node/YjsType.java | 1 + .../org/bdware/sc/visitor/ContractReader.java | 3 +++ .../org/bdware/sc/bean/DoipOperationInfo.java | 20 ++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 src/main/entry/org/bdware/sc/bean/DoipOperationInfo.java diff --git a/src/main/base/org/bdware/sc/node/ContractNode.java b/src/main/base/org/bdware/sc/node/ContractNode.java index e03e9ff..00704f9 100644 --- a/src/main/base/org/bdware/sc/node/ContractNode.java +++ b/src/main/base/org/bdware/sc/node/ContractNode.java @@ -1,6 +1,7 @@ package org.bdware.sc.node; import org.antlr.v4.runtime.CommonTokenStream; +import org.bdware.doip.codec.operations.BasicOperations; import org.bdware.sc.event.REvent.REventSemantics; import java.util.*; @@ -12,6 +13,7 @@ public class ContractNode { private final List clzs; private final List functions; private final Map functionMap; + private final Map doipOperationsMap; private final Set dependentContracts; public Map events; public Map logs; @@ -38,6 +40,7 @@ public class ContractNode { permission = new ArrayList<>(); instrumentBranch = false; dependentContracts = new HashSet<>(); + doipOperationsMap = new HashMap<>(); } public void addFunction(FunctionNode function) { @@ -196,4 +199,25 @@ public class ContractNode { public void resetContractName(String name) { contractName = name; } + + public void addDoipOperation(FunctionNode function) { + doipOperationsMap.put(function.getDoipOperationInfo().operationType, function); + } + + public FunctionNode getDoipOperation(String action) { + FunctionNode result = null; + for (BasicOperations op : BasicOperations.values()) { + if (op.toString().equals(action)) { + result = doipOperationsMap.get(op); + return result; + } + } + + result = doipOperationsMap.get(BasicOperations.Unknown); + return result; + } + + public FunctionNode getDoipOperation(BasicOperations basicOperation) { + return doipOperationsMap.get(basicOperation); + } } diff --git a/src/main/base/org/bdware/sc/node/FunctionNode.java b/src/main/base/org/bdware/sc/node/FunctionNode.java index d33a393..f1646db 100644 --- a/src/main/base/org/bdware/sc/node/FunctionNode.java +++ b/src/main/base/org/bdware/sc/node/FunctionNode.java @@ -1,6 +1,7 @@ package org.bdware.sc.node; import com.google.gson.JsonElement; +import org.bdware.sc.bean.DoipOperationInfo; import org.bdware.sc.bean.JoinInfo; import org.bdware.sc.bean.RouteInfo; @@ -25,6 +26,7 @@ public class FunctionNode extends Script { private CostDetail cost; private RouteInfo routeInfo; private JoinInfo joinInfo; + private DoipOperationInfo doipOperationInfo; private boolean isHandler; private boolean isConfidential; private boolean isHomomorphicEncrypt; @@ -36,6 +38,14 @@ public class FunctionNode extends Script { private JsonElement homoDecryptConf; public transient Class compiledClazz; + public DoipOperationInfo getDoipOperationInfo() { + return doipOperationInfo; + } + + public void setDoipOperationInfo(DoipOperationInfo doipOperationInfo) { + this.doipOperationInfo = doipOperationInfo; + } + public FunctionNode(String name, String fileName) { this.functionName = name; this.stmts = new ArrayList<>(); diff --git a/src/main/base/org/bdware/sc/node/YjsType.java b/src/main/base/org/bdware/sc/node/YjsType.java index d8479cd..47718d6 100644 --- a/src/main/base/org/bdware/sc/node/YjsType.java +++ b/src/main/base/org/bdware/sc/node/YjsType.java @@ -3,5 +3,6 @@ package org.bdware.sc.node; public enum YjsType { Oracle, Contract, + DoipModule, Module } diff --git a/src/main/base/org/bdware/sc/visitor/ContractReader.java b/src/main/base/org/bdware/sc/visitor/ContractReader.java index a850be8..d589ea8 100644 --- a/src/main/base/org/bdware/sc/visitor/ContractReader.java +++ b/src/main/base/org/bdware/sc/visitor/ContractReader.java @@ -72,7 +72,10 @@ public class ContractReader extends YJSParserBaseVisitor { node.setYjsType(YjsType.Contract); } else if (null != contractDelcar.Module()) { node.setYjsType(YjsType.Module); + } else if (null != contractDelcar.DoipModule()) { + node.setYjsType(YjsType.DoipModule); } + if (null != contractDelcar.annotations()) annotations = contractDelcar.annotations().annotation(); for (AnnotationContext annotation : annotations) { diff --git a/src/main/entry/org/bdware/sc/bean/DoipOperationInfo.java b/src/main/entry/org/bdware/sc/bean/DoipOperationInfo.java new file mode 100644 index 0000000..fb0b011 --- /dev/null +++ b/src/main/entry/org/bdware/sc/bean/DoipOperationInfo.java @@ -0,0 +1,20 @@ +package org.bdware.sc.bean; + +import org.bdware.doip.codec.operations.BasicOperations; +import org.bdware.sc.node.AnnotationNode; +import org.bdware.sc.node.ContractNode; +import org.bdware.sc.util.JsonUtil; + +public class DoipOperationInfo { + public BasicOperations operationType; + + public static DoipOperationInfo create(AnnotationNode annotationNode, ContractNode contractNode) { + DoipOperationInfo info = new DoipOperationInfo(); + if (annotationNode.getArgs().size() == 1) { + String str = annotationNode.getArgs().get(0); + info = JsonUtil.fromJson(str, DoipOperationInfo.class); + } + System.out.println("[DoipOperationInfo] annotationNode:" + JsonUtil.toJson(annotationNode)); + return info; + } +}