OTDB::OTPacker * OTASCIIArmor::GetPacker() { if (NULL == s_pPacker) { // WARNING: Do not change OTDB_DEFAULT_PACKER below unless you also change SetAndPackData() since it ASSUMES this. s_pPacker = OTDB::OTPacker::Create(OTDB_DEFAULT_PACKER); // Protobuf is the only one that works on all platforms right now. OT_ASSERT(NULL != s_pPacker); g_thePackerAngel.SetCleanupTargetPointer(s_pPacker); } return s_pPacker; }
// currently only "simple" accounts (normal user asset accounts) are added to this list // Any "special" accounts, such as basket reserve accounts, or voucher reserve accounts, // or cash reserve accounts, are not included on this list. // bool OTAssetContract::ForEachAccountRecord(OTAcctFunctor & theAction) // Loops through all the accounts for a given asset type, and calls Functor on each. { // Load up account list stringmap // if success, iterate through map and trigger theAction. // loop // theAction.Trigger(theAcct); OTString strAssetTypeID, strAcctRecordFile; this->GetIdentifier(strAssetTypeID); strAcctRecordFile.Format("%s.a", strAssetTypeID.Get()); // -------------------------------------------------------------- OTDB::Storable * pStorable = OTDB::QueryObject(OTDB::STORED_OBJ_STRING_MAP, OTFolders::Contract().Get(), strAcctRecordFile.Get()); OTCleanup<OTDB::Storable> theAngel(pStorable); // It will definitely be cleaned up. OTDB::StringMap * pMap = (NULL == pStorable) ? NULL : dynamic_cast<OTDB::StringMap *>(pStorable); // -------------------------------------------------------------- // There was definitely a StringMap loaded from local storage. // (Even an empty one, possibly.) This is the only block that matters in this function. // if (NULL != pMap) { OTIdentifier * pServerID = theAction.GetServerID(); OT_ASSERT_MSG(NULL != pServerID, "Assert: NULL Server ID on functor. (How did you even construct the thing?)"); // ------------------------------------- mapOfStrings & theMap = pMap->the_map; // todo: optimize: will probably have to use a database for this, int64_t term. // (What if there are a million acct IDs in this flat file? Not scaleable.) // FOR_EACH(mapOfStrings, theMap) { const std::string & str_acct_id = (*it).first; // Containing the account ID. const std::string & str_asset_id = (*it).second; // Containing the asset type ID. (Just in case someone copied the wrong file here...) // -------------------------------- if (false == strAssetTypeID.Compare(str_asset_id.c_str())) { OTLog::vError("OTAssetContract::ForEachAccountRecord: Error: wrong asset type ID (%s) when expecting: %s\n", str_asset_id.c_str(), strAssetTypeID.Get()); } else { OTAccount * pAccount = NULL; OTCleanup<OTAccount> theAcctAngel; bool bAlreadyLoaded = false; const OTIdentifier theAccountID(str_acct_id.c_str()); // Before loading it from local storage, let's first make sure it's not already loaded. // (theAction functor has a list of 'already loaded' accounts, just in case.) // mapOfAccounts * pLoadedAccounts = theAction.GetLoadedAccts(); if (NULL != pLoadedAccounts) // there are some accounts already loaded, { // let's see if the one we're looking for is there... mapOfAccounts::iterator found_it = pLoadedAccounts->find(str_acct_id); if (pLoadedAccounts->end() != found_it) // FOUND IT. { bAlreadyLoaded = true; pAccount = (*found_it).second; OT_ASSERT(NULL != pAccount); if (theAccountID != pAccount->GetPurportedAccountID()) { OTLog::Error("Error: the actual account didn't have the ID that the std::map SAID it had! (Should never happen.)\n"); bAlreadyLoaded = false; pAccount = NULL; } } } // ------------------------------------------------ // I guess it wasn't already loaded... // Let's try to load it. // if (NULL == pAccount) { pAccount = OTAccount::LoadExistingAccount(theAccountID, *pServerID); theAcctAngel.SetCleanupTargetPointer(pAccount); } // -------------------------------- const bool bSuccessLoadingAccount = ((pAccount != NULL) ? true:false ); if (bSuccessLoadingAccount) { const bool bTriggerSuccess = theAction.Trigger(*pAccount); if (!bTriggerSuccess) OTLog::vError("%s: Error: Trigger Failed.", __FUNCTION__); } else { OTLog::vError("%s: Error: Failed Loading Account!", __FUNCTION__); } // -------------------------------- } } // FOR_EACH return true; } // if pMap != NULL