Skip to content

Commit

Permalink
Remove -2 as an error code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OttoAllmendinger committed Nov 12, 2014
1 parent de74cc7 commit f7cf2a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
13 changes: 0 additions & 13 deletions include/opentxs/client/OTClient.hpp
Expand Up @@ -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,
Expand Down Expand Up @@ -237,7 +225,6 @@ class OTClient
ProcessServerReplyArgs& args);

public:
int32_t CalcReturnVal(const int64_t& lRequestNumber);
bool IsRunningAsScript() const
{
return m_bRunningAsScript;
Expand Down
24 changes: 3 additions & 21 deletions src/client/OTClient.cpp
Expand Up @@ -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<int32_t>(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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -9145,7 +9128,7 @@ int32_t OTClient::ProcessUserCommand(
}
} // Get out og the big switch statement!

return CalcReturnVal(lReturnValue);
return static_cast<int32_t>(lReturnValue);
}

/// Used in RPC mode (instead of Connect.)
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion src/client/OpenTransactions.cpp
Expand Up @@ -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<int32_t>(requestNumber);
}

} // namespace opentxs

0 comments on commit f7cf2a8

Please sign in to comment.