From 7678e444941ea5b3cf9923ea118cc38721498fbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?=
 <alexander.lysikov@demlabs.net>
Date: Fri, 14 Aug 2020 20:51:44 +0500
Subject: [PATCH] fixed bug in command mempool_add_ca

---
 modules/chain/dap_chain.c            | 3 +++
 modules/chain/include/dap_chain.h    | 1 +
 modules/net/dap_chain_node_cli_cmd.c | 7 ++++++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/modules/chain/dap_chain.c b/modules/chain/dap_chain.c
index bf81b508e0..ccbbf22ad1 100644
--- a/modules/chain/dap_chain.c
+++ b/modules/chain/dap_chain.c
@@ -200,6 +200,9 @@ static dap_chain_type_t s_chain_type_from_str(const char *a_type_str)
     if(!dap_strcmp(a_type_str, "transaction")) {
         return CHAIN_TYPE_TX;
     }
+    if(!dap_strcmp(a_type_str, "ca")) {
+        return CHAIN_TYPE_CA;
+    }
     return CHAIN_TYPE_LAST;
 }
 
diff --git a/modules/chain/include/dap_chain.h b/modules/chain/include/dap_chain.h
index ed25e99e7a..4ed1a66426 100644
--- a/modules/chain/include/dap_chain.h
+++ b/modules/chain/include/dap_chain.h
@@ -91,6 +91,7 @@ typedef  enum dap_chain_type
     CHAIN_TYPE_TOKEN,
     CHAIN_TYPE_EMISSION,
     CHAIN_TYPE_TX,
+    CHAIN_TYPE_CA,
     CHAIN_TYPE_LAST
 } dap_chain_type_t;
 
diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c
index 850dcd1004..57c1acbc2c 100644
--- a/modules/net/dap_chain_node_cli_cmd.c
+++ b/modules/net/dap_chain_node_cli_cmd.c
@@ -3518,8 +3518,13 @@ int com_mempool_add_ca( int a_argc,  char ** a_argv, void *a_arg_func, char ** a
     // Chech for chain if was set or not
     if ( l_chain == NULL){
        // If wasn't set - trying to auto detect
-        l_chain = dap_chain_net_get_chain_by_chain_type( l_net, DAP_CHAIN_DATUM_CA );
+        l_chain = dap_chain_net_get_chain_by_chain_type( l_net, CHAIN_TYPE_CA );
         if (l_chain == NULL) { // If can't auto detect
+            // clean previous error code
+            if(a_str_reply && *a_str_reply) {
+                DAP_DELETE(*a_str_reply);
+                *a_str_reply = NULL;
+            }
             dap_chain_node_cli_set_reply_text(a_str_reply,
                     "No chains for CA datum in network \"%s\"", l_net->pub.name );
             return -2;
-- 
GitLab