146 #include <irrxml/irrXML.hpp>
152 #include <sys/time.h>
178 , markForDeletion_(false)
189 , markForDeletion_(false)
198 , markForDeletion_(false)
208 , markForDeletion_(false)
220 int32_t index =
static_cast<int32_t
>(accountType);
231 if (box->LoadInbox() && box->VerifyAccount(nym)) {
236 otInfo <<
"Unable to load or verify inbox:\n" << strAcctID
237 <<
"\n For user:\n" << strUserID <<
"\n";
248 if (box->LoadOutbox() && box->VerifyAccount(nym)) {
253 otInfo <<
"Unable to load or verify outbox:\n" << strAcctID
254 <<
"\n For user:\n" << strUserID <<
"\n";
267 otErr <<
"OTAccount::SaveInbox: ERROR: The ledger passed in, isn't "
268 "even for this account!\n"
269 " Acct ID: " << strAcctID <<
"\n Other ID: " << strBoxAcctID
270 <<
"\n Server ID: " << strServerID
271 <<
"\n Other ID: " << strBoxSvrID <<
"\n";
276 if (hash ==
nullptr) hash = &theHash;
294 otErr <<
"OTAccount::SaveOutbox: ERROR: The ledger passed in, isn't "
295 "even for this account!\n"
296 " Acct ID: " << strAcctID <<
"\n Other ID: " << strBoxAcctID
297 <<
"\n Server ID: " << strServerID
298 <<
"\n Other ID: " << strBoxSvrID <<
"\n";
303 if (hash ==
nullptr) hash = &theHash;
392 int64_t newBalance = oldBalance - amount;
419 int64_t newBalance = oldBalance + amount;
483 bool folderAlreadyExist =
false;
484 bool folderIsNew =
false;
498 otErr <<
"Unable to find or create accounts folder: "
516 otInfo <<
"OTAccount::LoadExistingAccount: File does not exist: "
536 int64_t stashTransNum)
563 int64_t stashTransNum)
569 otErr << __FUNCTION__ <<
": Failed trying to acquire random numbers.\n";
577 otErr << __FUNCTION__ <<
": Error generating new account ID.\n";
621 otLog3 << __FUNCTION__ <<
": Creating new account, type:\n"
636 OT_ASSERT_MSG(stashTransNum > 0,
"You created a stash account, but "
637 "with a zero-or-negative transaction "
638 "number for its cron item.");
677 if (acctTypeString.
Compare(
"simple"))
679 else if (acctTypeString.
Compare(
"issuer"))
681 else if (acctTypeString.
Compare(
"basket"))
683 else if (acctTypeString.
Compare(
"basketsub"))
685 else if (acctTypeString.
Compare(
"mint"))
687 else if (acctTypeString.
Compare(
"voucher"))
689 else if (acctTypeString.
Compare(
"stash"))
692 otErr <<
"Error: Unknown account type: " << acctTypeString <<
"\n";
702 acctType.
Set(
"simple");
705 acctType.
Set(
"issuer");
708 acctType.
Set(
"basket");
711 acctType.
Set(
"basketsub");
714 acctType.
Set(
"mint");
717 acctType.
Set(
"voucher");
720 acctType.
Set(
"stash");
723 acctType.
Set(
"err_acct");
738 contents.
Concatenate(
" Asset Account (%s) Name: %s\n"
739 " Last retrieved Balance: %s on date: %s\n"
747 strUserID.
Get(), strServerID.
Get(),
748 strAssetTypeID.
Get());
770 "<!-- Last retrieved balance: %s on date: %s -->\n"
771 "<!-- Account type: %s --><assetAccount name=\"%s\"\n"
772 " accountID=\"%s\"\n"
774 " serverID=\"%s\" />\n"
775 "<!-- assetTypeID: %s -->\n\n",
778 strUserID.
Get(), strServerID.
Get(), strAssetTypeID.
Get());
821 "accountID=\"%s\"\n userID=\"%s\"\n"
822 " serverID=\"%s\"\n assetTypeID=\"%s\" >\n\n",
824 ACCOUNT_ID.
Get(), USER_ID.
Get(), SERVER_ID.
Get(),
825 strAssetTYPEID.
Get());
846 "<MARKED_FOR_DELETION>\n"
847 "%s</MARKED_FOR_DELETION>\n\n",
848 "THIS ACCOUNT HAS BEEN MARKED FOR DELETION AT ITS OWN REQUEST");
858 OTString strNodeName(xml->getNodeName());
871 if (strNodeName.Compare(
"assetAccount")) {
875 acctType = xml->getAttributeValue(
"type");
878 otErr <<
"OTAccount::ProcessXMLNode: Failed: Empty assetAccount "
879 "'type' attribute.\n";
886 otErr <<
"OTAccount::ProcessXMLNode: Failed: assetAccount 'type' "
887 "attribute contains unknown value.\n";
891 OTString strAcctAssetType = xml->getAttributeValue(
"assetTypeID");
893 if (strAcctAssetType.
Exists()) {
896 OTString strAccountID(xml->getAttributeValue(
"accountID"));
897 OTString strServerID(xml->getAttributeValue(
"serverID"));
898 OTString strAcctUserID(xml->getAttributeValue(
"userID"));
909 otLog3 <<
"\n\nAccount Type: " << acctType
910 <<
"\nAccountID: " << strAccountID
911 <<
"\nUserID: " << strAcctUserID
913 "AssetTypeID: " << strAssetTypeID
914 <<
"\nServerID: " << strServerID <<
"\n";
918 else if (strNodeName.Compare(
"inboxHash")) {
920 OTString strHash = xml->getAttributeValue(
"value");
924 otLog3 <<
"Account inboxHash: " << strHash <<
"\n";
928 else if (strNodeName.Compare(
"outboxHash")) {
930 OTString strHash = xml->getAttributeValue(
"value");
934 otLog3 <<
"Account outboxHash: " << strHash <<
"\n";
938 else if (strNodeName.Compare(
"MARKED_FOR_DELETION")) {
940 otLog3 <<
"This asset account has been MARKED_FOR_DELETION (at some "
945 else if (strNodeName.Compare(
"balance")) {
963 else if (strNodeName.Compare(
"stashinfo")) {
965 otErr <<
"OTAccount::ProcessXMLNode: Error: Encountered stashinfo "
966 "tag while loading NON-STASH account. \n";
970 int64_t lTransNum = 0;
971 OTString strStashTransNum = xml->getAttributeValue(
"cronItemNum");
972 if (!strStashTransNum.
Exists() ||
973 ((lTransNum = atol(strStashTransNum.
Get())) <= 0)) {
975 otErr <<
"OTAccount::ProcessXMLNode: Error: Bad transaction number "
976 "for supposed corresponding cron item: " << lTransNum
1006 otErr <<
"OTAccount::IsInternalServerAcct: Unknown account type.\n";
1025 otErr <<
"OTAccount::IsOwnedByUser: Unknown account type.\n";
1063 otErr <<
"OTAccount::IsAllowedToGoNegative: Unknown account type.\n";
virtual EXPORT bool LoadContract()
virtual void UpdateContents()
EXPORT void SetInboxHash(const OTIdentifier &input)
EXPORT void Release_Account()
virtual EXPORT void Release()
OTIdentifier m_AcctUserID
EXPORT void InitAccount()
EXPORT bool CalculateDigest(const OTData &dataInput)
virtual EXPORT bool DisplayStatistics(OTString &contents) const
EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT bool SaveOutbox(OTIdentifier *pOutboxHash=nullptr)
EXPORT const OTIdentifier & GetAssetTypeID() const
EXPORT bool SaveOutbox(OTLedger &box, OTIdentifier *nash=nullptr)
EXPORT int64_t GetBalance() const
EXPORT bool VerifyOwnerByID(const OTIdentifier &nymId) const
EXPORT bool SaveContract()
static EXPORT OTAccount * GenerateNewAccount(const OTIdentifier &userId, const OTIdentifier &serverId, const OTPseudonym &serverNym, const OTMessage &message, AccountType acctType=simple, int64_t stashTransNum=0)
static EXPORT const char * PathSeparator()
EXPORT OTLedger * LoadOutbox(OTPseudonym &nym) const
EXPORT void SetOutboxHash(const OTIdentifier &input)
virtual EXPORT ~OTAccount()
bool IsSameAccount(const OTTransactionType &rhs) const
void SetRealAccountID(const OTIdentifier &theID)
OTLOG_IMPORT OTLogStream otLog3
EXPORT bool IsInternalServerAcct() const
EXPORT bool IsStashAcct() const
EXPORT bool GetInboxHash(OTIdentifier &output)
EXPORT void Concatenate(const char *arg,...)
void TranslateAccountTypeToString(OTAccount::AccountType type, OTString &acctType)
EXPORT bool CalculateOutboxHash(OTIdentifier &theOutput)
void SetRealServerID(const OTIdentifier &theID)
EXPORT bool IsIssuer() const
static EXPORT char const * _GetTypeString(AccountType accountType)
EXPORT bool Exists() const
EXPORT bool SetString(const OTString &theData, bool bLineBreaks=true)
EXPORT void SetString(const char *szString)
EXPORT void Format(const char *fmt,...)
static EXPORT bool AppendFolder(OTString &out_strPath, const OTString &strBasePath, const OTString &strFolderName)
const OTIdentifier & GetRealAccountID() const
EXPORT bool Compare(const char *compare) const
virtual EXPORT bool SaveContractWallet(std::ofstream &ofs) const
EXPORT bool VerifyOwner(const OTPseudonym &candidate) const
const OTIdentifier & GetPurportedServerID() const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
time64_t OTTimeGetCurrentTime()
OTAccount::AccountType TranslateAccountTypeStringToEnum(const OTString &acctType)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
char const *const __TypeStrings[]
EXPORT OTLedger * LoadInbox(OTPseudonym &nym) const
OTString m_strContractType
#define OT_ASSERT_MSG(x, s)
OTLOG_IMPORT OTLogStream otInfo
virtual EXPORT bool LoadContract()
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
EXPORT bool IsOwnedByEntity() const
OTStringXML m_xmlUnsigned
static EXPORT bool ConfirmCreateFolder(const OTString &strExactPath, bool &out_Exists, bool &out_IsNew)
EXPORT bool GetOutboxHash(OTIdentifier &output)
EXPORT const char * Get() const
void SetUserID(const OTIdentifier &theID)
virtual EXPORT bool SignContract(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
EXPORT bool IsAllowedToGoNegative() const
EXPORT bool SaveInbox(OTLedger &box, OTIdentifier *hash=nullptr)
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetPurportedAccountID() const
void SetPurportedServerID(const OTIdentifier &theID)
virtual EXPORT bool VerifyContractID() const
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
EXPORT bool IsEmpty() const
const OTIdentifier & GetUserID() const
virtual EXPORT void Release()
EXPORT bool SaveAccount()
EXPORT bool Randomize(uint32_t size)
static EXPORT const OTString & Account()
EXPORT bool CalculateInboxHash(OTIdentifier &theOutput)
EXPORT bool Credit(const int64_t &amount)
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
EXPORT bool Debit(const int64_t &amount)
void SetPurportedAccountID(const OTIdentifier &theID)
virtual EXPORT void Release()
static EXPORT OTString Get()
const OTIdentifier & GetRealServerID() const
OTIdentifier acctAssetTypeId_
EXPORT bool IsOwnedByUser() const
EXPORT bool SaveInbox(OTIdentifier *pInboxHash=nullptr)