From 40e4512d08b438f62557be5bf304890d7000ae9a Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Tue, 3 Nov 2020 14:59:44 +0700
Subject: [PATCH] [+] Output satoshi scrupt for arbitr transaction [*] Fixed
 NULL pointer free in dap_client_http

---
 dap-sdk/net/client/dap_client_http.c            |  8 +++++---
 modules/bridge/btc/CMakeLists.txt               |  2 ++
 modules/bridge/btc/share/in.satoshi.tpl         | 17 +++++++++++------
 modules/bridge/btc/share/out-arbitr.satoshi.tpl |  1 +
 modules/bridge/btc/share/out.satoshi.tpl        |  1 +
 5 files changed, 20 insertions(+), 9 deletions(-)
 create mode 100644 modules/bridge/btc/share/out-arbitr.satoshi.tpl

diff --git a/dap-sdk/net/client/dap_client_http.c b/dap-sdk/net/client/dap_client_http.c
index c94fe5f370..05ce3b7eaf 100644
--- a/dap-sdk/net/client/dap_client_http.c
+++ b/dap-sdk/net/client/dap_client_http.c
@@ -418,9 +418,11 @@ static void s_http_connected(dap_events_socket_t * a_esocket)
             "\r\n",
             l_http_pvt->method, l_http_pvt->path, l_get_str ? l_get_str : "", l_http_pvt->uplink_addr, l_request_headers->str);
     // send data for POST request
-    if(!l_get_str)
-        dap_events_socket_write_unsafe( a_esocket, l_http_pvt->request, l_http_pvt->request_size);
-    DAP_DELETE(l_get_str);
+    if(l_get_str)
+        DAP_DELETE(l_get_str);
+    else
+        if (l_http_pvt->request_size)
+            dap_events_socket_write_unsafe( a_esocket, l_http_pvt->request, l_http_pvt->request_size);
 
     dap_string_free(l_request_headers, true);
 
diff --git a/modules/bridge/btc/CMakeLists.txt b/modules/bridge/btc/CMakeLists.txt
index 0da1a6cad9..95991633d9 100644
--- a/modules/bridge/btc/CMakeLists.txt
+++ b/modules/bridge/btc/CMakeLists.txt
@@ -9,3 +9,5 @@ add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_BRIDGE_BTC_SRCS} ${DAP_CHAIN_BRID
 target_include_directories(dap_chain_crypto INTERFACE .)
 target_include_directories(${PROJECT_NAME} PUBLIC include)
 target_link_libraries(${PROJECT_NAME} dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net )
+
+#INSTALL(DIRECTORY ${ share/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/bridge-btc/ FILES_MATCHING PATTERN "*"  PATTERN "*")
diff --git a/modules/bridge/btc/share/in.satoshi.tpl b/modules/bridge/btc/share/in.satoshi.tpl
index c4d3b90276..112f497f62 100644
--- a/modules/bridge/btc/share/in.satoshi.tpl
+++ b/modules/bridge/btc/share/in.satoshi.tpl
@@ -1,9 +1,14 @@
-{{for: i from 0 to $arbitr-count }}
+# Setup arbitres consensus count
+OP_${arbitr-count-consensus}
+# List arbitrs public keys
+{{for: i from 0 to ${arbitr-count} }}
+{{arbitr-${i}.public_key}}
+{{endfor}}
+# Check multisig if they are
+OP_${arbitr-count}
+OP_CHECKMULTISIG
 OP_IF
-  <arbitr-{i}.public_key>
-  OP_CHECKSIGVERIFY
-  <1>
+OP_VERIFY
 OP_ELSE
-  <2>
+# Here is the verificators check
 OP_ENDIF
-{{endfor}}
diff --git a/modules/bridge/btc/share/out-arbitr.satoshi.tpl b/modules/bridge/btc/share/out-arbitr.satoshi.tpl
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/modules/bridge/btc/share/out-arbitr.satoshi.tpl
@@ -0,0 +1 @@
+
diff --git a/modules/bridge/btc/share/out.satoshi.tpl b/modules/bridge/btc/share/out.satoshi.tpl
index e69de29bb2..8b13789179 100644
--- a/modules/bridge/btc/share/out.satoshi.tpl
+++ b/modules/bridge/btc/share/out.satoshi.tpl
@@ -0,0 +1 @@
+
-- 
GitLab