feat: support @RouteInfo byFunc

This commit is contained in:
WangXuxin 2022-04-27 10:23:33 +08:00
parent fa729d80a0
commit bac80bbf31
2 changed files with 21 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package org.bdware.sc; package org.bdware.sc;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
@ -846,6 +847,21 @@ public class ContractProcess {
return logIndex.size(); return logIndex.size();
} }
public String executeFunctionWithoutLimit(String arg) {
try {
JsonObject body = JsonUtil.parseString(arg).getAsJsonObject();
String funcName = body.get("funcName").getAsString();
JsonArray arr = body.getAsJsonArray("funcArgs");
Object[] funcArgs = JsonUtil.fromJson(arr, Object[].class);
Object result = engine.invokeFunction(funcName, funcArgs);
return JsonUtil.toJson(result);
} catch (Exception e) {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(bo));
return bo.toString();
}
}
public String executeContract(String arg) { public String executeContract(String arg) {
// TODO // TODO
// eventCenter.pub(new EventMsg("executeContract", arg)); // eventCenter.pub(new EventMsg("executeContract", arg));

View File

@ -115,6 +115,11 @@ public class ContractHandler extends MsgHandler implements Runnable {
cb.onResult(cs.executeContract(msg.arg)); cb.onResult(cs.executeContract(msg.arg));
} }
@Description(value = "invoke function without limit")
public void invokeFunctionWithoutLimit(GetMessage msg, ResultCallback cb) {
cb.onResult(cs.executeFunctionWithoutLimit(msg.arg));
}
@Description("set DesktopPermission") @Description("set DesktopPermission")
public void setDesktopPermission(GetMessage msg, ResultCallback cb) { public void setDesktopPermission(GetMessage msg, ResultCallback cb) {
String result = cs.setDesktopPermission(msg.arg); String result = cs.setDesktopPermission(msg.arg);