From 2d7f1854f9fce019d7077b8005afbee667c9a95e Mon Sep 17 00:00:00 2001
From: moneroexamples <moneroexamples@tuta.io>
Date: Wed, 28 Sep 2016 10:21:14 +0800
Subject: [PATCH] deserialization of unsigined tx data

---
 CMakeLists.txt       |  5 +++++
 src/monero_headers.h | 10 ++++++++++
 src/page.h           | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 34fa1bf..64b75ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,6 +73,10 @@ add_library(ringct STATIC IMPORTED)
 set_property(TARGET ringct
         PROPERTY IMPORTED_LOCATION ${MONERO_LIBS_DIR}/libringct.a)
 
+add_library(wallet STATIC IMPORTED)
+set_property(TARGET wallet
+        PROPERTY IMPORTED_LOCATION ${MONERO_LIBS_DIR}/libwallet.a)
+
 # include boost headers
 include_directories(${Boost_INCLUDE_DIRS})
 include_directories("ext/mstch/include")
@@ -118,6 +122,7 @@ target_link_libraries(${PROJECT_NAME}
         myxrm
         myext
         mstch
+        wallet
         cryptonote_core
         blockchain_db
         crypto
diff --git a/src/monero_headers.h b/src/monero_headers.h
index ed31525..fccc924 100644
--- a/src/monero_headers.h
+++ b/src/monero_headers.h
@@ -9,6 +9,10 @@
 #define BLOCKCHAIN_DB DB_LMDB
 
 
+#define UNSIGNED_TX_PREFIX "Monero unsigned tx set\001"
+#define SIGNED_TX_PREFIX "Monero signed tx set\001"
+
+
 #include "net/http_base.h"
 #include "net/http_server_handlers_map2.h"
 #include "net/http_client.h"
@@ -19,12 +23,18 @@
 #include "cryptonote_core/blockchain.h"
 #include "blockchain_db/lmdb/db_lmdb.h"
 
+#include "wallet/wallet2.h"
+
+#include "serialization/binary_utils.h"
+
 #include "ringct/rctTypes.h"
 #include "ringct/rctOps.h"
 #include "ringct/rctSigs.h"
 
 #include "common/base58.h"
 
+#include "string_coding.h"
+
 
 #endif //XMREG01_MONERO_HEADERS_H_H
 
diff --git a/src/page.h b/src/page.h
index 4efdabf..4e13213 100644
--- a/src/page.h
+++ b/src/page.h
@@ -1531,8 +1531,47 @@ namespace xmreg {
         string
         show_checkandpushtx(string raw_tx_data, string action)
         {
+            // remove white characters
+            boost::trim(raw_tx_data);
+            boost::erase_all(raw_tx_data, "\r\n");
+            boost::erase_all(raw_tx_data, "\n");
 
             cout << raw_tx_data << endl;
+
+            string decoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data);
+
+            cout << decoded_raw_tx_data << endl;
+
+            const size_t magiclen = strlen(UNSIGNED_TX_PREFIX);
+
+            bool unsigned_tx_given {false};
+
+            if (strncmp(decoded_raw_tx_data.c_str(), UNSIGNED_TX_PREFIX, magiclen) == 0)
+            {
+                unsigned_tx_given = true;
+                cout << "UNSIGNED_TX_PREFIX data given" << endl;
+            }
+
+            if (unsigned_tx_given)
+            {
+                ::tools::wallet2::unsigned_tx_set exported_txs;
+
+                bool r = serialization::parse_binary(std::string(
+                            decoded_raw_tx_data.c_str() + magiclen,
+                            decoded_raw_tx_data.size() - magiclen),
+                                                exported_txs);
+                if (r)
+                {
+
+                }
+                else
+                {
+                    cout << "deserialization of unsigined tx data NOT sucessful" << endl;
+                    return string("deserialization of unsigined tx data NOT successful. "
+                                          "Maybe its not base64 encoded?");
+                }
+            }
+
             cout << action << endl;
 
             return {};