public static boolean getTransactionNumbers(String serverID, String nymID, boolean bForceFirstCall) // defaults to true.
{
// System.out.println("DEBUGGING -- 1.");
//
OTBool bWasSent = new OTBool(false);
int nGetNumbers = -1;
if (bForceFirstCall) {
nGetNumbers = Helpers.getTransactionNumLowLevel(serverID, nymID, bWasSent); // <============ FIRST TRY
} else {
nGetNumbers = -1;
}
// System.out.println("DEBUGGING -- 2.");
if (!bForceFirstCall || // if the first call didn't happen, due to bForceFirstCall being false, that means the caller wants the rest of this to happen as though it did.
(bWasSent.getBooleanValue() && (nGetNumbers >= 1))
|| (!bWasSent.getBooleanValue() && (nGetNumbers == 0))) {
// System.out.println("DEBUGGING -- 3.");
// Because it was successful, we have to now SIGN FOR those numbers we requested.
//
int nProcess = Helpers.getAndProcessNymbox(serverID, nymID, bWasSent, true); // bForceDownload=true
// System.out.println("DEBUGGING -- 4.");
if ((bWasSent.getBooleanValue() && (1 == nProcess))
|| (!bWasSent.getBooleanValue() && (0 == nProcess))) {
// System.out.println("DEBUGGING -- 5.");
return true;
}
} else if ((nGetNumbers < (-1)) || // If value is LESS THAN (-1) (which is an unexpected value)
!bWasSent.getBooleanValue()) // or if the getTransactionNum message WASN'T EVEN SENT, then return.
{
// System.out.println("DEBUGGING -- 6.");
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getTransactionNumLowLevel returned unexpected value: " + nGetNumbers);
return false;
} // -----------------------------------------------------------------
// Below this point, the message WAS sent. -1 is error, 0 is failure, >0 is success.
// Now it's just about whether a reply was successful, or was even received.
//
else if (((-1) == nGetNumbers) || // Message sent, but then error receiving or loading the reply.
((0) == nGetNumbers)) // Received a reply, but status == failure on that reply.
{
// System.out.println("DEBUGGING -- 7.");
if ((-1) == nGetNumbers) {
System.out.println("Utility.getTransactionNumbers: FYI: Utility.getTransactionNumLowLevel did send, but returned error (-1). (Re-trying...)");
} else if ((0) == nGetNumbers) {
System.out.println("Utility.getTransactionNumbers: FYI: Utility.getTransactionNumLowLevel did send, but returned failure (0). (Re-trying...)");
}
// ---------------------------------
final int nGetRequest = Helpers.getRequestNumber(serverID, nymID);
// System.out.println("DEBUGGING -- 8.");
if (1 != nGetRequest) {
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getTransactionNumLowLevel failed, then "
+ "I tried to resync with getRequestNumber and then that failed too. (I give up.)");
return false;
}
// ---------------------------------
// System.out.println("DEBUGGING -- 9.");
OTBool bWasProcessSent = new OTBool(false);
OTBool bFoundNymboxItem = new OTBool(false);
final int nProcessNymbox = Helpers.getAndProcessNymbox(serverID, nymID, bWasProcessSent, true); //boolean bForceDownload=true
// System.out.println("DEBUGGING -- 10.");
if ((!bWasProcessSent.getBooleanValue() && ((nProcessNymbox < 0) || (nProcessNymbox > 1)))
|| (bWasProcessSent.getBooleanValue() && (nProcessNymbox != 1))) // -1 error, 0 failed (harvesting success), 1 success, >1 failed (harvesting NOT done) RequestNum is returned.
{
// System.out.println("DEBUGGING -- 11.");
// todo: if request num is returned probably don't have to do anything with it.
// Why not? Because future processNymbox will iterate Nymbox and search for all found
// items in the sent message buffer, and REMOVE them from it (as clearly they will be
// processed already.)
// The ones left over in the sent buffer, after this? Must be harvested!
// Hmm, solution: Use the "Flush Sent Messages" function, which is already
// there. Have it be smart enough to harvest all sent messages before flushing,
//
//
if (bWasProcessSent.getBooleanValue() && nProcessNymbox > 1) {
// System.out.println("DEBUGGING -- 12.");
String strNymbox = otapiJNI.OTAPI_Basic_LoadNymboxNoVerify(serverID, nymID); // FLUSH SENT MESSAGES!!!! (AND HARVEST.)
// System.out.println("DEBUGGING -- 13.");
// *******************************************************
if (Helpers.isValid(strNymbox)) {
otapiJNI.OTAPI_Basic_FlushSentMessages(false, //harvesting for retry == false
serverID,
nymID,
strNymbox);
}
// System.out.println("DEBUGGING -- 14.");
}
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getAndProcessNymbox. Returned value: " + nProcessNymbox);
return false;
}
// System.out.println("DEBUGGING -- 15.");
// -----------------------------------------------------------------
nGetNumbers = Helpers.getTransactionNumLowLevel(serverID, nymID, bWasSent); // <================= SECOND TRY
// System.out.println("DEBUGGING -- 16.");
// -----------------------------------------------------------------
if ((bWasSent.getBooleanValue() && (nGetNumbers >= 1)) || // if message was sent, and was a success.
(!bWasSent.getBooleanValue() && (nGetNumbers == 0))) // Or if message wasn't sent due to "you already signed out too many numbers--you need to process your Nymbox..."
{
// System.out.println("DEBUGGING -- 17.");
int nProcess = Helpers.getAndProcessNymbox(serverID, nymID, bWasSent, true); // bForceDownload=true
// System.out.println("DEBUGGING -- 18.");
if ((bWasSent.getBooleanValue() && (1 == nProcess))
|| (!bWasSent.getBooleanValue() && (0 == nProcess))) {
// System.out.println("DEBUGGING -- 19.");
return true;
}
} else if ((nGetNumbers < (-1))
|| (!bWasSent.getBooleanValue() && nGetNumbers != 0)) {
// System.out.println("DEBUGGING -- 20.");
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getTransactionNumLowLevel returned unexpected value: " + nGetNumbers);
return false;
} else if (((-1) == nGetNumbers)
|| ((0) == nGetNumbers)) {
// System.out.println("DEBUGGING -- 21.");
if ((-1) == nGetNumbers) {
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getTransactionNumLowLevel did send, but returned error (-1), "
+ "even after syncing the request number successfully. (Giving up.)");
} else if ((0) == nGetNumbers) {
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getTransactionNumLowLevel did send, but returned failure (0), "
+ "even after syncing the request number successfully. (Giving up.)");
}
// System.out.println("DEBUGGING -- 22.");
int nLast = Helpers.getAndProcessNymbox(serverID, nymID, bWasProcessSent, true); //boolean bForceDownload=true
if (((false == bWasProcessSent.getBooleanValue()) && ((nLast < 0) || (nLast > 1)))
|| ((true == bWasProcessSent.getBooleanValue()) && (nLast != 1))) // -1 error, 0 failed (harvesting success), 1 success, >1 failed (harvesting NOT done) RequestNum is returned.
{
// System.out.println("DEBUGGING -- 23.");
if (bWasProcessSent.getBooleanValue() && (nLast > 1)) {
// System.out.println("DEBUGGING -- 24.");
String strNymbox = otapiJNI.OTAPI_Basic_LoadNymboxNoVerify(serverID, nymID); // FLUSH SENT MESSAGES!!!! (AND HARVEST.)
// System.out.println("DEBUGGING -- 25.");
// *******************************************************
if (Helpers.isValid(strNymbox)) {
otapiJNI.OTAPI_Basic_FlushSentMessages(false, //harvesting for retry == false
serverID,
nymID,
strNymbox);
}
}
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getAndProcessNymbox. Returned value: " + nLast);
return false;
}
// System.out.println("DEBUGGING -- 27.");
nGetNumbers = Helpers.getTransactionNumLowLevel(serverID, nymID, bWasSent); // <============ FIRST TRY
// System.out.println("DEBUGGING -- 28.");
if ((bWasSent.getBooleanValue() && (nGetNumbers >= 1))
|| ((!bWasSent.getBooleanValue() && (nGetNumbers == 0)))) {
// System.out.println("DEBUGGING -- 29.");
int nProcess = Helpers.getAndProcessNymbox(serverID, nymID, bWasSent, true); // bForceDownload=true
// System.out.println("DEBUGGING -- 30.");
if ((bWasSent.getBooleanValue() && (1 == nProcess))
|| (!bWasSent.getBooleanValue() && (0 == nProcess))) {
// System.out.println("DEBUGGING -- 31.");
return true;
}
}
if ((nGetNumbers < (-1)) || // If value is LESS THAN (-1) (which is an unexpected value)
!bWasSent.getBooleanValue()) // or if the getTransactionNum message WASN'T EVEN SENT, then return.
{
// System.out.println("DEBUGGING -- 32.");
System.out.println("Utility.getTransactionNumbers: Failure: Utility.getTransactionNumLowLevel returned unexpected value: " + nGetNumbers);
return false;
}
}
}
// System.out.println("DEBUGGING -- 33.");
// BY THIS POINT, we have SUCCESSFULLY sent the getTransactionNumLowLevel message,
// and nGetNumbers contains its request number.
// -----
// No need to read the result, as getTransactionNumLowLevel() already read it,
// and and it's available anytime via Utility.getLastReplyReceived()
// -------------------------------------------------------------------------
final String strLastReplyReceived = Helpers.getLastReplyReceived();
if (!Helpers.isValid(strLastReplyReceived)) {
System.out.println("Utility.getTransactionNumbers: "
+ "ERROR in Utility.getLastReplyReceived(): why was this string not set, when Utility.getRequestNumber was otherwise an apparent success?");
return false; // (SHOULD NEVER HAPPEN. This string is set in the getRequestNumber function.)
}
//-------------------------------------------------
// BY THIS POINT, we have received a server reply: @getTransactionNum
// (Unless it is malformed.) It's definitely not null, nor empty.
//-------------------------------------------------
// Grab the NymboxHash on the @getTransactionNum reply, and also the one I
// already had on my client-side Nym... (So we can compare them.)
//
final String strServerHash = otapiJNI.OTAPI_Basic_Message_GetNymboxHash(strLastReplyReceived);
final boolean bServerhash = Helpers.isValid(strServerHash);
if (!bServerhash) {
System.out.println("Utility.getTransactionNumbers: Warning: Unable to retrieve server-side "
+ "NymboxHash from OT, from server @getTransactionNum reply:\n\n"
+ strLastReplyReceived);
// return false;
}
//-------------------------------------------------
final String strLocalHash = otapiJNI.OTAPI_Basic_GetNym_NymboxHash(serverID, nymID);
final boolean bLocalhash = Helpers.isValid(strLocalHash);
if (!bLocalhash) {
System.out.println("Utility.getTransactionNumbers: Warning: Unable to retrieve client-side NymboxHash from OT, "
+ "for:\n serverID: " + serverID + "\n nymID: " + nymID);
// return false;
}
//-------------------------------------------------
if (!bServerhash || !bLocalhash
|| (bServerhash && bLocalhash
&& !strServerHash.equals(strLocalHash))) // the hashes don't match -- so let's definitely re-try to download the latest nymbox.
{
// the getRequest worked, and the server hashes don't match,
// so let's get and process the Nymbox...
//
// System.out.println("DEBUGGING -- 34.");
OTBool bWasProcessSent = new OTBool(false);
OTBool bFoundNymboxItem = new OTBool(false);
final int nGetNymbox = Helpers.getAndProcessNymbox(serverID, nymID, bWasProcessSent, true); //boolean bForceDownload=true
if (((false == bWasProcessSent.getBooleanValue()) && ((nGetNymbox < 0) || (nGetNymbox > 1)))
|| ((true == bWasProcessSent.getBooleanValue()) && (nGetNymbox != 1))) // -1 error, 0 failed (harvesting success), 1 success, >1 failed (harvesting NOT done) RequestNum is returned.
{