about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorlogin000 <34250284+login000@users.noreply.github.com>2019-06-25 12:58:57 +1000
committerGitHub <noreply@github.com>2019-06-25 12:58:57 +1000
commitd7db0da8b714d560123e7a83b8bd1b56f3f35129 (patch)
tree15eecd44143c6079c7625b783c41643b2b1e5a53
parent6411a27b8d6e9583bfcbb61a8d869ef8584fab61 (diff)
downloadtcoin-d7db0da8b714d560123e7a83b8bd1b56f3f35129.tar.gz
Added #define DEBUG, fixed pcoin error message
Added #define DEBUG and put a few check statements under it.
Fixed error message in pcoin that suggested the incorrect "add_internal_balance" amount when "internal_balance" owed to a particular user was not enough (and was lesser than the number of tildecoins being sent using the "send" command to said user). Also, fixed an error in retrieving the amount owed to a particular user when doing checks during the "send" command ("temp_program_sender_username" instead of "program_sender_username").
-rw-r--r--pcoin.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/pcoin.cpp b/pcoin.cpp
index e4eeb86..978b41d 100644
--- a/pcoin.cpp
+++ b/pcoin.cpp
@@ -15,6 +15,9 @@
 #include <ctime>
 #include <unistd.h>
 
+//set to 1 to enable some debug std::cout statements
+#define DEBUG 0
+
 #define TCOIN_PATH "/home/login/tcoin"
 #define TCOIN_MSG_PATH "/home/login/tcoin/messages/"
 #define TCOIN_SALT_PATH "/home/login/tcoin/salts/"
@@ -988,15 +991,19 @@ int send(const char* sender_username, const char* receiver_username, const long
         {
           std::ifstream fin(program_sender_path.c_str());
           std::ifstream fin2(temp_program_sender_path.c_str());
-          std::cout << program_sender_path << "," << temp_program_sender_path << "," << !fin << "," << file_is_empty(fin) << "," << !fin2 << std::endl;
+          #if DEBUG
+            std::cout << program_sender_path << "," << temp_program_sender_path << "," << !fin << "," << file_is_empty(fin) << "," << !fin2 << std::endl;
+          #endif
           if((!fin || file_is_empty(fin)) && (!fin2))
           {
             fin.close();
             std::ofstream fout(program_sender_path.c_str(), std::fstream::trunc);
             fout << "0\n";
             fout.close();
-            char dummy;
-            std::cout << "Press enter to continue"; std::cin >> dummy;
+            #if DEBUG
+              char dummy;
+              std::cout << "Press enter to continue"; std::cin >> dummy;
+            #endif
           }
           else
             fin.close();
@@ -1271,15 +1278,14 @@ int send(const char* sender_username, const char* receiver_username, const long
             }
             else if(return_value == 1)
             {
-              std::string program_sender_username = std::string(PROG_ACT_W_SLASH) + std::string(sender_username) + std::string("/") + std::string(receiver_username);
-              long long int amount_owed = get_file_value(program_sender_username.c_str());
-
+              long long int amount_owed = get_file_value(temp_program_sender_username.c_str());
+              long long int amount_to_aib = (long long int)(amount_to_send) - amount_owed;
               std::cout << "\nSorry, you only owe `" << receiver_username << "` ";
               cout_formatted_amount(amount_owed, " tildecoins", " tildecoin");
               std::cout << ", not ";
               cout_formatted_amount(amount_to_send, " tildecoins. ", " tildecoin. ");
               std::cout << "Please run `" << PCOIN_BIN_PATH_W_SPACE << "add_internal_balance " << receiver_username << " ";
-              cout_formatted_amount(amount_to_send);
+              cout_formatted_amount(amount_to_aib);
               std::cout << "` to sufficiently increase the amount owed to `" << receiver_username << "`.\n\n";
 
               final_return_value = 3; //we don't simply "return 3" here because we want temp_program_sender_path to get renamed again