Browse Source

wallet_rpc_server: add set_log_level/set_log_categories

moneromooo-monero 1 month ago
parent
commit
294e858d57
No account linked to committer's email address

+ 33
- 0
src/wallet/wallet_rpc_server.cpp View File

@@ -4163,6 +4163,39 @@ namespace tools
4163 4163
     return true;
4164 4164
   }
4165 4165
   //------------------------------------------------------------------------------------------------------------------------------
4166
+  bool wallet_rpc_server::on_set_log_level(const wallet_rpc::COMMAND_RPC_SET_LOG_LEVEL::request& req, wallet_rpc::COMMAND_RPC_SET_LOG_LEVEL::response& res, epee::json_rpc::error& er, const connection_context *ctx)
4167
+  {
4168
+    if (m_restricted)
4169
+    {
4170
+      er.code = WALLET_RPC_ERROR_CODE_DENIED;
4171
+      er.message = "Command unavailable in restricted mode.";
4172
+      return false;
4173
+    }
4174
+
4175
+    if (req.level < 0 || req.level > 4)
4176
+    {
4177
+      er.code = WALLET_RPC_ERROR_CODE_INVALID_LOG_LEVEL;
4178
+      er.message = "Error: log level not valid";
4179
+      return true;
4180
+    }
4181
+    mlog_set_log_level(req.level);
4182
+    return true;
4183
+  }
4184
+  //------------------------------------------------------------------------------------------------------------------------------
4185
+  bool wallet_rpc_server::on_set_log_categories(const wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES::request& req, wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES::response& res, epee::json_rpc::error& er, const connection_context *ctx)
4186
+  {
4187
+    if (m_restricted)
4188
+    {
4189
+      er.code = WALLET_RPC_ERROR_CODE_DENIED;
4190
+      er.message = "Command unavailable in restricted mode.";
4191
+      return false;
4192
+    }
4193
+
4194
+    mlog_set_log(req.categories.c_str());
4195
+    res.categories = mlog_get_categories();
4196
+    return true;
4197
+  }
4198
+  //------------------------------------------------------------------------------------------------------------------------------
4166 4199
   bool wallet_rpc_server::on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx)
4167 4200
   {
4168 4201
     res.version = WALLET_RPC_VERSION;

+ 4
- 0
src/wallet/wallet_rpc_server.h View File

@@ -151,6 +151,8 @@ namespace tools
151 151
         MAP_JON_RPC_WE("submit_multisig",    on_submit_multisig,    wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG)
152 152
         MAP_JON_RPC_WE("validate_address",   on_validate_address,   wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS)
153 153
         MAP_JON_RPC_WE("set_daemon",         on_set_daemon,         wallet_rpc::COMMAND_RPC_SET_DAEMON)
154
+        MAP_JON_RPC_WE("set_log_level",      on_set_log_level,      wallet_rpc::COMMAND_RPC_SET_LOG_LEVEL)
155
+        MAP_JON_RPC_WE("set_log_categories", on_set_log_categories, wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES)
154 156
         MAP_JON_RPC_WE("get_version",        on_get_version,        wallet_rpc::COMMAND_RPC_GET_VERSION)
155 157
       END_JSON_RPC_MAP()
156 158
     END_URI_MAP2()
@@ -234,6 +236,8 @@ namespace tools
234 236
       bool on_submit_multisig(const wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
235 237
       bool on_validate_address(const wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
236 238
       bool on_set_daemon(const wallet_rpc::COMMAND_RPC_SET_DAEMON::request& req, wallet_rpc::COMMAND_RPC_SET_DAEMON::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
239
+      bool on_set_log_level(const wallet_rpc::COMMAND_RPC_SET_LOG_LEVEL::request& req, wallet_rpc::COMMAND_RPC_SET_LOG_LEVEL::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
240
+      bool on_set_log_categories(const wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES::request& req, wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
237 241
       bool on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
238 242
 
239 243
       //json rpc v2

+ 44
- 1
src/wallet/wallet_rpc_server_commands_defs.h View File

@@ -47,7 +47,7 @@
47 47
 // advance which version they will stop working with
48 48
 // Don't go over 32767 for any of these
49 49
 #define WALLET_RPC_VERSION_MAJOR 1
50
-#define WALLET_RPC_VERSION_MINOR 10
50
+#define WALLET_RPC_VERSION_MINOR 11
51 51
 #define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
52 52
 #define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
53 53
 namespace tools
@@ -2489,5 +2489,48 @@ namespace wallet_rpc
2489 2489
     typedef epee::misc_utils::struct_init<response_t> response;
2490 2490
   };
2491 2491
 
2492
+  struct COMMAND_RPC_SET_LOG_LEVEL
2493
+  {
2494
+    struct request_t
2495
+    {
2496
+      int8_t level;
2497
+
2498
+      BEGIN_KV_SERIALIZE_MAP()
2499
+        KV_SERIALIZE(level)
2500
+      END_KV_SERIALIZE_MAP()
2501
+    };
2502
+    typedef epee::misc_utils::struct_init<request_t> request;
2503
+
2504
+    struct response_t
2505
+    {
2506
+      BEGIN_KV_SERIALIZE_MAP()
2507
+      END_KV_SERIALIZE_MAP()
2508
+    };
2509
+    typedef epee::misc_utils::struct_init<response_t> response;
2510
+  };
2511
+
2512
+  struct COMMAND_RPC_SET_LOG_CATEGORIES
2513
+  {
2514
+    struct request_t
2515
+    {
2516
+      std::string categories;
2517
+
2518
+      BEGIN_KV_SERIALIZE_MAP()
2519
+        KV_SERIALIZE(categories)
2520
+      END_KV_SERIALIZE_MAP()
2521
+    };
2522
+    typedef epee::misc_utils::struct_init<request_t> request;
2523
+
2524
+    struct response_t
2525
+    {
2526
+      std::string categories;
2527
+
2528
+      BEGIN_KV_SERIALIZE_MAP()
2529
+        KV_SERIALIZE(categories)
2530
+      END_KV_SERIALIZE_MAP()
2531
+    };
2532
+    typedef epee::misc_utils::struct_init<response_t> response;
2533
+  };
2534
+
2492 2535
 }
2493 2536
 }

+ 1
- 0
src/wallet/wallet_rpc_server_error_codes.h View File

@@ -74,3 +74,4 @@
74 74
 #define WALLET_RPC_ERROR_CODE_SIGNED_SUBMISSION      -41
75 75
 #define WALLET_RPC_ERROR_CODE_SIGN_UNSIGNED          -42
76 76
 #define WALLET_RPC_ERROR_CODE_NON_DETERMINISTIC      -43
77
+#define WALLET_RPC_ERROR_CODE_INVALID_LOG_LEVEL      -44

+ 22
- 0
utils/python-rpc/framework/wallet.py View File

@@ -728,6 +728,28 @@ class Wallet(object):
728 728
         }
729 729
         return self.rpc.send_json_rpc_request(import_key_images)
730 730
 
731
+    def set_log_level(self, level):
732
+        set_log_level = {
733
+            'method': 'set_log_level',
734
+            'params': {
735
+                'level': level,
736
+            },
737
+            'jsonrpc': '2.0',
738
+            'id': '0'
739
+        }
740
+        return self.rpc.send_json_rpc_request(set_log_level)
741
+
742
+    def set_log_categories(self, categories):
743
+        set_log_categories = {
744
+            'method': 'set_log_categories',
745
+            'params': {
746
+                'categories': categories,
747
+            },
748
+            'jsonrpc': '2.0',
749
+            'id': '0'
750
+        }
751
+        return self.rpc.send_json_rpc_request(set_log_categories)
752
+
731 753
     def get_version(self):
732 754
         get_version = {
733 755
             'method': 'get_version',

Loading…
Cancel
Save