mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
feat(cp): update event mechanism
support local event in contract process
This commit is contained in:
parent
a7be50024e
commit
d70490b5fb
@ -26,7 +26,7 @@ sourceSets {
|
||||
|
||||
dependencies {
|
||||
implementation project(":common")
|
||||
implementation project(":MockJava")
|
||||
implementation project(":mockjava")
|
||||
|
||||
implementation 'com.atlassian.commonmark:commonmark:0.17.0'
|
||||
implementation 'com.idealista:format-preserving-encryption:1.0.0'
|
||||
|
@ -637,12 +637,7 @@ public class JavaScriptEntry {
|
||||
topic_handlers.remove(topic);
|
||||
ContractProcess.instance.unSubscribe(handler);
|
||||
}
|
||||
REvent msg =
|
||||
new REvent(
|
||||
topic,
|
||||
UNSUBSCRIBE,
|
||||
content,
|
||||
reqID);
|
||||
REvent msg = new REvent(topic, UNSUBSCRIBE, content, reqID);
|
||||
msgList.add(msg);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,9 @@ public class RocksDBUtil {
|
||||
lockFile.delete();
|
||||
if (readOnly) {
|
||||
rocksDB = RocksDB.openReadOnly(options, path);
|
||||
} else rocksDB = RocksDB.open(options, path);
|
||||
} else {
|
||||
rocksDB = RocksDB.open(options, path);
|
||||
}
|
||||
} catch (RocksDBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.bdware.sc.event.REvent.REventSemantics;
|
||||
import org.bdware.sc.node.*;
|
||||
import org.bdware.sc.syncMech.SyncType;
|
||||
import org.bdware.sc.trace.ProgramPointCounter;
|
||||
import org.bdware.sc.util.HashUtil;
|
||||
import org.bdware.sc.util.JsonUtil;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
@ -259,31 +260,13 @@ public class DesktopEngine extends JSEngine {
|
||||
e.printStackTrace();
|
||||
return new ContractResult(Status.Error, new JsonPrimitive(bo.toString()));
|
||||
}
|
||||
LOGGER.debug(JsonUtil.toJson(contractNode.events));
|
||||
for (String event : contractNode.events.keySet()) {
|
||||
try {
|
||||
String str;
|
||||
REventSemantics semantics = contractNode.events.get(event);
|
||||
if (REventSemantics.AT_LEAST_ONCE.equals(semantics)) {
|
||||
str =
|
||||
String.format(
|
||||
"function %s(arg) { YancloudUtil.pubEvent(\"%s\", arg); }",
|
||||
event, event);
|
||||
} else {
|
||||
str =
|
||||
String.format(
|
||||
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
||||
event, event, semantics.name());
|
||||
}
|
||||
compileFunction(str, false);
|
||||
str =
|
||||
String.format(
|
||||
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
||||
event, event);
|
||||
compileFunction(str, false);
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOGGER.debug(JsonUtil.toJson(contractNode.events) + "\n\t" + JsonUtil.toJson(contractNode.logs));
|
||||
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 (ClassNode cn : contractNode.getClzs()) {
|
||||
try {
|
||||
@ -302,6 +285,33 @@ public class DesktopEngine extends JSEngine {
|
||||
return cResult;
|
||||
}
|
||||
|
||||
private void compileEventFunction(String name, String topic, REventSemantics semantics) {
|
||||
try {
|
||||
String str;
|
||||
if (REventSemantics.AT_LEAST_ONCE.equals(semantics)) {
|
||||
str =
|
||||
String.format(
|
||||
"function %s(arg) { YancloudUtil.pubEvent(\"%s\", arg); }",
|
||||
name, topic);
|
||||
} else {
|
||||
str =
|
||||
String.format(
|
||||
"function %s(arg) { YancloudUtil.pubEventConstraint(\"%s\", arg, \"%s\"); }",
|
||||
name, topic, semantics.name());
|
||||
}
|
||||
compileFunction(str, false);
|
||||
LOGGER.debug("compile function " + name + " success!");
|
||||
str =
|
||||
String.format(
|
||||
"function %ss(arg0, arg1) { YancloudUtil.pubEventConstraint(\"%s\", arg0, arg1); }",
|
||||
name, topic);
|
||||
compileFunction(str, false);
|
||||
LOGGER.debug("compile function " + name + "s success!");
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Load a contract into contract engine
|
||||
// *
|
||||
|
Loading…
Reference in New Issue
Block a user