From 9481b458a1dd71ffe4f4d11c48858a6f2eab8fe5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?=
 <alexander.lysikov@demlabs.net>
Date: Mon, 10 Jun 2019 23:18:04 +0500
Subject: [PATCH] fixed dap_chain_hash_fast_to_str()

---
 dap_chain_common.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dap_chain_common.c b/dap_chain_common.c
index 718100e..ae94273 100755
--- a/dap_chain_common.c
+++ b/dap_chain_common.c
@@ -66,11 +66,15 @@ size_t dap_chain_hash_fast_to_str(dap_chain_hash_fast_t * a_hash, char * a_str,
         log_it(L_ERROR, "String for hash too small, need %u but have only %u", c_hash_str_size, a_str_max);
     }
     size_t i;
+    // faster conversion to string
     snprintf(a_str, 3, "0x");
-    for(i = 0; i < sizeof(a_hash->raw); ++i)
-        snprintf(a_str + i * 2 + 2, 3, "%02x", a_hash->raw[i]);
-    a_str[c_hash_str_size] = '\0';
-    return strlen(a_str);
+    size_t l_ret = dap_bin2hex(a_str + 2, a_hash->raw, sizeof(a_hash->raw));
+    //for(i = 0; i < sizeof(a_hash->raw); ++i)
+    //    snprintf(a_str + i * 2 + 2, 3, "%02x", (a_hash->raw[i]));
+    a_str[c_hash_str_size - 1] = '\0';
+    if(!l_ret)
+        return 0;
+    return c_hash_str_size - 1; //strlen(a_str);
 }
 
 /**
-- 
GitLab