- private <T> void parseParamsAndRunCommand(
- final Manager m,
- final ObjectMapper objectMapper,
- final TreeNode params,
- final OutputWriter outputWriter,
- final JsonRpcCommand<T> command
- ) throws CommandException, JsonMappingException {
- T requestParams = null;
- final var requestType = command.getRequestType();
- if (params != null && requestType != null) {
- try {
- requestParams = objectMapper.readValue(objectMapper.treeAsTokens(params), requestType);
- } catch (JsonMappingException e) {
- throw e;
- } catch (IOException e) {
- throw new AssertionError(e);
+ private class UnsubscribeReceiveCommand implements JsonRpcSingleCommand<JsonNode>, JsonRpcMultiCommand<JsonNode> {
+
+ @Override
+ public String getName() {
+ return "unsubscribeReceive";
+ }
+
+ @Override
+ public TypeReference<JsonNode> getRequestType() {
+ return new TypeReference<>() {};
+ }
+
+ @Override
+ public void handleCommand(
+ final JsonNode request, final Manager m, final JsonWriter jsonWriter
+ ) throws CommandException {
+ final var subscriptionId = getSubscriptionId(request);
+ if (subscriptionId == null) {
+ unsubscribeReceive(m);
+ } else {
+ if (!unsubscribeReceive(subscriptionId)) {
+ throw new UserErrorException("Unknown subscription id");
+ }
+ }
+ }
+
+ @Override
+ public void handleCommand(
+ final JsonNode request, final MultiAccountManager c, final JsonWriter jsonWriter
+ ) throws CommandException {
+ final var subscriptionId = getSubscriptionId(request);
+ if (subscriptionId == null) {
+ throw new UserErrorException("Missing subscription parameter with subscription id");
+ } else {
+ if (!unsubscribeReceive(subscriptionId)) {
+ throw new UserErrorException("Unknown subscription id");
+ }
+ }
+ }
+
+ private Integer getSubscriptionId(final JsonNode request) {
+ if (request instanceof ArrayNode req) {
+ return req.get(0).asInt();
+ } else if (request instanceof ObjectNode req) {
+ return req.get("subscription").asInt();
+ } else {
+ return null;