mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
feat: add JavaScriptEntry.subscribe
add JavaScriptEntry.subscribe(String, String, ScriptFunction) to allow contract process to subscribe local event
This commit is contained in:
parent
a70d1ca14e
commit
47ed2656dd
@ -456,7 +456,7 @@ public class ContractProcess {
|
||||
JavaScriptEntry.random.setSeed(Integer.parseInt(contract.getID()));
|
||||
JavaScriptEntry.numOfCopies = this.contract.getNumOfCopies();
|
||||
JavaScriptEntry.shardingID =
|
||||
this.contract.getShardingId(); // 设置javaScriptEntry中的shadingID
|
||||
this.contract.getShardingId(); // 设置javaScriptEntry中的shardingID
|
||||
// JavaScriptEntry
|
||||
String zipPath = contract.getScriptStr();
|
||||
if (isArchiveFile(new File(zipPath))) {
|
||||
|
@ -59,7 +59,7 @@ public class JavaScriptEntry {
|
||||
public static int numOfCopies;
|
||||
public static boolean isDebug;
|
||||
public static List<REvent> msgList;
|
||||
public static int shadingId;
|
||||
public static int shardingID;
|
||||
// private static SM2KeyPair keyPair = new SM2().generateKeyPair(); // TODO ?? 本地服务器的,39上运行39的
|
||||
// public static String privKey;
|
||||
// public static String pubKey;
|
||||
@ -594,6 +594,23 @@ public class JavaScriptEntry {
|
||||
topic_handlers.put(topic, fun);
|
||||
}
|
||||
|
||||
/**
|
||||
* subscribe a local event
|
||||
*
|
||||
* @param contractID contractID
|
||||
* @param event local event topic
|
||||
* @param fun related handler function
|
||||
* @author Kaidong Wu
|
||||
*/
|
||||
public static void subscribe(String contractID, String event, ScriptFunction fun) {
|
||||
String topic = HashUtil.sha3(contractID, event);
|
||||
subscribe(topic, fun, false);
|
||||
if (topic_handlers.containsKey(topic)) {
|
||||
ContractProcess.instance.unSubscribe(topic_handlers.get(topic).getName());
|
||||
}
|
||||
topic_handlers.put(topic, fun);
|
||||
}
|
||||
|
||||
private static void subscribe(String topic, ScriptFunction fun, boolean fromPreSub) {
|
||||
String reqID =
|
||||
String.format(
|
||||
|
Loading…
Reference in New Issue
Block a user