From d6ec40b39661654f689970a2399387c9ae7ed47e Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Sat, 18 Aug 2018 04:09:49 +0800
Subject: [PATCH 01/12] Add Python3.5 prerequisites in README

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 581325e..2ae6e97 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Most use cases for micropayments involve a single user or device interacting
 repeatedly with a few vendors.
 
 ## Prerequisites
+`Iota-swarm-node` is compatible with Python 3.5.
 
 Install dependent packages:
 ```shell

From f837ad5b9e670fe323c0e213207e2fece3237389 Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Sat, 18 Aug 2018 16:38:32 +0800
Subject: [PATCH 02/12] Perform sanity checks on Python3

---
 Makefile     |  3 ++-
 mk/python.mk | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 mk/python.mk

diff --git a/Makefile b/Makefile
index e40c5ff..5d9607c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+include mk/python.mk
 DCURL_DIR := deps/dcurl
 DCURL_LIB := $(DCURL_DIR)/build/libdcurl.so
 DEPS += $(DCURL_LIB)
@@ -19,7 +20,7 @@ TESTS += $(wildcard tests/tangleid/*.sh)
 check: server.py $(DCURL_LIB)
 	@ TMP_PID=`mktemp /tmp/server_pid.XXXXXX`; \
 	echo "Running test suite..." ; \
-	( python $^ & echo $$! > $${TMP_PID} ); \
+	( $(PYTHON) $^ & echo $$! > $${TMP_PID} ); \
 	sleep 3 ; \
 	for i in $(TESTS); do \
 	    ( echo "\n\n==[ $$i ]==\n"; $$i || kill -9 `cat $${TMP_PID}` ) \
diff --git a/mk/python.mk b/mk/python.mk
new file mode 100644
index 0000000..d325f82
--- /dev/null
+++ b/mk/python.mk
@@ -0,0 +1,12 @@
+PYTHON = python3
+PYTHON := $(shell which $(PYTHON))
+ifndef PYTHON
+$(error "python3 is required.")
+endif
+
+# check "iota" module in Python installation
+PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \
+                       echo 1 || echo 0)
+ifneq ("$(PY_CHECK_MOD_IOTA)","1")
+    $(error "skip $@ because PyOTA is not installed.")
+endif

From 5e75e2e0b129318f5cc2936ebea67fb86a55d0ce Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Mon, 20 Aug 2018 16:03:06 +0800
Subject: [PATCH 03/12] Revise known to work version of Python in README

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 2ae6e97..f601b8c 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Most use cases for micropayments involve a single user or device interacting
 repeatedly with a few vendors.
 
 ## Prerequisites
-`Iota-swarm-node` is compatible with Python 3.5.
+`iota-swarm-node`, writing with Python3+ compatible code as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for bot Python 3.5 and 3.6; yet, our testing result indicates that the environment for Python 3.6 is invalid in this case. Details as [Pyota issue#203](https://github.com/iotaledger/iota.lib.py/issues/203).
 
 Install dependent packages:
 ```shell

From 669270523d762e91f4b2ff5528992e8feb745b33 Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Mon, 20 Aug 2018 16:43:31 +0800
Subject: [PATCH 04/12] Complement the error message when no Pyota installed

---
 mk/python.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mk/python.mk b/mk/python.mk
index d325f82..2fdd702 100644
--- a/mk/python.mk
+++ b/mk/python.mk
@@ -1,12 +1,12 @@
-PYTHON = python3
+PYTHON = python3.5
 PYTHON := $(shell which $(PYTHON))
 ifndef PYTHON
-$(error "python3 is required.")
+$(error "python3.5 is required.")
 endif
 
 # check "iota" module in Python installation
 PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \
                        echo 1 || echo 0)
 ifneq ("$(PY_CHECK_MOD_IOTA)","1")
-    $(error "skip $@ because PyOTA is not installed.")
+    $(error "dependency error $@ because PyOTA is not installed, to install the latest version: pip3 install pyota")
 endif

From 365e066299e8f0dd408497d1da73a2f5ed767537 Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Wed, 22 Aug 2018 11:34:18 +0800
Subject: [PATCH 05/12] Revise prerequisites in README

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index f601b8c..38655ec 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Most use cases for micropayments involve a single user or device interacting
 repeatedly with a few vendors.
 
 ## Prerequisites
-`iota-swarm-node`, writing with Python3+ compatible code as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for bot Python 3.5 and 3.6; yet, our testing result indicates that the environment for Python 3.6 is invalid in this case. Details as [Pyota issue#203](https://github.com/iotaledger/iota.lib.py/issues/203).
+`iota-swarm-node`, compatible with Python3+ as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for both Python 3.5 and 3.6; yet, our testing result indicates that the environment for Python 3.6 is invalid in this case. Details as [Pyota issue#203](https://github.com/iotaledger/iota.lib.py/issues/203).
 
 Install dependent packages:
 ```shell

From cb5ad42ef635703e49ecabf741c3b995156e7dff Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Wed, 22 Aug 2018 11:41:27 +0800
Subject: [PATCH 06/12] Add Python executeable and compatible in sanity checks

---
 mk/python.mk | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/mk/python.mk b/mk/python.mk
index 2fdd702..84ab7eb 100644
--- a/mk/python.mk
+++ b/mk/python.mk
@@ -1,12 +1,35 @@
-PYTHON = python3.5
-PYTHON := $(shell which $(PYTHON))
+# check Python version
+PYTHON := $(shell which "python")
+PYTHON_COMPATIBLE = python3.5
+
 ifndef PYTHON
-$(error "python3.5 is required.")
+    $(error "Python is not executable, try to check the PATH environment variable or install $(PYTHON_COMPATIBLE) package.")
+endif # PYTHON
+
+ifdef PYTHON
+    PY_CHECK_VERSION := $(shell python -c "print(__import__('sys').version_info[0:2])")
+
+ifneq ($(PY_CHECK_VERSION), (3, 5))
+    PYTHON_COMPATIBLE_PATH := $(shell which $(PYTHON_COMPATIBLE))
+
+    ifdef PYTHON_COMPATIBLE_PATH
+        $(error "Found $(PYTHON_COMPATIBLE) in current environment, but it should be setting as \
+            default interpreter, try to create a symbolic link for $(PYTHON_COMPATIBLE_PATH)")
+    else
+        $(error "$(shell python -V):Invalid Python version, only available for $(PYTHON_COMPATIBLE).")
+    endif
 endif
+endif # PYTHON
+
+ifndef PYTHON
+
+endif # PYTHON
 
 # check "iota" module in Python installation
+ifdef PYTHON
 PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \
                        echo 1 || echo 0)
 ifneq ("$(PY_CHECK_MOD_IOTA)","1")
     $(error "dependency error $@ because PyOTA is not installed, to install the latest version: pip3 install pyota")
 endif
+endif # PYTHON

From 0b1bbf87c6008d7bc92d9b0d6283b1cc4251d4d0 Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Wed, 22 Aug 2018 13:22:53 +0800
Subject: [PATCH 07/12] Refractory sanity checks

---
 mk/python.mk | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/mk/python.mk b/mk/python.mk
index 84ab7eb..81503f2 100644
--- a/mk/python.mk
+++ b/mk/python.mk
@@ -1,35 +1,30 @@
 # check Python version
 PYTHON := $(shell which "python")
-PYTHON_COMPATIBLE = python3.5
+PYTHON_COMPATIBLE_VERSION = 3.5
 
 ifndef PYTHON
-    $(error "Python is not executable, try to check the PATH environment variable or install $(PYTHON_COMPATIBLE) package.")
-endif # PYTHON
+    $(error "Python is not executable, try to check the PATH environment variable or \
+        install python$(PYTHON_COMPATIBLE_VERSION) package.")
+endif # $(shell which "python")
 
-ifdef PYTHON
-    PY_CHECK_VERSION := $(shell python -c "print(__import__('sys').version_info[0:2])")
+PY_CHECK_VERSION := $(shell python -c "print(str(__import__('sys').version_info.major) + \
+    str('.') + str(__import__('sys').version_info.minor) )")
 
-ifneq ($(PY_CHECK_VERSION), (3, 5))
-    PYTHON_COMPATIBLE_PATH := $(shell which $(PYTHON_COMPATIBLE))
+ifneq ($(PY_CHECK_VERSION), $(PYTHON_COMPATIBLE_VERSION))
+
+    PYTHON_COMPATIBLE_PATH := $(shell which "python"$(PYTHON_COMPATIBLE_VERSION))
 
     ifdef PYTHON_COMPATIBLE_PATH
-        $(error "Found $(PYTHON_COMPATIBLE) in current environment, but it should be setting as \
-            default interpreter, try to create a symbolic link for $(PYTHON_COMPATIBLE_PATH)")
+        $(error "Found python$(PYTHON_COMPATIBLE_VERSION) in current environment, but it should be setting as \
+            default interpreter, try to set $(PYTHON_COMPATIBLE_PATH) in PATH environment variable.")
     else
-        $(error "$(shell python -V):Invalid Python version, only available for $(PYTHON_COMPATIBLE).")
+        $(error "$(shell python -V):Unsupported python version, only available for Python$(PYTHON_COMPATIBLE_VERSION).")
     endif
 endif
-endif # PYTHON
-
-ifndef PYTHON
-
-endif # PYTHON
 
 # check "iota" module in Python installation
-ifdef PYTHON
-PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \
+PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \
                        echo 1 || echo 0)
 ifneq ("$(PY_CHECK_MOD_IOTA)","1")
-    $(error "dependency error $@ because PyOTA is not installed, to install the latest version: pip3 install pyota")
+    $(error "Dependency error $@ because PyOTA is not installed, to install the latest version: pip3 install pyota")
 endif
-endif # PYTHON

From 91f89af43032716b9e788754a2fa22567cfefb8c Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Thu, 23 Aug 2018 02:44:45 +0800
Subject: [PATCH 08/12] Add sanity checks rules

---
 mk/python.mk | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/mk/python.mk b/mk/python.mk
index 81503f2..62bf18b 100644
--- a/mk/python.mk
+++ b/mk/python.mk
@@ -1,24 +1,28 @@
 # check Python version
+PY_FAVORED_VER = 3.5
 PYTHON := $(shell which "python")
-PYTHON_COMPATIBLE_VERSION = 3.5
+ifndef PYTHON
+    PYTHON := $(shell which "python3")
+endif
+
+ifndef PYTHON
+    PYTHON := $(shell which "python$(PY_FAVORED_VER)")
+endif
 
 ifndef PYTHON
     $(error "Python is not executable, try to check the PATH environment variable or \
-        install python$(PYTHON_COMPATIBLE_VERSION) package.")
+        install python$(PY_FAVORED_VER) package.")
 endif # $(shell which "python")
 
-PY_CHECK_VERSION := $(shell python -c "print(str(__import__('sys').version_info.major) + \
-    str('.') + str(__import__('sys').version_info.minor) )")
-
-ifneq ($(PY_CHECK_VERSION), $(PYTHON_COMPATIBLE_VERSION))
-
-    PYTHON_COMPATIBLE_PATH := $(shell which "python"$(PYTHON_COMPATIBLE_VERSION))
+PY_CHECK_VERSION := $(shell $(PYTHON) -V)
 
-    ifdef PYTHON_COMPATIBLE_PATH
-        $(error "Found python$(PYTHON_COMPATIBLE_VERSION) in current environment, but it should be setting as \
-            default interpreter, try to set $(PYTHON_COMPATIBLE_PATH) in PATH environment variable.")
+ifeq "$(filter $(PY_FAVORED_VER).%, $(PY_CHECK_VERSION))" ""
+    PYTHON := $(shell which "python"$(PY_FAVORED_VER))
+    ifdef PYTHON
+        $(error "Found python$(PY_FAVORED_VER), but it should be set as \
+            default interpreter, try to set $(PYTHON) in PATH environment variable.")
     else
-        $(error "$(shell python -V):Unsupported python version, only available for Python$(PYTHON_COMPATIBLE_VERSION).")
+        $(error "$(shell python -V):Unsupported python version, only available for Python$(PY_FAVORED_VER).")
     endif
 endif
 
@@ -26,5 +30,5 @@ endif
 PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \
                        echo 1 || echo 0)
 ifneq ("$(PY_CHECK_MOD_IOTA)","1")
-    $(error "Dependency error $@ because PyOTA is not installed, to install the latest version: pip3 install pyota")
+    $(error "Dependency error $@ because PyOTA is not installed, to install the latest version: pip install pyota")
 endif

From 81ffc182d9e924e88ae7128ac4817ec3704b43dc Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Thu, 23 Aug 2018 15:46:45 +0800
Subject: [PATCH 09/12] Add pip version detect rule

---
 mk/python.mk | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/mk/python.mk b/mk/python.mk
index 62bf18b..b440f65 100644
--- a/mk/python.mk
+++ b/mk/python.mk
@@ -30,5 +30,15 @@ endif
 PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \
                        echo 1 || echo 0)
 ifneq ("$(PY_CHECK_MOD_IOTA)","1")
-    $(error "Dependency error $@ because PyOTA is not installed, to install the latest version: pip install pyota")
+    PIP := $(shell pip -V)
+    PIP_CHECK_VERSION := $(findstring python 3, $(PIP))
+
+ifndef PIP
+    $(error "PIP package doesn't pre-configured, try to install it.")
+endif
+
+ifndef PIP_CHECK_VERSION
+    PIP_FAVORED_VER = 3
 endif
+    $(error "PyOTA package doesn't pre-configured, install the latest version: pip$(PIP_FAVORED_VER) install pyota")
+endif # PIP

From 98eccb6d4a116427db927abd3a4a72becc15caef Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Mon, 27 Aug 2018 15:11:53 +0800
Subject: [PATCH 10/12] Refractory sanity checks

---
 README.md    |  2 +-
 mk/python.mk | 45 ++++++++++++++++++++++++---------------------
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index 38655ec..d3852d6 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Most use cases for micropayments involve a single user or device interacting
 repeatedly with a few vendors.
 
 ## Prerequisites
-`iota-swarm-node`, compatible with Python3+ as well as depending on [Pyota](https://github.com/iotaledger/iota.lib.py) is theoretically available for both Python 3.5 and 3.6; yet, our testing result indicates that the environment for Python 3.6 is invalid in this case. Details as [Pyota issue#203](https://github.com/iotaledger/iota.lib.py/issues/203).
+This package depends in PyOTA, which is known to work with Python 3.5. However, before PyOTA issue [#203](https://github.com/iotaledger/iota.lib.py/issues/203) is resolved, Python 3.6/3.7 will be excluded for running this package. The build system would detect and validate the environment in advance.
 
 Install dependent packages:
 ```shell
diff --git a/mk/python.mk b/mk/python.mk
index b440f65..7f7fa83 100644
--- a/mk/python.mk
+++ b/mk/python.mk
@@ -2,43 +2,46 @@
 PY_FAVORED_VER = 3.5
 PYTHON := $(shell which "python")
 ifndef PYTHON
-    PYTHON := $(shell which "python3")
+PYTHON := $(shell which "python3")
 endif
 
 ifndef PYTHON
-    PYTHON := $(shell which "python$(PY_FAVORED_VER)")
+PYTHON := $(shell which "python$(PY_FAVORED_VER)")
 endif
 
 ifndef PYTHON
-    $(error "Python is not executable, try to check the PATH environment variable or \
-        install python$(PY_FAVORED_VER) package.")
+$(error "Python is not executable, try to check the PATH environment variable or \
+install python$(PY_FAVORED_VER) package.")
 endif # $(shell which "python")
 
 PY_CHECK_VERSION := $(shell $(PYTHON) -V)
 
 ifeq "$(filter $(PY_FAVORED_VER).%, $(PY_CHECK_VERSION))" ""
-    PYTHON := $(shell which "python"$(PY_FAVORED_VER))
-    ifdef PYTHON
-        $(error "Found python$(PY_FAVORED_VER), but it should be set as \
-            default interpreter, try to set $(PYTHON) in PATH environment variable.")
-    else
-        $(error "$(shell python -V):Unsupported python version, only available for Python$(PY_FAVORED_VER).")
-    endif
-endif
+PYTHON := $(shell which "python"$(PY_FAVORED_VER))
+ifdef PYTHON
+$(error "Found python$(PY_FAVORED_VER), but it should be set as \
+default interpreter, try to set $(PYTHON) in PATH environment variable.")
+else
+$(error "$(shell python -V):Unsupported python version, only available for Python$(PY_FAVORED_VER).")
+endif # PYTHON
+endif # "$(filter ...
 
 # check "iota" module in Python installation
 PY_CHECK_MOD_IOTA := $(shell python -c "import iota" 2>/dev/null && \
                        echo 1 || echo 0)
-ifneq ("$(PY_CHECK_MOD_IOTA)","1")
-    PIP := $(shell pip -V)
-    PIP_CHECK_VERSION := $(findstring python 3, $(PIP))
+ifeq ("$(PY_CHECK_MOD_IOTA)","0")
+PIP := $(shell pip -V && echo 1 || echo 0))
+PIP_CHECK_VERSION := $(findstring python 3, $(PIP) && echo $@ || echo 0)
+endif
+
+ifneq ("$(PIP)", "1")
+$(error "PIP package doesn't pre-configured, try to install it.")
+endif
 
-ifndef PIP
-    $(error "PIP package doesn't pre-configured, try to install it.")
+ifeq ("$(PIP_CHECK_VERSION)", "0")
+PIP_FAVORED_VER = 3
 endif
 
-ifndef PIP_CHECK_VERSION
-    PIP_FAVORED_VER = 3
+ifeq ("$(PY_CHECK_MOD_IOTA)", "0")
+$(error "PyOTA package doesn't pre-configured, install the latest version: pip$(PIP_FAVORED_VER) install pyota")
 endif
-    $(error "PyOTA package doesn't pre-configured, install the latest version: pip$(PIP_FAVORED_VER) install pyota")
-endif # PIP

From e74d2ee9453d5d232eab6ecbdd6dae55793e6b8a Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Mon, 27 Aug 2018 18:00:17 +0800
Subject: [PATCH 11/12] Fix typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d3852d6..1501b71 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Most use cases for micropayments involve a single user or device interacting
 repeatedly with a few vendors.
 
 ## Prerequisites
-This package depends in PyOTA, which is known to work with Python 3.5. However, before PyOTA issue [#203](https://github.com/iotaledger/iota.lib.py/issues/203) is resolved, Python 3.6/3.7 will be excluded for running this package. The build system would detect and validate the environment in advance.
+This package depends on PyOTA, which is known to work with Python 3.5. However, before PyOTA issue [#203](https://github.com/iotaledger/iota.lib.py/issues/203) is resolved, Python 3.6/3.7 will be excluded for running this package. The build system would detect and validate the environment in advance.
 
 Install dependent packages:
 ```shell

From 81a82b45d7f269ef3ce43963bb5261e2d4b6041d Mon Sep 17 00:00:00 2001
From: yillkid <yillkid@gmail.com>
Date: Wed, 31 Oct 2018 14:11:01 +0800
Subject: [PATCH 12/12] Store transaction before broadcast

---
 swarm_node.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/swarm_node.py b/swarm_node.py
index 5c19b04..70368c1 100644
--- a/swarm_node.py
+++ b/swarm_node.py
@@ -145,8 +145,9 @@ def send_transfer(tag, messages, address, values, dict_tips, debug=0):
         time_end_pow = time.time()
         elapsed_pow = elapsed_pow + (time_end_pow - time_start_pow)
 
-        print("Prepare to broadcast ...")
+        print("Prepare to store and broadcast ...")
         try:
+            api.store_transactions([tx_tryte[0:2673]])
             api.broadcast_transactions([tx_tryte[0:2673]])
         except Exception as e:
             print("Error: %s" % (str(e.context)))