// Loops through ALL markets, and calls pMarket->GetNym_OfferList(NYM_ID, *pOfferList) for each. // Returns a list of all the offers that a specific Nym has on all the markets. // bool OTCron::GetNym_OfferList(OTASCIIArmor & ascOutput, const OTIdentifier & NYM_ID, int & nOfferCount) { nOfferCount = 0; // Outputs the number of offers on this nym. // --------------------------- OTDB::OfferListNym * pOfferList = dynamic_cast<OTDB::OfferListNym*>(OTDB::CreateObject(OTDB::STORED_OBJ_OFFER_LIST_NYM)); OTCleanup<OTDB::OfferListNym> theListAngel(*pOfferList); // ----------------------------------------------------------- FOR_EACH(mapOfMarkets, m_mapMarkets) { OTMarket * pMarket = (*it).second; OT_ASSERT(NULL != pMarket); int nNymOfferCount = 0; if (false == pMarket->GetNym_OfferList(NYM_ID, *pOfferList, nNymOfferCount)) // appends to *pOfferList, each iteration. { // may wish to add a log later. Anyway, keep iterationg and appending, then send back whatever we have. } else // Success! nOfferCount += nNymOfferCount; }
// Loops through ALL markets, and calls pMarket->GetNym_OfferList(NYM_ID, *pOfferList) for each. // Returns a list of all the offers that a specific Nym has on all the markets. // bool OTCron::GetNym_OfferList(OTASCIIArmor & ascOutput, const OTIdentifier & NYM_ID, int & nOfferCount) { nOfferCount = 0; // Outputs the number of offers on this nym. // --------------------------- OTDB::OfferListNym * pOfferList = dynamic_cast<OTDB::OfferListNym*>(OTDB::CreateObject(OTDB::STORED_OBJ_OFFER_LIST_NYM)); OTCleanup<OTDB::OfferListNym> theListAngel(*pOfferList); // ----------------------------------------------------------- for (mapOfMarkets::iterator ii = m_mapMarkets.begin(); ii != m_mapMarkets.end(); ++ii) { OTMarket * pMarket = (*ii).second; OT_ASSERT(NULL != pMarket); int nNymOfferCount = 0; if (false == pMarket->GetNym_OfferList(NYM_ID, *pOfferList, nNymOfferCount)) // appends to *pOfferList, each iteration. { // may wish to add a log later. Anyway, keep iterationg and appending, then send back whatever we have. } else // Success! nOfferCount += nNymOfferCount; } // ------------------------------------------------------------- // Now pack the list into strOutput... if (nOfferCount == 0) return true; // Success, but 0 offers being returned. (List is empty.) else if (nOfferCount > 0) { OTDB::Storage * pStorage = OTDB::GetDefaultStorage(); OT_ASSERT(NULL != pStorage); OTDB::OTPacker * pPacker = pStorage->GetPacker(); // No need to check for failure, since this already ASSERTS. No need to cleanup either. // ----------------------------- OTDB::PackedBuffer * pBuffer = pPacker->Pack(*pOfferList); // Now we PACK our nym's offer list. if (NULL == pBuffer) { OTLog::Error("Failed packing pOfferList in OTCron::GetNym_OfferList. \n"); return false; } OTCleanup<OTDB::PackedBuffer> theBufferAngel(*pBuffer); // make sure memory is cleaned up. // -------------------------------------------------------- // Now we need to translate pBuffer into strOutput. const uint8_t* pUint = static_cast<const uint8_t*>(pBuffer->GetData()); const size_t theSize = pBuffer->GetSize(); if ((NULL != pUint) || (theSize < 2)) { OTData theData(pUint, theSize); // This function will base64 ENCODE theData, // and then Set() that as the string contents. ascOutput.SetData(theData); return true; } else OTLog::Error("Null returned, or bad size, while getting buffer data in OTCron::GetNym_OfferList.\n"); } else OTLog::vError("Error: Less-than-zero nOfferCount in OTCron::GetNym_OfferList: %d.\n", nOfferCount); return false; }