From f7cf2a8d10d34f025c48d1fb5434346d8371b78f Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Tue, 11 Nov 2014 19:03:48 +0100 Subject: [PATCH] Remove -2 as an error code The error code is never checked. The methods for handling the error are not implemented. The error is unlikely to occur. The error can be prevented by using the correct data types. --- include/opentxs/client/OTClient.hpp | 13 ------------- src/client/OTClient.cpp | 24 +++--------------------- src/client/OpenTransactions.cpp | 7 ++++++- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/include/opentxs/client/OTClient.hpp b/include/opentxs/client/OTClient.hpp index 1721943fb0..c5b4050213 100644 --- a/include/opentxs/client/OTClient.hpp +++ b/include/opentxs/client/OTClient.hpp @@ -177,18 +177,6 @@ class OTClient // wasn't used to startup, (which would mean we're executing a script) then // it's A-Okay to fire those auto messages. - /// Any time a message is sent to the server, its request number is copied - /// here. - /// Most server message functions return int32_t, but technically a request - /// number can - /// be int64_t. So if the number being returned is too large for that - /// int32_t, it will return - /// -2 instead, and then another function can be called that returns - /// lMostRecentRequestNumber - /// in string form, or whatever is easiest. - /// - int64_t m_lMostRecentRequestNumber; - void load_str_trans_add_to_ledger(const OTIdentifier& the_nym_id, const String& str_trans, String str_box_type, @@ -237,7 +225,6 @@ class OTClient ProcessServerReplyArgs& args); public: - int32_t CalcReturnVal(const int64_t& lRequestNumber); bool IsRunningAsScript() const { return m_bRunningAsScript; diff --git a/src/client/OTClient.cpp b/src/client/OTClient.cpp index 472ede7841..c7dea54a35 100644 --- a/src/client/OTClient.cpp +++ b/src/client/OTClient.cpp @@ -171,23 +171,6 @@ namespace opentxs { -int32_t OTClient::CalcReturnVal(const int64_t& lRequestNumber) -{ - m_lMostRecentRequestNumber = lRequestNumber; - if ((-1) == lRequestNumber) - return (-1); - else if (0 == lRequestNumber) - return 0; - - const int32_t nRequestNum = static_cast(lRequestNumber); - - if (lRequestNumber == nRequestNum) // In this case, it works! - return nRequestNum; - - return (-2); // some other call can return m_lMostRecentRequestNumber - // if needed. -} - void OTClient::ProcessMessageOut(const Message& theMessage) { const String strMessage(theMessage); @@ -7845,8 +7828,8 @@ int32_t OTClient::ProcessUserCommand( otErr << "OTClient::ProcessUserCommand: " "pAccount->GetPurportedServerID() doesn't match " "SERVER_ID.\n(Try adding: --server SERVER_ID)\n"; - return CalcReturnVal(-1); - ; + + return -1; } } @@ -9145,7 +9128,7 @@ int32_t OTClient::ProcessUserCommand( } } // Get out og the big switch statement! - return CalcReturnVal(lReturnValue); + return static_cast(lReturnValue); } /// Used in RPC mode (instead of Connect.) @@ -9182,7 +9165,6 @@ bool OTClient::InitClient(OTWallet& theWallet) OTClient::OTClient() : m_pWallet(nullptr) , m_bRunningAsScript(false) - , m_lMostRecentRequestNumber(0) , m_pConnection(nullptr) , m_bInitialized(false) { diff --git a/src/client/OpenTransactions.cpp b/src/client/OpenTransactions.cpp index fcef62bbf2..c3bd65635c 100644 --- a/src/client/OpenTransactions.cpp +++ b/src/client/OpenTransactions.cpp @@ -14024,12 +14024,17 @@ void OT_API::SendMessage(OTServerContract* pServerContract, OTPseudonym* pNym, } // Calls SendMessage() and does some request number magic +// Returns the requestNumber parameter cast down to int32_t. int32_t OT_API::SendMessage(OTServerContract* pServerContract, OTPseudonym* pNym, Message& message, int64_t requestNumber) const { SendMessage(pServerContract, pNym, message); - return m_pClient->CalcReturnVal(requestNumber); + + // We cast in order to satisfy the OTAPI_Exec return types. + // That will suffice for 2 billion request or 70 years if the client makes + // a request every second. + return static_cast(requestNumber); } } // namespace opentxs