if ("get".equals(action)){
try {
result = ScriptingService.getStore(id);
} catch (ScriptException e) {
//should never happen
throw new CommandExecutionException(command,"script does not exists");
}
} else if ("set".equals(action)){
JsonNode args = params.get("args");
if (args==null){
args = NullNode.getInstance();
}
if (!args.isObject()||!args.isNull()){
throw new CommandExecutionException(command,"Stored values should be objects or null");
}
try {
result = ScriptingService.resetStore(id,args);
} catch (ScriptException e) {
throw new CommandExecutionException(command,"script does not exists");
}
} else if ("swap".equals(action)){
if (callback==null) throw new CommandExecutionException(command,"missing function callback");
try {
result = ScriptingService.swap(id,callback);
} catch (ScriptException e) {
throw new CommandExecutionException(command,e.getMessage(),e);
}
} else if ("trade".equals(action)){
if (callback==null) throw new CommandExecutionException(command,"missing function callback");
try {
result = ScriptingService.trade(id,callback);
} catch (ScriptException e) {
throw new CommandExecutionException(command,e.getMessage(),e);
}
} else {
throw new CommandParsingException(command,"unknown action: "+action);
}
if (result == null){
return NullNode.getInstance();
} else {
String s = result.toJSON();
try {
JsonNode jsonNode = Json.mapper().readTree(s);
return jsonNode;
} catch (IOException e) {
throw new CommandExecutionException(command,"error converting result",e);
}
}
}