예제 #1
0
        protected static void makeGenericErrorReponse(Common.JsonValue resp, string what, int errorCode = -32001)
        {
            JsonValue error = new JsonValue(JsonValue.OBJECT);

            JsonValue code = new JsonValue();

            code = (long)errorCode;

            string msg;

            if (what != null)
            {
                msg = what;
            }
            else
            {
                msg = "Unknown application error";
            }

            JsonValue message = new JsonValue();

            message = msg;

            error.insert("code", code);
            error.insert("message", message);

            resp.insert.functorMethod("error", error);
        }
예제 #2
0
        public JsonInputValueSerializer(Common.JsonValue value)
        {
            if (!value.isObject())
            {
                throw new System.Exception("Serializer doesn't support this type of serialization: Object expected.");
            }

            chain.Add(value.functorMethod);
        }
예제 #3
0
        protected static void prepareJsonResponse(Common.JsonValue req, Common.JsonValue resp)
        {
            if (req.contains("id"))
            {
                resp.insert.functorMethod("id", req.functorMethod("id"));
            }

            resp.insert.functorMethod("jsonrpc", "2.0");
        }
예제 #4
0
        // HttpServer
        private override void processRequest(CryptoNote.HttpRequest req, CryptoNote.HttpResponse resp)
        {
            try
            {
                logger.functorMethod(Logging.Level.TRACE) << "HTTP request came: \n" << req;

                if (req.getUrl() == "/json_rpc")
                {
                    std::istringstream jsonInputStream = new std::istringstream(req.getBody());
                    Common.JsonValue   jsonRpcRequest  = new Common.JsonValue();
                    Common.JsonValue   jsonRpcResponse = new Common.JsonValue(Common.JsonValue.OBJECT);

                    try
                    {
                        jsonInputStream >> jsonRpcRequest.functorMethod;
                    }
                    catch (System.Exception)
                    {
                        logger.functorMethod(Logging.Level.DEBUGGING) << "Couldn't parse request: \"" << req.getBody() << "\"";
                        makeJsonParsingErrorResponse(ref jsonRpcResponse.functorMethod);
                        resp.setStatus(CryptoNote.HttpResponse.STATUS_200);
                        resp.setBody(jsonRpcResponse.toString());
                        return;
                    }

                    processJsonRpcRequest(jsonRpcRequest.functorMethod, jsonRpcResponse.functorMethod);

                    std::ostringstream jsonOutputStream = new std::ostringstream();
                    jsonOutputStream << jsonRpcResponse.functorMethod;

                    if (config.serviceConfig.corsHeader != "")
                    {
                        resp.addHeader("Access-Control-Allow-Origin", config.serviceConfig.corsHeader);
                    }

                    resp.setStatus(CryptoNote.HttpResponse.STATUS_200);
                    resp.setBody(jsonOutputStream.str());
                }
                else
                {
                    logger.functorMethod(Logging.Level.WARNING) << "Requested url \"" << req.getUrl() << "\" is not found";
                    resp.setStatus(CryptoNote.HttpResponse.STATUS_404);
                    return;
                }
            }
            catch (System.Exception e)
            {
                logger.functorMethod(Logging.Level.WARNING) << "Error while processing http request: " << e.Message;
                resp.setStatus(CryptoNote.HttpResponse.STATUS_500);
            }
        }
예제 #5
0
        protected static void makeInvalidPasswordResponse(Common.JsonValue resp)
        {
            JsonValue error = new JsonValue(JsonValue.OBJECT);

            JsonValue code = new JsonValue();

            code = (long)CryptoNote.JsonRpc.errInvalidPassword;

            JsonValue message = new JsonValue();

            message = "Invalid or no rpc password";

            error.insert("code", code);
            error.insert("message", message);

            resp.insert.functorMethod("error", error);
        }
예제 #6
0
        protected static void makeMethodNotFoundResponse(Common.JsonValue resp)
        {
            JsonValue error = new JsonValue(JsonValue.OBJECT);

            JsonValue code = new JsonValue();

            code = (long)CryptoNote.JsonRpc.errMethodNotFound; //ambigous declaration of JsonValue::operator= (between int and JsonValue)

            JsonValue message = new JsonValue();

            message = "Method not found";

            error.insert("code", code);
            error.insert("message", message);

            resp.insert.functorMethod("error", error);
        }
예제 #7
0
        protected static void makeJsonParsingErrorResponse(ref Common.JsonValue resp)
        {
            resp = new JsonValue(JsonValue.OBJECT);
            resp.insert.functorMethod("jsonrpc", "2.0");
            resp.insert.functorMethod("id", null);

            JsonValue error = new JsonValue(JsonValue.OBJECT);
            JsonValue code  = new JsonValue();

            code = (long)CryptoNote.JsonRpc.errParseError; //ambigous declaration of JsonValue::operator= (between int and JsonValue)

            JsonValue message = "Parse error";

            error.insert("code", code);
            error.insert("message", message);

            resp.insert.functorMethod("error", error);
        }
예제 #8
0
        protected static void makeErrorResponse(std::error_code ec, Common.JsonValue resp)
        {
            JsonValue error = new JsonValue(JsonValue.OBJECT);

            JsonValue code = new JsonValue();

            code = (long)CryptoNote.JsonRpc.errParseError; //Application specific error code

            JsonValue message = new JsonValue();

            message = ec.message();

            JsonValue data    = new JsonValue(JsonValue.OBJECT);
            JsonValue appCode = new JsonValue();

            appCode = (long)ec.value();
            data.insert("application_code", appCode);

            error.insert("code", code);
            error.insert("message", message);
            error.insert("data", data);

            resp.insert.functorMethod("error", error);
        }
예제 #9
0
 protected abstract void processJsonRpcRequest(Common.JsonValue req, Common.JsonValue resp);
예제 #10
0
 protected static void fillJsonResponse(Common.JsonValue v, Common.JsonValue resp)
 {
     resp.insert.functorMethod("result", v.functorMethod);
 }