[rpc] add method version
#include "cJSON_Utils.h"
#include "rpc_wrapper.h"
#include "rpc_service.h"
+#include "../version.h"
#include "../init.h"
#include "../block.h"
#include "../address.h"
#include "../../dnet/dnet_main.h"
#include "../utils/log.h"
-#if defined(_WIN32) || defined(_WIN64)
-#define poll WSAPoll
-#else
-#include <poll.h>
-#endif
-
-#if !defined(_WIN32) && !defined(_WIN64)
-#define UNIX_SOCK "unix_sock.dat"
-#else
-#define LOCAL_HOST_IP 0x7f000001 // 127.0.0.1
-#define APPLICATION_DOMAIN_PORT 7676
-#endif
-
#define rpc_query_func(command) \
cJSON * method_xdag_##command (struct xdag_rpc_context * ctx, cJSON * params, cJSON *id, char *version); \
cJSON * method_xdag_##command (struct xdag_rpc_context * ctx, cJSON * params, cJSON *id, char *version) { \
@@ -68,6 +56,32 @@ cJSON * method_xdag_##command (struct xdag_rpc_context * ctx, cJSON * params, cJ
rpc_query_func(state)
rpc_query_func(stats)
+/* version */
+/*
+ request:
+ "method":"xdag_version", "params":[], "id":1
+ "jsonrpc":"2.0", "method":"xdag_version", "params":[], "id":1
+ "version":"1.1", "method":"xdag_version", "params":[], "id":1
+
+ reponse:
+ "result":[{"version":"0.2.1"}], "error":null, "id":1
+ "jsonrpc":"2.0", "result":[{"version":"0.2.1"}], "error":null, "id":1
+ "version":"1.1", "result":[{"version":"0.2.1"}], "error":null, "id":1
+ */
+cJSON * method_xdag_version(struct xdag_rpc_context *ctx, cJSON *params, cJSON *id, char *version);
+cJSON * method_xdag_version(struct xdag_rpc_context *ctx, cJSON *params, cJSON *id, char *version)
+{
+ xdag_debug("rpc call method version, version %s",version);
+ cJSON * ret = NULL;
+ cJSON* item = cJSON_CreateObject();
+
+ cJSON_AddItemToObject(item, "version", cJSON_CreateString(XDAG_VERSION));
+
+ ret = cJSON_CreateArray();
+ cJSON_AddItemToArray(ret, item);
+ return ret;
+}
+
/* account */
/*
request:
@@ -307,6 +321,7 @@ cJSON * method_xdag_do_xfer(struct xdag_rpc_context * ctx, cJSON * params, cJSON
int xdag_rpc_init_procedures(void)
{
/* register query func */
+ rpc_register_func(xdag_version);
rpc_register_func(xdag_state);
rpc_register_func(xdag_stats);
