bool DlgMarkets::LowLevelLoadMarketList(QString qstrServerID, QString qstrNymID, mapIDName & the_map) { if (qstrServerID.isEmpty() || qstrNymID.isEmpty()) return false; // ----------------------------------- OTDB::MarketList * pMarketList = LoadMarketListForServer(qstrServerID.toStdString()); OTCleanup<OTDB::MarketList> theAngel(pMarketList); if (NULL != pMarketList) { size_t nMarketDataCount = pMarketList->GetMarketDataCount(); for (size_t ii = 0; ii < nMarketDataCount; ++ii) { OTDB::MarketData * pMarketData = pMarketList->GetMarketData(ii); if (NULL == pMarketData) // Should never happen. continue; // ----------------------------------------------------------------------- QString qstrMarketID = QString::fromStdString(pMarketData->market_id); QString qstrScale = QString::fromStdString(pMarketData->scale); // ----------------------------------------------------------------------- QString qstrCompositeID = QString("%1,%2").arg(qstrMarketID).arg(qstrScale); // ----------------------------------------------------------------------- // This multimap will have multiple markets of the same key (from // different servers.) // m_mapMarkets.insertMulti(qstrCompositeID, VPtr<OTDB::MarketData>::asQVariant(pMarketData->clone())); // ----------------------------------------------------------------------- // Whereas this map will only have a single entry for each key. (Thus // we only add it here if it's not already present.) // mapIDName::iterator it_map = the_map.find(qstrCompositeID); if (the_map.end() == it_map) { const std::string str_asset_name = OTAPI_Wrap::GetAssetType_Name(pMarketData->asset_type_id); const std::string str_currency_name = OTAPI_Wrap::GetAssetType_Name(pMarketData->currency_type_id); // -------------------------- QString qstrMarketName = QString("%1 for %2"). arg(QString::fromStdString(str_asset_name)). arg(QString::fromStdString(str_currency_name)); // --------------------------- the_map.insert(qstrCompositeID, qstrMarketName); } // --------------------------- } // for } // ----------------------------------- return true; }
// NOTE: if the caller wants a list of servers NOT filtered by Nym, then he can // just directly use the OT API. So you'd only call THIS function if you DID // want it filtered by Nym (that's why the nym parameter isn't optional.) // bool MTContactHandler::GetServers(mapIDName & theMap, QString filterByNym) { QMutexLocker locker(&m_Mutex); QString str_select = QString("SELECT (`server_id`) FROM `nym_server` WHERE `nym_id`='%1'").arg(filterByNym); bool bFoundAny = false; int nRows = DBHandler::getInstance()->querySize(str_select); for(int ii=0; ii < nRows; ii++) { QString server_id = DBHandler::getInstance()->queryString(str_select, 0, ii); if (!server_id.isEmpty()) { QString server_name = QString::fromStdString(OTAPI_Wrap::GetServer_Name(server_id.toStdString())); if (!server_name.isEmpty()) { bFoundAny = true; // At this point we have the server ID *and* the server name. // So we can add them to our map... theMap.insert(server_id, server_name); } } } // --------------------------------------------------------------------- return bFoundAny; }
// The contact ID (unlike all the other IDs) is an int instead of a string. // Therefore we just convert it to a string and return it in a map in the same // format as all the others. // (FYI.) // bool MTContactHandler::GetContacts(mapIDName & theMap) { QMutexLocker locker(&m_Mutex); QString str_select = QString("SELECT * FROM contact"); bool bFoundAny = false; int nRows = DBHandler::getInstance()->querySize(str_select); for(int ii=0; ii < nRows; ii++) { int contact_id = DBHandler::getInstance()->queryInt (str_select, 0, ii); QString contact_name = DBHandler::getInstance()->queryString(str_select, 1, ii); if (contact_id > 0) { bFoundAny = true; QString str_contact_id; str_contact_id = QString("%1").arg(contact_id); if (!contact_name.isEmpty()) { // qDebug() << QString("About to decode name: %1").arg(contact_name); //Decode base64. OTASCIIArmor ascName; ascName.Set(contact_name.toStdString().c_str()); OTString strName(ascName); contact_name = QString(strName.Get()); } // -------------------------------------------------- // At this point we have the contact ID (in string form) *and* the contact name. // So we can add them to our map... theMap.insert(str_contact_id, contact_name); } } // --------------------------------------------------------------------- return bFoundAny; }
bool MTContactHandler::GetNyms(mapIDName & theMap, int nFilterByContact) //resume { QMutexLocker locker(&m_Mutex); QString str_select = QString("SELECT * FROM `nym` WHERE `contact_id`='%1'").arg(nFilterByContact); // QString str_select = QString("SELECT * FROM `nym` WHERE `contact_id`='%1' LIMIT 0,1").arg(nFilterByContact); bool bFoundAny = false; int nRows = DBHandler::getInstance()->querySize(str_select); for (int ii=0; ii < nRows; ii++) { QString nym_id = DBHandler::getInstance()->queryString(str_select, 0, ii); QString nym_name = DBHandler::getInstance()->queryString(str_select, 2, ii); if (!nym_id.isEmpty()) { bFoundAny = true; if (!nym_name.isEmpty()) { // qDebug() << QString("About to decode name: %1").arg(nym_name); //Decode base64. OTASCIIArmor ascName; ascName.Set(nym_name.toStdString().c_str()); OTString strName(ascName); nym_name = QString(strName.Get()); } // ---------------------------- // At this point we have the nym ID *and* the nym name. // So we can add them to our map... theMap.insert(nym_id, nym_name); } } // --------------------------------------------------------------------- return bFoundAny; }
bool MTContactHandler::GetAccounts(mapIDName & theMap, QString filterByNym, QString filterByServer, QString filterByAsset) { QMutexLocker locker(&m_Mutex); // ------------------------- mapIDName parameters; // ------------------------- if (!filterByNym.isEmpty()) parameters.insert("nym_id", filterByNym); // ------------------------- if (!filterByServer.isEmpty()) parameters.insert("server_id", filterByServer); // ------------------------- if (!filterByAsset.isEmpty()) parameters.insert("asset_id", filterByAsset); // ------------------------- // Construct the WHERE clause. // QString strParams; int nIteration = 0; while (!parameters.empty()) { nIteration++; // 1 on first iteration. // ---------------------------------- mapIDName::iterator the_beginning = parameters.begin(); if (parameters.end() == the_beginning) break; // Done. // ---------------------------------- QString strKey = the_beginning.key(); QString strValue = the_beginning.value(); // ---------------------------------- if (1 == nIteration) // first iteration { strParams = QString(" WHERE `%1`='%2'").arg(strKey).arg(strValue); } else // subsequent iterations. { strParams += QString(" AND `%1`='%2'").arg(strKey).arg(strValue); } // ---------------------------------- parameters.remove(strKey); } // while // --------------------------------- // Construct the SELECT statement and append the WHERE clause. // QString str_select = QString("SELECT * FROM `nym_account`"); if (!strParams.isEmpty()) str_select += strParams; // --------------------------------- bool bFoundAccounts = false; int nRows = DBHandler::getInstance()->querySize(str_select); for(int ii=0; ii < nRows; ii++) { QString account_id = DBHandler::getInstance()->queryString(str_select, 0, ii); QString account_nym_id = DBHandler::getInstance()->queryString(str_select, 2, ii); QString display_name = DBHandler::getInstance()->queryString(str_select, 4, ii); if (!display_name.isEmpty()) { // qDebug() << QString("About to decode name: %1").arg(display_name); //Decode base64. OTASCIIArmor ascName; ascName.Set(display_name.toStdString().c_str()); OTString strName(ascName); display_name = QString(strName.Get()); } //--------------------------------------------------- if (!account_id.isEmpty()) // Account ID is present. { if (display_name.isEmpty()) // Display name isn't. { // Look up the display name for the contact who owns the Nym who owns the Acct. // if (!account_nym_id.isEmpty()) { int nContactID = this->FindContactIDByNymID(account_nym_id); if (nContactID > 0) { display_name = this->GetContactName(nContactID); } } } // ---------------------- if (display_name.isEmpty()) // Display name isn't. { display_name = account_id; } // ---------------------- bFoundAccounts = true; theMap.insert(account_id, display_name); } } // for // --------------------------------- return bFoundAccounts; }
// ----------------------------------------------- bool DlgMarkets::LowLevelLoadOfferList(QString qstrServerID, QString qstrNymID, mapIDName & the_map, QString qstrMarketID) { if (qstrServerID.isEmpty() || qstrNymID.isEmpty() || qstrMarketID.isEmpty()) return false; // ----------------------------------- QString qstrAssetID, qstrCurrencyID, qstrMarketScale; const bool bGotIDs = GetMarket_AssetCurrencyScale(qstrMarketID, qstrAssetID, qstrCurrencyID, qstrMarketScale); // ----------------------------------- if (bGotIDs) { OTDB::OfferListNym * pOfferList = LoadOfferListForServer(qstrServerID.toStdString(), qstrNymID.toStdString()); OTCleanup<OTDB::OfferListNym> theAngel(pOfferList); if (NULL != pOfferList) { size_t nOfferDataCount = pOfferList->GetOfferDataNymCount(); for (size_t ii = 0; ii < nOfferDataCount; ++ii) { OTDB::OfferDataNym * pOfferData = pOfferList->GetOfferDataNym(ii); if (NULL == pOfferData) // Should never happen. continue; // ----------------------------------------------------------------------- QString qstrOfferAssetID = QString::fromStdString(pOfferData->asset_type_id); QString qstrOfferCurrencyID = QString::fromStdString(pOfferData->currency_type_id); QString qstrOfferScale = QString::fromStdString(pOfferData->scale); // ----------------------------------------------------------------------- if ((qstrAssetID != qstrOfferAssetID) || (qstrCurrencyID != qstrOfferCurrencyID) || (qstrMarketScale != qstrOfferScale)) continue; // ----------------------------------------------------------------------- QString qstrTransactionID = QString::fromStdString(pOfferData->transaction_id); // ----------------------------------------------------------------------- QString qstrCompositeID = QString("%1,%2").arg(qstrServerID).arg(qstrTransactionID); // ----------------------------------------------------------------------- QString qstrBuySell = pOfferData->selling ? tr("Sell") : tr("Buy"); const std::string str_asset_name = OTAPI_Wrap::GetAssetType_Name(pOfferData->asset_type_id); // -------------------------- int64_t lTotalAssets = OTAPI_Wrap::StringToLong(pOfferData->total_assets); int64_t lFinishedSoFar = OTAPI_Wrap::StringToLong(pOfferData->finished_so_far); // -------------------------- const std::string str_total_assets = OTAPI_Wrap::FormatAmount(pOfferData->asset_type_id, lTotalAssets); const std::string str_finished_so_far = OTAPI_Wrap::FormatAmount(pOfferData->asset_type_id, lFinishedSoFar); // -------------------------- QString qstrAmounts; if (lFinishedSoFar > 0) // "300g (40g finished so far)" qstrAmounts = QString("%1 (%2 %3)"). arg(QString::fromStdString(str_total_assets)). arg(QString::fromStdString(str_finished_so_far)). arg(tr("finished so far")); else // "300g" qstrAmounts = QString("%1"). arg(QString::fromStdString(str_total_assets)); // -------------------------- // "Buy Silver Grams: 300g (40g finished so far)"; // QString qstrOfferName = QString("%1 %2: %3"). arg(qstrBuySell). arg(QString::fromStdString(str_asset_name)). arg(qstrAmounts); // --------------------------- the_map.insert(qstrCompositeID, qstrOfferName); // --------------------------- // NOTE that m_mapMarkets is a multimap, since there can be multiple markets with // the exact same ID and scale, across multiple servers. The single entry from MTMarketDetails::m_map // is then mapped to a group of entries in m_mapMarkets, or to a single entry by cross-referencing // the server ID. // Whereas in m_mapOffers, each Offer can be uniquely identified (regardless of server) by its unique key: // serverID,transactionID. Therefore MTOfferDetails::m_map and m_mapOffers are both maps (neither is a // multimap) and each offer is uniquely identified by that same key on both maps. // (That's why you see an insert() here instead of insertMulti.) // m_mapOffers.insert(qstrCompositeID, VPtr<OTDB::OfferDataNym>::asQVariant(pOfferData->clone())); // ----------------------------------------------------------------------- } // for } } // ----------------------------------- return true; }