feat: update event mechanism for clients

update return value of EventActions.subEvent
This commit is contained in:
Frank.R.Wu 2021-10-31 23:25:24 +08:00
parent ad2b0fb6c3
commit 9f3563334d

View File

@ -10,8 +10,15 @@ import org.bdware.server.action.CMActions;
public class EventActions { public class EventActions {
@Action(async = true, userPermission = 0) @Action(async = true, userPermission = 0)
public void subEvent(JsonObject args, final ResultCallback rcb) { public void subEvent(JsonObject args, final ResultCallback rcb) {
JsonObject ret = new JsonObject();
ret.addProperty("action", "onSubEvent");
ret.addProperty("status", "Error");
if (args.has("requestID")) {
ret.addProperty("responseID", args.get("requestID").getAsString());
}
if (!args.has("topic")) { if (!args.has("topic")) {
rcb.onResult("{\"status\":\"Error\",\"data\":\"no topic arg!\"}"); ret.addProperty("data", "no topic arg!");
rcb.onResult(ret.toString());
return; return;
} }
String topic = args.get("topic").getAsString(); String topic = args.get("topic").getAsString();
@ -19,12 +26,16 @@ public class EventActions {
String argCID = args.get("contractID").getAsString(); String argCID = args.get("contractID").getAsString();
ContractClient client = CMActions.manager.getClient(argCID); ContractClient client = CMActions.manager.getClient(argCID);
if (null == client) { if (null == client) {
rcb.onResult("{\"status\":\"Error\",\"data\":\"invalid contract ID or Name!\"}"); ret.addProperty("data", "invalid contract ID or Name!");
rcb.onResult(ret.toString());
return; return;
} }
String contractID = client.getContractID(); String contractID = client.getContractID();
topic = HashUtil.sha3(contractID + topic); topic = HashUtil.sha3(contractID + topic);
} }
CMActions.manager.subEventByClient(topic, rcb.getChannel()); CMActions.manager.subEventByClient(topic, rcb.getChannel());
ret.addProperty("status", "Success");
ret.addProperty("data", topic);
rcb.onResult(ret.toString());
} }
} }