void OTCron::UpdateContents() { // I release this because I'm about to repopulate it. m_xmlUnsigned.Release(); m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0"); // ------------------------------------------------------------- const OTString SERVER_ID(m_SERVER_ID); m_xmlUnsigned.Concatenate("<cron\n version=\"%s\"\n" " serverID=\"%s\"" " >\n\n", m_strVersion.Get(), SERVER_ID.Get()); // ------------------------------------------------------------- // Save the Market entries (the markets themselves are saved in a markets folder.) OTMarket * pMarket = NULL; for (mapOfMarkets::iterator ii = m_mapMarkets.begin(); ii != m_mapMarkets.end(); ++ii) { pMarket = (*ii).second; OT_ASSERT(NULL != pMarket); OTIdentifier MARKET_ID(*pMarket); OTString str_MARKET_ID(MARKET_ID); OTString str_ASSET_ID(pMarket->GetAssetID()); OTString str_CURRENCY_ID(pMarket->GetCurrencyID()); m_xmlUnsigned.Concatenate("<market\n marketID=\"%s\"\n" " assetID=\"%s\"\n" " currencyID=\"%s\"\n" " marketScale=\"%ld\"" " >\n\n", str_MARKET_ID.Get(), str_ASSET_ID.Get(), str_CURRENCY_ID.Get(), pMarket->GetScale()); } // ------------------------------------------------------------- // Save the Cron Items OTCronItem * pItem = NULL; for (mapOfCronItems::iterator ii = m_mapCronItems.begin(); ii != m_mapCronItems.end(); ++ii) { pItem = (*ii).second; OT_ASSERT(NULL != pItem); OTString strItem(*pItem); // Extract the cron item contract into string form. OTASCIIArmor ascItem(strItem); // Base64-encode that for storage. m_xmlUnsigned.Concatenate("<cronItem>\n%s</cronItem>\n\n", ascItem.Get()); } // ------------------------------------------------------------- // Save the transaction numbers. long lTransactionNumber = 0; for (listOfTransactionNumbers::iterator iii = m_listTransactionNumbers.begin(); iii != m_listTransactionNumbers.end(); ++iii) { lTransactionNumber = *iii; m_xmlUnsigned.Concatenate("<transactionNum value=\"%ld\" />\n\n", lTransactionNumber); } // for // ------------------------------------------------------------- m_xmlUnsigned.Concatenate("</cron>\n"); }
bool OTCron::GetMarketList (OTASCIIArmor & ascOutput, int & nMarketCount) { nMarketCount = 0; // This parameter is set to zero here, and incremented in the loop below. // ------------------------ OTMarket * pMarket = NULL; OTDB::MarketList * pMarketList = dynamic_cast<OTDB::MarketList*>(OTDB::CreateObject(OTDB::STORED_OBJ_MARKET_LIST)); OTCleanup<OTDB::MarketList> theListAngel(*pMarketList); // ----------------------------------------------------------- for (mapOfMarkets::iterator ii = m_mapMarkets.begin(); ii != m_mapMarkets.end(); ++ii) { pMarket = (*ii).second; OT_ASSERT(NULL != pMarket); OTDB::MarketData * pMarketData = dynamic_cast<OTDB::MarketData *>(OTDB::CreateObject(OTDB::STORED_OBJ_MARKET_DATA)); OTCleanup<OTDB::MarketData> theDataAngel(*pMarketData); // -------------------------------------------- const OTIdentifier MARKET_ID(*pMarket); const OTString str_MARKET_ID(MARKET_ID); const OTString str_ServerID(pMarket->GetServerID()); const OTString str_ASSET_ID(pMarket->GetAssetID()); const OTString str_CURRENCY_ID(pMarket->GetCurrencyID()); pMarketData->server_id = str_ServerID.Get(); pMarketData->market_id = str_MARKET_ID.Get(); pMarketData->asset_type_id = str_ASSET_ID.Get(); pMarketData->currency_type_id = str_CURRENCY_ID.Get(); // -------------------------------------------- const long & lScale = pMarket->GetScale(); pMarketData->scale = to_string<long>(lScale); // -------------------------------------------- const uint64_t theCurrentBid = pMarket->GetHighestBidPrice(); const uint64_t theCurrentAsk = pMarket->GetLowestAskPrice(); pMarketData->current_bid = to_string<uint64_t>(theCurrentBid); pMarketData->current_ask = to_string<uint64_t>(theCurrentAsk); // --------------------------------------------- const long & lLastSalePrice = pMarket->GetLastSalePrice(); const long & lTotalAvailableAssets = pMarket->GetTotalAvailableAssets(); pMarketData->total_assets = to_string<long>(lTotalAvailableAssets); pMarketData->last_sale_price = to_string<long>(lLastSalePrice); // --------------------------------------------- const mapOfOffers::size_type theBidCount = pMarket->GetBidCount(); const mapOfOffers::size_type theAskCount = pMarket->GetAskCount(); pMarketData->number_bids = to_string<mapOfOffers::size_type>(theBidCount); pMarketData->number_asks = to_string<mapOfOffers::size_type>(theAskCount); // --------------------------------------------- // In the past 24 hours. // (I'm not collecting this data yet, (maybe never), so these values aren't set at all.) // // pMarketData->volume_trades = ???; // pMarketData->volume_assets = ???; // pMarketData->volume_currency = ???; // // pMarketData->recent_highest_bid = ???; // pMarketData->recent_lowest_ask = ???; // --------------------------------------------- // *pMarketData is CLONED at this time (I'm still responsible to delete.) // That's also why I add it here, below: So the data is set right before the cloning occurs. // pMarketList->AddMarketData(*pMarketData); nMarketCount++; } // ------------------------------------------------------------- // Now pack the list into strOutput... if (nMarketCount == 0) return true; // Success, but the list contains 0 markets. else if (nMarketCount > 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(*pMarketList); // Now we PACK our market list. if (NULL == pBuffer) { OTLog::Error("Failed packing pMarketList in OTCron::GetMarketList. \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 ((theSize > 0) && (NULL != pUint)) { OTData theData(pUint, theSize); // This function will base64 ENCODE theData, // and then Set() that as the string contents. ascOutput.SetData(theData); // bool bSuccessSetData = false; // bSuccessSetData = ascOutput.SetData(theData); return true; } else OTLog::Error("OTCron::GetMarketList: 0 size, or null return value, while getting raw data from packed buffer.\n"); } else OTLog::vError("OTCron::GetMarketList: nMarketCount is less than zero: %d.\n", nMarketCount); return false; }