From afab14ca1306587aec29ecf03e8d808932c4d7e8 Mon Sep 17 00:00:00 2001
From: "Constantin P." <papizh.konstantin@demlabs.net>
Date: Mon, 7 Oct 2024 16:01:56 +0700
Subject: [PATCH] ...

---
 modules/net/dap_chain_node_cli_cmd.c | 15 ++-------------
 modules/wallet/dap_chain_wallet.c    | 22 +++++-----------------
 2 files changed, 7 insertions(+), 30 deletions(-)

diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c
index 3d4fee8dff..241706c1a6 100644
--- a/modules/net/dap_chain_node_cli_cmd.c
+++ b/modules/net/dap_chain_node_cli_cmd.c
@@ -6091,23 +6091,12 @@ static bool s_json_get_srv_uid(struct json_object *a_json, const char *a_key_ser
 
 static dap_chain_wallet_t* s_json_get_wallet(struct json_object *a_json, const char *a_key)
 {
-    // From wallet
-    const char *l_wallet_str = s_json_get_text(a_json, a_key);
-    if(l_wallet_str) {
-        dap_chain_wallet_t *l_wallet = dap_chain_wallet_open(l_wallet_str, dap_config_get_item_str_default(g_config, "resources", "wallets_path", NULL), NULL);
-        return l_wallet;
-    }
-    return NULL;
+    return dap_chain_wallet_open(s_json_get_text(a_json, a_key), dap_chain_wallet_get_path(g_config), NULL);
 }
 
 static const dap_cert_t* s_json_get_cert(struct json_object *a_json, const char *a_key)
 {
-    const char *l_cert_name = s_json_get_text(a_json, a_key);
-    if(l_cert_name) {
-        dap_cert_t *l_cert = dap_cert_find_by_name(l_cert_name);
-        return l_cert;
-    }
-    return NULL;
+    return dap_cert_find_by_name(s_json_get_text(a_json, a_key));
 }
 
 // Read pkey from wallet or cert
diff --git a/modules/wallet/dap_chain_wallet.c b/modules/wallet/dap_chain_wallet.c
index 0797c8b6f1..a33348a5ee 100644
--- a/modules/wallet/dap_chain_wallet.c
+++ b/modules/wallet/dap_chain_wallet.c
@@ -74,7 +74,7 @@
 #ifndef DAP_OS_WINDOWS                                    /* An argument for open()/create() */
 static const mode_t s_fileprot =  ( S_IREAD | S_IWRITE) | (S_IREAD >> 3) | (S_IREAD >> 6) ;
 #endif
-static char s_wallet_ext [] = ".dwallet";
+static char const s_wallet_ext [] = ".dwallet", *s_wallets_path = NULL;
 
 static  pthread_rwlock_t s_wallet_n_pass_lock = PTHREAD_RWLOCK_INITIALIZER; /* Coordinate access to the hash-table */
 static  dap_chain_wallet_n_pass_t   *s_wallet_n_pass;                       /* A hash table to keep passwords for wallets */
@@ -346,7 +346,7 @@ int dap_chain_wallet_init()
  */
 void dap_chain_wallet_deinit(void)
 {
-
+    DAP_DELETE(s_wallets_path);
 }
 
 /**
@@ -354,24 +354,12 @@ void dap_chain_wallet_deinit(void)
  * @param[in] a_config Configuration
  * @return wallets path or NULL if error
  */
-static char s_wallets_path[MAX_PATH];
 
 const char* dap_chain_wallet_get_path(dap_config_t * a_config)
 {
-    const char *l_cp = NULL;
-    if (!a_config)
-        a_config = g_config;
-    if ( s_wallets_path[0] )                                                /* Is the path to the wallet's store has been defined ? */
-        return  s_wallets_path;                                             /* Fine, just return existen value */
-
-                                                                            /* Retrieve Wallet's store path from config */
-    if ( !(l_cp = dap_config_get_item_str_path_default(a_config, "resources", "wallets_path", NULL)) )
-        return  log_it(L_WARNING, "No path to wallet's store has been defined"), l_cp;
-
-
-    strncpy(s_wallets_path, l_cp, sizeof(s_wallets_path) - 1 );     /* Make local copy , return it to caller */
-    DAP_DEL_Z(l_cp);
-    return s_wallets_path;
+    return s_wallets_path
+        ? s_wallets_path
+        : ( s_wallets_path = dap_config_get_item_str_path_default(a_config ? a_config : g_config, "resources", "wallets_path", NULL) );
 }
 
 /**
-- 
GitLab