140 #include <irrxml/irrXML.hpp>
147 #include <sys/time.h>
160 const OTString& acctType);
162 AccountList::AccountList()
168 : acctType_(acctType)
182 append.
Concatenate(
"<accountList type=\"%s\" count=\"%d\" >\n\n",
183 acctType.
Get(), mapAcctIDs_.size());
185 for (
auto& it : mapAcctIDs_) {
186 std::string assetTypeId = it.first;
187 std::string accountId = it.second;
188 OT_ASSERT((assetTypeId.size() > 0) && (accountId.size() > 0));
191 "<accountEntry assetTypeID=\"%s\" accountID=\"%s\" />\n\n",
192 assetTypeId.c_str(), accountId.c_str());
203 otErr <<
"AccountList::ReadFromXMLNode: Failed: Empty accountList "
204 "'type' attribute.\n";
211 otErr <<
"AccountList::ReadFromXMLNode: Failed: accountList 'type' "
212 "attribute contains unknown value.\n";
217 int32_t count = acctCount.
Exists() ? atoi(acctCount.
Get()) : 0;
219 while (count-- > 0) {
222 <<
"AccountList::ReadFromXMLNode: Failure: Unable to find "
223 "expected element.\n";
227 if ((xml->getNodeType() == EXN_ELEMENT) &&
228 (!strcmp(
"accountEntry", xml->getNodeName()))) {
229 OTString assetTypeID = xml->getAttributeValue(
231 OTString accountID = xml->getAttributeValue(
235 otErr <<
"Error loading accountEntry: Either the "
236 "assetTypeID (" << assetTypeID
237 <<
"), or the accountID (" << accountID
243 std::make_pair(assetTypeID.
Get(), accountID.
Get()));
246 otErr <<
"Expected accountEntry element in accountList.\n";
254 otOut <<
"*** AccountList::ReadFromXMLNode: Bad data? Expected "
255 "EXN_ELEMENT_END here, but "
256 "didn't get it. Returning false.\n";
266 mapWeakAccts_.clear();
279 bool& wasAcctCreated, int64_t stashTransNum)
281 std::shared_ptr<OTAccount> account;
282 wasAcctCreated =
false;
285 if (stashTransNum <= 0) {
287 <<
"AccountList::GetOrCreateAccount: Failed attempt to create "
288 "stash account without cron item #.\n";
295 std::string assetTypeIdString =
OTString(assetTypeId).
Get();
300 auto acctIDsIt = mapAcctIDs_.find(assetTypeIdString);
302 if (mapAcctIDs_.end() != acctIDsIt) {
304 std::string accountIdString = acctIDsIt->second;
305 auto weakIt = mapWeakAccts_.find(accountIdString);
308 if (mapWeakAccts_.end() != weakIt) {
310 std::shared_ptr<OTAccount> weakAccount(weakIt->second);
326 <<
"AccountList::GetOrCreateAccount: Warning: account ("
328 <<
") was already in memory so I gave you a "
329 "pointer to the existing one. (But who else has a "
340 mapWeakAccts_.erase(weakIt);
347 OTString acctIDString(accountIdString.c_str());
355 if (!loadedAccount) {
356 otErr <<
"Failed trying to load " << acctTypeString
357 <<
" account with account ID: " << acctIDString <<
'\n';
360 otErr <<
"Failed verifying server's signature on " << acctTypeString
361 <<
" account with account ID: " << acctIDString <<
'\n';
364 OTString strOwnerID(accountOwnerId);
365 otErr <<
"Failed verifying owner ID (" << strOwnerID <<
") on "
366 << acctTypeString <<
" account ID: " << acctIDString <<
'\n';
369 otLog3 <<
"Successfully loaded " << acctTypeString
370 <<
" account ID: " << acctIDString
371 <<
" Asset Type ID: " << assetTypeIdString <<
"\n";
373 account = std::shared_ptr<OTAccount>(loadedAccount);
376 mapWeakAccts_[acctIDString.Get()] =
377 std::weak_ptr<OTAccount>(account);
390 accountOwnerId, serverId, serverNym, message, acctType_, stashTransNum);
392 if (!createdAccount) {
393 otErr <<
" AccountList::GetOrCreateAccount: Failed trying to generate"
395 <<
" account with asset type ID: " << assetTypeIdString <<
"\n";
401 otOut <<
"Successfully created " << acctTypeString
402 <<
" account ID: " << acctIDString
403 <<
" Asset Type ID: " << assetTypeIdString <<
"\n";
405 account = std::shared_ptr<OTAccount>(createdAccount);
409 mapWeakAccts_[acctIDString.
Get()] = std::weak_ptr<OTAccount>(account);
413 wasAcctCreated =
true;
EXPORT bool VerifyOwnerByID(const OTIdentifier &nymId) const
static EXPORT OTAccount * GenerateNewAccount(const OTIdentifier &userId, const OTIdentifier &serverId, const OTPseudonym &serverNym, const OTMessage &message, AccountType acctType=simple, int64_t stashTransNum=0)
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otLog3
EXPORT std::shared_ptr< OTAccount > GetOrCreateAccount(OTPseudonym &serverNym, const OTIdentifier &ACCOUNT_OWNER_ID, const OTIdentifier &ASSET_TYPE_ID, const OTIdentifier &SERVER_ID, bool &wasAcctCreated, int64_t stashTransNum=0)
EXPORT int32_t ReadFromXMLNode(irr::io::IrrXMLReader *&xml, const OTString &acctType, const OTString &acctCount)
EXPORT void Concatenate(const char *arg,...)
void TranslateAccountTypeToString(OTAccount::AccountType type, OTString &acctType)
EXPORT bool Exists() const
OTAccount::AccountType TranslateAccountTypeStringToEnum(const OTString &acctType)
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT const char * Get() const
static bool SkipAfterLoadingField(irr::io::IrrXMLReader *&xml)
static bool SkipToElement(irr::io::IrrXMLReader *&xml)
OTLOG_IMPORT OTLogStream otErr
EXPORT void Serialize(OTString &append) const
EXPORT void GetString(OTString &theStr) const
virtual EXPORT bool VerifySignature(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
EXPORT void Release_AcctList()
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)