Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTAccount Class Reference

#include <OTAccount.hpp>

Inheritance diagram for opentxs::OTAccount:
Collaboration diagram for opentxs::OTAccount:

Public Types

enum  AccountType {
  simple, issuer, basket, basketsub,
  mint, voucher, stash, err_acct
}
 

Public Member Functions

EXPORT OTAccount (const OTIdentifier &userId, const OTIdentifier &accountId, const OTIdentifier &serverId, const OTString &name)
 
EXPORT OTAccount (const OTIdentifier &userId, const OTIdentifier &accountId, const OTIdentifier &serverId)
 
virtual EXPORT ~OTAccount ()
 
virtual EXPORT void Release ()
 
virtual EXPORT bool LoadContract ()
 
virtual EXPORT bool SaveContractWallet (std::ofstream &ofs) const
 
virtual EXPORT bool SaveContractWallet (OTString &contents) const
 
virtual EXPORT bool DisplayStatistics (OTString &contents) const
 
void MarkForDeletion ()
 
bool IsMarkedForDeletion () const
 
EXPORT bool IsInternalServerAcct () const
 
EXPORT bool IsOwnedByUser () const
 
EXPORT bool IsOwnedByEntity () const
 
EXPORT bool IsAllowedToGoNegative () const
 
EXPORT bool IsIssuer () const
 
EXPORT bool IsStashAcct () const
 
EXPORT const int64_t & GetStashTransNum () const
 
EXPORT void SetStashTransNum (const int64_t &transNum)
 
EXPORT void InitAccount ()
 
EXPORT void Release_Account ()
 
EXPORT bool GenerateNewAccount (const OTPseudonym &server, const OTMessage &message, AccountType acctType=simple, int64_t stashTransNum=0)
 
EXPORT OTLedgerLoadInbox (OTPseudonym &nym) const
 
EXPORT OTLedgerLoadOutbox (OTPseudonym &nym) const
 
EXPORT bool SaveInbox (OTLedger &box, OTIdentifier *hash=nullptr)
 
EXPORT bool SaveOutbox (OTLedger &box, OTIdentifier *nash=nullptr)
 
EXPORT const OTIdentifierGetAssetTypeID () const
 
EXPORT int64_t GetBalance () const
 
EXPORT bool Debit (const int64_t &amount)
 
EXPORT bool Credit (const int64_t &amount)
 
EXPORT bool VerifyOwner (const OTPseudonym &candidate) const
 
EXPORT bool VerifyOwnerByID (const OTIdentifier &nymId) const
 
EXPORT bool SaveAccount ()
 
EXPORT void SetInboxHash (const OTIdentifier &input)
 
EXPORT bool GetInboxHash (OTIdentifier &output)
 
EXPORT void SetOutboxHash (const OTIdentifier &input)
 
EXPORT bool GetOutboxHash (OTIdentifier &output)
 
EXPORT char const * GetTypeString () const
 
- Public Member Functions inherited from opentxs::OTTransactionType
EXPORT void GetNumList (OTNumList &theOutput)
 
bool Contains (const OTString &strContains)
 
EXPORT bool Contains (const char *szContains)
 
bool IsSameAccount (const OTTransactionType &rhs) const
 
void SetLoadInsecure ()
 
const OTIdentifierGetUserID () const
 
void SetUserID (const OTIdentifier &theID)
 
const OTIdentifierGetRealAccountID () const
 
void SetRealAccountID (const OTIdentifier &theID)
 
const OTIdentifierGetPurportedAccountID () const
 
void SetPurportedAccountID (const OTIdentifier &theID)
 
const OTIdentifierGetRealServerID () const
 
void SetRealServerID (const OTIdentifier &theID)
 
const OTIdentifierGetPurportedServerID () const
 
void SetPurportedServerID (const OTIdentifier &theID)
 
virtual EXPORT bool VerifyContractID () const
 
virtual bool VerifyAccount (const OTPseudonym &theNym)
 
 OTTransactionType (const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID)
 
 OTTransactionType (const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, int64_t lTransactionNum)
 
void InitTransactionType ()
 
virtual ~OTTransactionType ()
 
void Release_TransactionType ()
 
EXPORT int64_t GetTransactionNum () const
 
void SetTransactionNum (int64_t lTransactionNum)
 
virtual EXPORT void CalculateNumberOfOrigin ()
 
virtual EXPORT int64_t GetNumberOfOrigin ()
 
EXPORT int64_t GetRawNumberOfOrigin () const
 
EXPORT void SetNumberOfOrigin (int64_t lTransactionNum)
 
EXPORT void SetNumberOfOrigin (OTTransactionType &setFrom)
 
EXPORT bool VerifyNumberOfOrigin (OTTransactionType &compareTo)
 
EXPORT int64_t GetReferenceToNum () const
 
EXPORT void SetReferenceToNum (int64_t lTransactionNum)
 
EXPORT void GetReferenceString (OTString &theStr) const
 
EXPORT void SetReferenceString (const OTString &theStr)
 
- Public Member Functions inherited from opentxs::OTContract
const char * GetHashType () const
 
void SetIdentifier (const OTIdentifier &theID)
 
EXPORT OTContract ()
 
EXPORT OTContract (const OTString &name, const OTString &foldername, const OTString &filename, const OTString &strID)
 
EXPORT OTContract (const OTString &strID)
 
EXPORT OTContract (const OTIdentifier &theID)
 
void Initialize ()
 
virtual EXPORT ~OTContract ()
 
EXPORT void Release_Contract ()
 
EXPORT void ReleaseSignatures ()
 
virtual EXPORT bool CreateContract (const OTString &strContract, const OTPseudonym &theSigner)
 
EXPORT bool InsertNym (const OTString &strKeyName, const OTString &strKeyValue)
 
EXPORT void GetName (OTString &strName) const
 
EXPORT void SetName (const OTString &strName)
 
virtual EXPORT bool VerifyContract ()
 
virtual EXPORT void GetIdentifier (OTIdentifier &theIdentifier) const
 
virtual EXPORT void GetIdentifier (OTString &theIdentifier) const
 
EXPORT void GetFilename (OTString &strFilename) const
 
EXPORT void GetFoldername (OTString &strFoldername) const
 
EXPORT bool LoadContract (const char *szFoldername, const char *szFilename)
 
EXPORT bool LoadContractFromString (const OTString &theStr)
 
bool LoadContractRawFile ()
 
EXPORT bool ParseRawFile ()
 
EXPORT bool SaveToContractFolder ()
 
EXPORT bool SaveContractRaw (OTString &strOutput) const
 
EXPORT bool RewriteContract (OTString &strOutput) const
 
EXPORT bool SaveContract ()
 
EXPORT bool SaveContract (const char *szFoldername, const char *szFilename)
 
virtual EXPORT void CreateContents ()
 
EXPORT void CreateInnerContents ()
 
virtual EXPORT bool SaveContents (std::ofstream &ofs) const
 
virtual EXPORT bool SaveContents (OTString &strContents) const
 
virtual EXPORT bool SignContract (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContractAuthent (const OTPseudonym &theNym, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const OTAsymmetricKey &theKey, OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr)
 
EXPORT bool SignContract (const char *szFoldername, const char *szFilename, OTSignature &theSignature, const OTPasswordData *pPWData=nullptr)
 
virtual EXPORT void CalculateContractID (OTIdentifier &newID) const
 
virtual EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
virtual EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifyWithKey (const OTAsymmetricKey &theKey, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySigAuthent (const OTPseudonym &theNym, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const OTAsymmetricKey &theKey, const OTSignature &theSignature, const OTString &strHashType, const OTPasswordData *pPWData=nullptr) const
 
EXPORT bool VerifySignature (const char *szFoldername, const char *szFilename, const OTSignature &theSignature, const OTPasswordData *pPWData=nullptr) const
 
EXPORT const OTAsymmetricKeyGetContractPublicKey () const
 
EXPORT const OTPseudonymGetContractPublicNym () const
 

Static Public Member Functions

static EXPORT OTAccountGenerateNewAccount (const OTIdentifier &userId, const OTIdentifier &serverId, const OTPseudonym &serverNym, const OTMessage &message, AccountType acctType=simple, int64_t stashTransNum=0)
 
static EXPORT OTAccountLoadExistingAccount (const OTIdentifier &accountId, const OTIdentifier &serverId)
 
static EXPORT char const * _GetTypeString (AccountType accountType)
 
- Static Public Member Functions inherited from opentxs::OTTransactionType
static EXPORT OTTransactionTypeTransactionFactory (OTString strInput)
 
- Static Public Member Functions inherited from opentxs::OTContract
static EXPORT bool DearmorAndTrim (const OTString &strInput, OTString &strOutput, OTString &strFirstLine)
 
static bool AddBookendsAroundContent (OTString &strOutput, const OTString &strContents, const OTString &strContractType, const OTString &strHashType, const listOfSignatures &listSignatures)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
 
static EXPORT bool LoadEncodedTextField (irr::io::IrrXMLReader *&xml, OTString &strOutput)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool LoadEncodedTextFieldByName (irr::io::IrrXMLReader *&xml, OTString &strOutput, const char *&szName, OTString::Map *pmapExtraVars=nullptr)
 
static bool SkipToElement (irr::io::IrrXMLReader *&xml)
 
static bool SkipToTextField (irr::io::IrrXMLReader *&xml)
 
static bool SkipAfterLoadingField (irr::io::IrrXMLReader *&xml)
 
static EXPORT bool SignFlatText (OTString &strFlatText, const OTString &strContractType, const OTPseudonym &theSigner, OTString &strOutput)
 

Protected Member Functions

 OTAccount (const OTIdentifier &userId, const OTIdentifier &serverId)
 
 OTAccount ()
 
virtual int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
virtual void UpdateContents ()
 
- Protected Member Functions inherited from opentxs::OTTransactionType
 OTTransactionType ()
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

Protected Attributes

AccountType acctType_
 
OTIdentifier acctAssetTypeId_
 
OTString balanceDate_
 
OTString balanceAmount_
 
int64_t stashTransNum_
 
bool markForDeletion_
 
OTIdentifier inboxHash_
 
OTIdentifier outboxHash_
 
- Protected Attributes inherited from opentxs::OTTransactionType
OTIdentifier m_AcctID
 
OTIdentifier m_ServerID
 
OTIdentifier m_AcctServerID
 
OTIdentifier m_AcctUserID
 
int64_t m_lTransactionNum
 
int64_t m_lInReferenceToTransaction
 
int64_t m_lNumberOfOrigin
 
OTASCIIArmor m_ascInReferenceTo
 
bool m_bLoadSecurely
 
OTNumList m_Numlist
 
- Protected Attributes inherited from opentxs::OTContract
OTString m_strName
 
OTString m_strFoldername
 
OTString m_strFilename
 
OTIdentifier m_ID
 
OTStringXML m_xmlUnsigned
 
OTString m_strRawFile
 
OTString m_strSigHashType
 
OTString m_strContractType
 
mapOfNyms m_mapNyms
 
listOfSignatures m_listSignatures
 
OTString m_strVersion
 
OTString m_strEntityShortName
 
OTString m_strEntityLongName
 
OTString m_strEntityEmail
 
OTString::Map m_mapConditions
 

Friends

OTTransactionTypeOTTransactionType::TransactionFactory (OTString input)
 

Detailed Description

Definition at line 148 of file OTAccount.hpp.

Member Enumeration Documentation

Enumerator
simple 
issuer 
basket 
basketsub 
mint 
voucher 
stash 
err_acct 

Definition at line 156 of file OTAccount.hpp.

156  {
157  simple, // used by users
158  issuer, // used by issuers (these can only go negative.)
159  basket, // issuer acct used by basket currencies (these can only go
160  // negative)
161  basketsub, // used by the server (to store backing reserves for basket
162  // sub-accounts)
163  mint, // used by mints (to store backing reserves for cash)
164  voucher, // used by the server (to store backing reserves for
165  // vouchers)
166  stash, // used by the server (to store backing reserves for stashes,
167  // for smart contracts.)
168  err_acct
169  };

Constructor & Destructor Documentation

opentxs::OTAccount::OTAccount ( const OTIdentifier userId,
const OTIdentifier accountId,
const OTIdentifier serverId,
const OTString name 
)

Definition at line 194 of file OTAccount.cpp.

196  : OTTransactionType(userId, accountId, serverId)
197  , stashTransNum_(0)
198  , markForDeletion_(false)
199 {
200  InitAccount();
201  m_strName = name;
202 }
EXPORT void InitAccount()
Definition: OTAccount.cpp:454
int64_t stashTransNum_
Definition: OTAccount.hpp:293
opentxs::OTAccount::OTAccount ( const OTIdentifier userId,
const OTIdentifier accountId,
const OTIdentifier serverId 
)

Definition at line 204 of file OTAccount.cpp.

206  : OTTransactionType(userId, accountId, serverId)
207  , stashTransNum_(0)
208  , markForDeletion_(false)
209 {
210  InitAccount();
211 }
EXPORT void InitAccount()
Definition: OTAccount.cpp:454
int64_t stashTransNum_
Definition: OTAccount.hpp:293
opentxs::OTAccount::~OTAccount ( )
virtual

Definition at line 213 of file OTAccount.cpp.

214 {
215  Release_Account();
216 }
EXPORT void Release_Account()
Definition: OTAccount.cpp:1069
opentxs::OTAccount::OTAccount ( const OTIdentifier userId,
const OTIdentifier serverId 
)
protected

Definition at line 175 of file OTAccount.cpp.

177  , stashTransNum_(0)
178  , markForDeletion_(false)
179 {
180  InitAccount();
181  SetUserID(userId);
182  SetRealServerID(serverId);
183  SetPurportedServerID(serverId);
184 }
EXPORT void InitAccount()
Definition: OTAccount.cpp:454
int64_t stashTransNum_
Definition: OTAccount.hpp:293
void SetRealServerID(const OTIdentifier &theID)
void SetUserID(const OTIdentifier &theID)
void SetPurportedServerID(const OTIdentifier &theID)
opentxs::OTAccount::OTAccount ( )
protected

Definition at line 186 of file OTAccount.cpp.

188  , stashTransNum_(0)
189  , markForDeletion_(false)
190 {
191  InitAccount();
192 }
EXPORT void InitAccount()
Definition: OTAccount.cpp:454
int64_t stashTransNum_
Definition: OTAccount.hpp:293

Member Function Documentation

char const * opentxs::OTAccount::_GetTypeString ( AccountType  accountType)
static

Definition at line 218 of file OTAccount.cpp.

219 {
220  int32_t index = static_cast<int32_t>(accountType);
221  return __TypeStrings[index];
222 }
char const *const __TypeStrings[]
Definition: OTAccount.cpp:161
bool opentxs::OTAccount::Credit ( const int64_t &  amount)

Definition at line 415 of file OTAccount.cpp.

416 {
417  int64_t oldBalance = atol(balanceAmount_.Get());
418  // The PLUS here is the big difference between Debit and Credit.
419  int64_t newBalance = oldBalance + amount;
420 
421  // If the balance gets too big, it may flip to negative due to us using
422  // int64_t int32_t.
423  // We'll maybe explicitly check that it's not negative in order to prevent
424  // that. TODO.
425  // if (newBalance > 0 || (OTAccount::simple != acctType_))
426  // {
427  // balanceAmount_.Format("%lld", newBalance);
428  // return true;
429  // }
430 
431  // This is where issuer accounts get a pass. They just go negative.
432  // IF the new balance is less than zero...
433  // AND it's a normal account... (not an issuer)
434  // AND the new balance is even less than the old balance...
435  // THEN FAIL. The "new less than old" requirement is recent,
436  if (newBalance < 0 && !IsAllowedToGoNegative() && newBalance < oldBalance) {
437  return false;
438  }
439  // and it means that we now allow <0 credits on normal accounts,
440  // AS LONG AS the result is a HIGHER BALANCE :-)
441  else {
442  balanceAmount_.Format("%lld", newBalance);
443  time64_t t = OTTimeGetCurrentTime(); // Today, now.
444  balanceDate_.Format("%d", t);
445  return true;
446  }
447 }
OTString balanceDate_
Definition: OTAccount.hpp:289
int64_t time64_t
Definition: Common.hpp:209
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
EXPORT const char * Get() const
Definition: OTString.cpp:1045
EXPORT bool IsAllowedToGoNegative() const
Definition: OTAccount.cpp:1041
OTString balanceAmount_
Definition: OTAccount.hpp:290
bool opentxs::OTAccount::Debit ( const int64_t &  amount)

Definition at line 388 of file OTAccount.cpp.

389 {
390  int64_t oldBalance = atol(balanceAmount_.Get());
391  // The MINUS here is the big difference between Debit and Credit
392  int64_t newBalance = oldBalance - amount;
393 
394  // This is where issuer accounts get a pass. They just go negative.
395  //
396  // IF the new balance is less than zero...
397  // AND it's a normal account... (not an issuer)
398  // AND the new balance is even less than the old balance...
399  // THEN FAIL. The "new less than old" requirement is recent,
400  if (newBalance < 0 && !IsAllowedToGoNegative() && newBalance < oldBalance) {
401  return false;
402  }
403  // and it means that we now allow <0 debits on normal accounts,
404  // AS LONG AS the result is a HIGHER BALANCE :-)
405  else {
406  balanceAmount_.Format("%lld", newBalance);
407  time64_t t = OTTimeGetCurrentTime(); // Today, now.
408  balanceDate_.Format("%d", t);
409  return true;
410  }
411 }
OTString balanceDate_
Definition: OTAccount.hpp:289
int64_t time64_t
Definition: Common.hpp:209
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
EXPORT const char * Get() const
Definition: OTString.cpp:1045
EXPORT bool IsAllowedToGoNegative() const
Definition: OTAccount.cpp:1041
OTString balanceAmount_
Definition: OTAccount.hpp:290
bool opentxs::OTAccount::DisplayStatistics ( OTString contents) const
virtual

Reimplemented from opentxs::OTContract.

Definition at line 728 of file OTAccount.cpp.

729 {
730  OTString strAccountID(GetPurportedAccountID());
731  OTString strServerID(GetPurportedServerID());
732  OTString strUserID(GetUserID());
733  OTString strAssetTypeID(acctAssetTypeId_);
734 
735  OTString acctType;
737 
738  contents.Concatenate(" Asset Account (%s) Name: %s\n"
739  " Last retrieved Balance: %s on date: %s\n"
740  " accountID: %s\n"
741  " userID: %s\n"
742  " serverID: %s\n"
743  " assetTypeID: %s\n"
744  "\n",
745  acctType.Get(), m_strName.Get(), balanceAmount_.Get(),
746  balanceDate_.Get(), strAccountID.Get(),
747  strUserID.Get(), strServerID.Get(),
748  strAssetTypeID.Get());
749 
750  return true;
751 }
OTString balanceDate_
Definition: OTAccount.hpp:289
void TranslateAccountTypeToString(OTAccount::AccountType type, OTString &acctType)
Definition: OTAccount.cpp:697
const OTIdentifier & GetPurportedServerID() const
AccountType acctType_
Definition: OTAccount.hpp:286
EXPORT const char * Get() const
Definition: OTString.cpp:1045
const OTIdentifier & GetPurportedAccountID() const
OTString balanceAmount_
Definition: OTAccount.hpp:290
const OTIdentifier & GetUserID() const
OTIdentifier acctAssetTypeId_
Definition: OTAccount.hpp:288
OTAccount * opentxs::OTAccount::GenerateNewAccount ( const OTIdentifier userId,
const OTIdentifier serverId,
const OTPseudonym serverNym,
const OTMessage message,
OTAccount::AccountType  acctType = simple,
int64_t  stashTransNum = 0 
)
static

Definition at line 531 of file OTAccount.cpp.

537 {
538  OTAccount* account = new OTAccount(userId, serverId);
539 
540  if (account) {
541  // This is only for stash accounts.
542  if (account->GenerateNewAccount(serverNym, message, acctType,
543  stashTransNum)) {
544  return account;
545  }
546 
547  delete account;
548  account = nullptr;
549  }
550 
551  return nullptr;
552 }
bool opentxs::OTAccount::GenerateNewAccount ( const OTPseudonym server,
const OTMessage message,
OTAccount::AccountType  acctType = simple,
int64_t  stashTransNum = 0 
)

Definition at line 560 of file OTAccount.cpp.

564 {
565  // First we generate a secure random number into a binary object...
566  OTPayload payload;
567  // TODO: hardcoding. Plus: is 100 bytes of random a little much here?
568  if (!payload.Randomize(100)) {
569  otErr << __FUNCTION__ << ": Failed trying to acquire random numbers.\n";
570  return false;
571  }
572 
573  // Next we calculate that binary object into a message digest (an
574  // OTIdentifier).
575  OTIdentifier newID;
576  if (!newID.CalculateDigest(payload)) {
577  otErr << __FUNCTION__ << ": Error generating new account ID.\n";
578  return false;
579  }
580 
581  // Next we get that digest (which is a binary hash number)
582  // and extract a human-readable standard string format of that hash,
583  // into an OTString.
584  OTString strID(newID);
585 
586  // Set the account number based on what we just generated.
587  SetRealAccountID(newID);
588  // Might as well set them both. (Safe here to do so, for once.)
589  SetPurportedAccountID(newID);
590  // So it's not blank. The user can always change it.
591  m_strName.Set(strID);
592 
593  // Next we create the full path filename for the account using the ID.
595  m_strFilename = strID.Get();
596 
597  // Then we try to load it, in order to make sure that it doesn't already
598  // exist.
600  otErr << __FUNCTION__ << ": Account already exists: " << m_strFilename
601  << "\n";
602  return false;
603  }
604 
605  // Set up the various important starting values of the account.
606  // Account type defaults to OTAccount::simple.
607  // But there are also issuer accts.
608  acctType_ = acctType;
609 
610  // basket, basketsub, mint, voucher, and stash
611  // accounts are all "owned" by the server.
612  if (IsInternalServerAcct()) {
613  server.GetIdentifier(m_AcctUserID);
614  }
615  else {
616  m_AcctUserID.SetString(message.m_strNymID);
617  }
618 
619  acctAssetTypeId_.SetString(message.m_strAssetID);
620 
621  otLog3 << __FUNCTION__ << ": Creating new account, type:\n"
622  << message.m_strAssetID << "\n";
623 
624  OTIdentifier serverId(message.m_strServerID);
625  // TODO: this assumes the serverID on the message
626  // is correct. It's vetted, but still...
627  SetRealServerID(serverId);
628  SetPurportedServerID(serverId);
629 
630  time64_t t = OTTimeGetCurrentTime(); // Today, now.
631  balanceDate_.Format("%d", t);
632 
633  balanceAmount_.Set("0");
634 
635  if (IsStashAcct()) {
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.");
639  stashTransNum_ = stashTransNum;
640  }
641 
642  // Sign the Account (so we know that we did)... Otherwise someone could put
643  // a fake
644  // account file on the server if the code wasn't designed to verify the
645  // signature on the
646  // account.
647  SignContract(server);
648  SaveContract();
649 
650  // Save the Account to storage (based on its ID.)
651  SaveAccount();
652 
653  // Don't know why I had this here. Putting SaveAccount() instead.
654  // OTString strFilename(m_strFilename);
655  // SaveContract(strFilename.Get()); // Saves the account to a specific
656  // filename
657 
658  // No need to create the inbox and outbox ledgers...they will be created
659  // automatically if they do not exist when they are needed.
660 
661  return true;
662 }
friend class OTPayload
Definition: OTContract.hpp:165
int64_t stashTransNum_
Definition: OTAccount.hpp:293
EXPORT bool SaveContract()
OTString balanceDate_
Definition: OTAccount.hpp:289
void SetRealAccountID(const OTIdentifier &theID)
OTLOG_IMPORT OTLogStream otLog3
EXPORT bool IsInternalServerAcct() const
Definition: OTAccount.cpp:993
EXPORT bool IsStashAcct() const
Definition: OTAccount.hpp:205
int64_t time64_t
Definition: Common.hpp:209
void SetRealServerID(const OTIdentifier &theID)
EXPORT void SetString(const char *szString)
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
time64_t OTTimeGetCurrentTime()
Definition: Common.hpp:211
AccountType acctType_
Definition: OTAccount.hpp:286
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
EXPORT const char * Get() const
Definition: OTString.cpp:1045
virtual EXPORT bool SignContract(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
Definition: OTContract.cpp:484
OTLOG_IMPORT OTLogStream otErr
void SetPurportedServerID(const OTIdentifier &theID)
OTString balanceAmount_
Definition: OTAccount.hpp:290
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
EXPORT bool SaveAccount()
Definition: OTAccount.cpp:379
static EXPORT const OTString & Account()
Definition: OTFolders.cpp:295
void SetPurportedAccountID(const OTIdentifier &theID)
OTIdentifier acctAssetTypeId_
Definition: OTAccount.hpp:288
OTString m_strFoldername
Definition: OTContract.hpp:169
const OTIdentifier & opentxs::OTAccount::GetAssetTypeID ( ) const

Definition at line 449 of file OTAccount.cpp.

450 {
451  return acctAssetTypeId_;
452 }
OTIdentifier acctAssetTypeId_
Definition: OTAccount.hpp:288
int64_t opentxs::OTAccount::GetBalance ( ) const

Definition at line 664 of file OTAccount.cpp.

665 {
666  if (balanceAmount_.Exists()) {
667  return atol(balanceAmount_.Get());
668  }
669  return 0;
670 }
EXPORT bool Exists() const
Definition: OTString.cpp:1035
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTString balanceAmount_
Definition: OTAccount.hpp:290
bool opentxs::OTAccount::GetInboxHash ( OTIdentifier output)

Definition at line 317 of file OTAccount.cpp.

318 {
319  output.Release();
320 
321  if (!inboxHash_.IsEmpty()) {
322  output = inboxHash_;
323  return true;
324  }
325  else if (!GetUserID().IsEmpty() && !GetRealAccountID().IsEmpty() &&
326  !GetRealServerID().IsEmpty()) {
327  OTLedger inbox(GetUserID(), GetRealAccountID(), GetRealServerID());
328 
329  if (inbox.LoadInbox() && inbox.CalculateInboxHash(output)) {
330  SetInboxHash(output);
331  return true;
332  }
333  }
334 
335  return false;
336 }
EXPORT void SetInboxHash(const OTIdentifier &input)
Definition: OTAccount.cpp:312
OTIdentifier inboxHash_
Definition: OTAccount.hpp:299
const OTIdentifier & GetRealAccountID() const
EXPORT bool IsEmpty() const
Definition: OTData.cpp:291
const OTIdentifier & GetUserID() const
const OTIdentifier & GetRealServerID() const
bool opentxs::OTAccount::GetOutboxHash ( OTIdentifier output)

Definition at line 343 of file OTAccount.cpp.

344 {
345  output.Release();
346 
347  if (!outboxHash_.IsEmpty()) {
348  output = outboxHash_;
349  return true;
350  }
351  else if (!GetUserID().IsEmpty() && !GetRealAccountID().IsEmpty() &&
352  !GetRealServerID().IsEmpty()) {
353  OTLedger outbox(GetUserID(), GetRealAccountID(), GetRealServerID());
354 
355  if (outbox.LoadOutbox() && outbox.CalculateOutboxHash(output)) {
356  SetOutboxHash(output);
357  return true;
358  }
359  }
360 
361  return false;
362 }
EXPORT void SetOutboxHash(const OTIdentifier &input)
Definition: OTAccount.cpp:338
const OTIdentifier & GetRealAccountID() const
EXPORT bool IsEmpty() const
Definition: OTData.cpp:291
const OTIdentifier & GetUserID() const
const OTIdentifier & GetRealServerID() const
OTIdentifier outboxHash_
Definition: OTAccount.hpp:302
EXPORT const int64_t& opentxs::OTAccount::GetStashTransNum ( ) const
inline

Definition at line 210 of file OTAccount.hpp.

211  {
212  return stashTransNum_;
213  }
int64_t stashTransNum_
Definition: OTAccount.hpp:293
EXPORT char const* opentxs::OTAccount::GetTypeString ( ) const
inline

Definition at line 271 of file OTAccount.hpp.

272  {
273  return _GetTypeString(acctType_);
274  }
static EXPORT char const * _GetTypeString(AccountType accountType)
Definition: OTAccount.cpp:218
AccountType acctType_
Definition: OTAccount.hpp:286
void opentxs::OTAccount::InitAccount ( )

Definition at line 454 of file OTAccount.cpp.

455 {
456  m_strContractType = "ACCOUNT";
458 }
AccountType acctType_
Definition: OTAccount.hpp:286
OTString m_strContractType
Definition: OTContract.hpp:178
bool opentxs::OTAccount::IsAllowedToGoNegative ( ) const

Definition at line 1041 of file OTAccount.cpp.

1042 {
1043  switch (acctType_) {
1044  // issuer acct controlled by a user
1045  case OTAccount::issuer:
1046  // basket issuer acct controlled by the server (for a basket currency)
1047  case OTAccount::basket:
1048  return true;
1049  // user asset acct
1050  case OTAccount::simple:
1051  // internal server acct for storing reserves for basket sub currencies
1052  case OTAccount::basketsub:
1053  // internal server acct for storing reserves for cash withdrawals
1054  case OTAccount::mint:
1055  // internal server acct for storing reserves for
1056  // vouchers (like cashier's cheques)
1057  case OTAccount::voucher:
1058  // internal server acct for storing reserves for
1059  // smart contract stashes. (Money stashed IN the contract.)
1060  case OTAccount::stash:
1061  return false;
1062  default:
1063  otErr << "OTAccount::IsAllowedToGoNegative: Unknown account type.\n";
1064  return false;
1065  }
1066  return false;
1067 }
AccountType acctType_
Definition: OTAccount.hpp:286
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAccount::IsInternalServerAcct ( ) const

Definition at line 993 of file OTAccount.cpp.

994 {
995  switch (acctType_) {
996  case OTAccount::simple:
997  case OTAccount::issuer:
998  return false;
999  case OTAccount::basket:
1000  case OTAccount::basketsub:
1001  case OTAccount::mint:
1002  case OTAccount::voucher:
1003  case OTAccount::stash:
1004  return true;
1005  default:
1006  otErr << "OTAccount::IsInternalServerAcct: Unknown account type.\n";
1007  return false;
1008  }
1009  return false;
1010 }
AccountType acctType_
Definition: OTAccount.hpp:286
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTAccount::IsIssuer ( ) const

Definition at line 1036 of file OTAccount.cpp.

1037 {
1038  return OTAccount::issuer == acctType_;
1039 }
AccountType acctType_
Definition: OTAccount.hpp:286
bool opentxs::OTAccount::IsMarkedForDeletion ( ) const
inline

Definition at line 191 of file OTAccount.hpp.

192  {
193  return markForDeletion_;
194  }
bool opentxs::OTAccount::IsOwnedByEntity ( ) const

Definition at line 1031 of file OTAccount.cpp.

1032 {
1033  return false;
1034 }
bool opentxs::OTAccount::IsOwnedByUser ( ) const

Definition at line 1012 of file OTAccount.cpp.

1013 {
1014  switch (acctType_) {
1015  case OTAccount::simple:
1016  case OTAccount::issuer:
1017  return true;
1018  case OTAccount::basket:
1019  case OTAccount::basketsub:
1020  case OTAccount::mint:
1021  case OTAccount::voucher:
1022  case OTAccount::stash:
1023  return false;
1024  default:
1025  otErr << "OTAccount::IsOwnedByUser: Unknown account type.\n";
1026  return false;
1027  }
1028  return false;
1029 }
AccountType acctType_
Definition: OTAccount.hpp:286
OTLOG_IMPORT OTLogStream otErr
EXPORT bool opentxs::OTAccount::IsStashAcct ( ) const
inline

Definition at line 205 of file OTAccount.hpp.

206  {
207  return (acctType_ == stash);
208  }
AccountType acctType_
Definition: OTAccount.hpp:286
bool opentxs::OTAccount::LoadContract ( )
virtual

Reimplemented from opentxs::OTContract.

Definition at line 372 of file OTAccount.cpp.

373 {
374  OTString id;
375  GetIdentifier(id);
376  return OTContract::LoadContract(OTFolders::Account().Get(), id.Get());
377 }
virtual EXPORT bool LoadContract()
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
static EXPORT const OTString & Account()
Definition: OTFolders.cpp:295
OTAccount * opentxs::OTAccount::LoadExistingAccount ( const OTIdentifier accountId,
const OTIdentifier serverId 
)
static

Definition at line 480 of file OTAccount.cpp.

482 {
483  bool folderAlreadyExist = false;
484  bool folderIsNew = false;
485 
486  OTString strDataFolder = "";
487  OTString strAccountPath = "";
488  if (!OTDataFolder::Get(strDataFolder)) {
489  OT_FAIL;
490  }
491  if (!OTPaths::AppendFolder(strAccountPath, strDataFolder,
492  OTFolders::Account())) {
493  OT_FAIL;
494  }
495 
496  if (!OTPaths::ConfirmCreateFolder(strAccountPath, folderAlreadyExist,
497  folderIsNew)) {
498  otErr << "Unable to find or create accounts folder: "
499  << OTFolders::Account() << "\n";
500  return nullptr;
501  }
502 
503  OTAccount* account = new OTAccount();
504  OT_ASSERT(account != nullptr);
505 
506  account->SetRealAccountID(accountId);
507  account->SetRealServerID(serverId);
508 
509  OTString strAcctID(accountId);
510 
511  account->m_strFoldername = OTFolders::Account().Get();
512  account->m_strFilename = strAcctID.Get();
513 
514  if (!OTDB::Exists(account->m_strFoldername.Get(),
515  account->m_strFilename.Get())) {
516  otInfo << "OTAccount::LoadExistingAccount: File does not exist: "
517  << account->m_strFoldername << OTLog::PathSeparator()
518  << account->m_strFilename << "\n";
519  delete account;
520  return nullptr;
521  }
522 
523  if (account->LoadContract() && account->VerifyContractID()) {
524  return account;
525  }
526 
527  delete account;
528  return nullptr;
529 }
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
static EXPORT bool AppendFolder(OTString &out_strPath, const OTString &strBasePath, const OTString &strFolderName)
Definition: OTPaths.cpp:1212
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
#define OT_FAIL
Definition: Assert.hpp:139
static EXPORT bool ConfirmCreateFolder(const OTString &strExactPath, bool &out_Exists, bool &out_IsNew)
Definition: OTPaths.cpp:921
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
static EXPORT const OTString & Account()
Definition: OTFolders.cpp:295
static EXPORT OTString Get()
OTLedger * opentxs::OTAccount::LoadInbox ( OTPseudonym nym) const

Definition at line 225 of file OTAccount.cpp.

226 {
227  auto* box =
228  new OTLedger(GetUserID(), GetRealAccountID(), GetRealServerID());
229  OT_ASSERT(box != nullptr);
230 
231  if (box->LoadInbox() && box->VerifyAccount(nym)) {
232  return box;
233  }
234 
235  OTString strUserID(GetUserID()), strAcctID(GetRealAccountID());
236  otInfo << "Unable to load or verify inbox:\n" << strAcctID
237  << "\n For user:\n" << strUserID << "\n";
238  return nullptr;
239 }
const OTIdentifier & GetRealAccountID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
const OTIdentifier & GetUserID() const
const OTIdentifier & GetRealServerID() const
OTLedger * opentxs::OTAccount::LoadOutbox ( OTPseudonym nym) const

Definition at line 242 of file OTAccount.cpp.

243 {
244  auto* box =
245  new OTLedger(GetUserID(), GetRealAccountID(), GetRealServerID());
246  OT_ASSERT(nullptr != box);
247 
248  if (box->LoadOutbox() && box->VerifyAccount(nym)) {
249  return box;
250  }
251 
252  OTString strUserID(GetUserID()), strAcctID(GetRealAccountID());
253  otInfo << "Unable to load or verify outbox:\n" << strAcctID
254  << "\n For user:\n" << strUserID << "\n";
255  return nullptr;
256 }
const OTIdentifier & GetRealAccountID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
const OTIdentifier & GetUserID() const
const OTIdentifier & GetRealServerID() const
void opentxs::OTAccount::MarkForDeletion ( )
inline

Definition at line 186 of file OTAccount.hpp.

187  {
188  markForDeletion_ = true;
189  }
int32_t opentxs::OTAccount::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
protectedvirtual

Reimplemented from opentxs::OTContract.

Definition at line 854 of file OTAccount.cpp.

855 {
856  int32_t retval = 0;
857 
858  OTString strNodeName(xml->getNodeName());
859 
860  // Here we call the parent class first.
861  // If the node is found there, or there is some error,
862  // then we just return either way. But if it comes back
863  // as '0', then nothing happened, and we'll continue executing.
864  //
865  // -- Note you can choose not to call the parent if
866  // you don't want to use any of those xml tags.
867  // As I do below, in the case of OTAccount.
868  // if (retval = OTTransactionType::ProcessXMLNode(xml))
869  // return retval;
870 
871  if (strNodeName.Compare("assetAccount")) {
872  OTString acctType;
873 
874  m_strVersion = xml->getAttributeValue("version");
875  acctType = xml->getAttributeValue("type");
876 
877  if (!acctType.Exists()) {
878  otErr << "OTAccount::ProcessXMLNode: Failed: Empty assetAccount "
879  "'type' attribute.\n";
880  return -1;
881  }
882 
884 
886  otErr << "OTAccount::ProcessXMLNode: Failed: assetAccount 'type' "
887  "attribute contains unknown value.\n";
888  return -1;
889  }
890 
891  OTString strAcctAssetType = xml->getAttributeValue("assetTypeID");
892 
893  if (strAcctAssetType.Exists()) {
894  acctAssetTypeId_.SetString(strAcctAssetType);
895  }
896  OTString strAccountID(xml->getAttributeValue("accountID"));
897  OTString strServerID(xml->getAttributeValue("serverID"));
898  OTString strAcctUserID(xml->getAttributeValue("userID"));
899 
900  OTIdentifier ACCOUNT_ID(strAccountID);
901  OTIdentifier SERVER_ID(strServerID);
902  OTIdentifier USER_ID(strAcctUserID);
903 
904  SetPurportedAccountID(ACCOUNT_ID);
905  SetPurportedServerID(SERVER_ID);
906  SetUserID(USER_ID);
907 
908  OTString strAssetTypeID(acctAssetTypeId_);
909  otLog3 << "\n\nAccount Type: " << acctType
910  << "\nAccountID: " << strAccountID
911  << "\nUserID: " << strAcctUserID
912  << "\n"
913  "AssetTypeID: " << strAssetTypeID
914  << "\nServerID: " << strServerID << "\n";
915 
916  retval = 1;
917  }
918  else if (strNodeName.Compare("inboxHash")) {
919 
920  OTString strHash = xml->getAttributeValue("value");
921  if (strHash.Exists()) {
922  inboxHash_.SetString(strHash);
923  }
924  otLog3 << "Account inboxHash: " << strHash << "\n";
925 
926  retval = 1;
927  }
928  else if (strNodeName.Compare("outboxHash")) {
929 
930  OTString strHash = xml->getAttributeValue("value");
931  if (strHash.Exists()) {
932  outboxHash_.SetString(strHash);
933  }
934  otLog3 << "Account outboxHash: " << strHash << "\n";
935 
936  retval = 1;
937  }
938  else if (strNodeName.Compare("MARKED_FOR_DELETION")) {
939  markForDeletion_ = true;
940  otLog3 << "This asset account has been MARKED_FOR_DELETION (at some "
941  "point prior.)\n";
942 
943  retval = 1;
944  }
945  else if (strNodeName.Compare("balance")) {
946  balanceDate_ = xml->getAttributeValue("date");
947  balanceAmount_ = xml->getAttributeValue("amount");
948 
949  // I convert to integer / int64_t and back to string.
950  // (Just an easy way to keep the data clean.)
951 
952  int32_t date = atoi(balanceDate_.Get());
953  int64_t amount = atol(balanceAmount_.Get());
954 
955  balanceDate_.Format("%d", date);
956  balanceAmount_.Format("%lld", amount);
957 
958  otLog3 << "\nBALANCE -- " << balanceAmount_ << "\nDATE -- "
959  << balanceDate_ << "\n";
960 
961  retval = 1;
962  }
963  else if (strNodeName.Compare("stashinfo")) {
964  if (!IsStashAcct()) {
965  otErr << "OTAccount::ProcessXMLNode: Error: Encountered stashinfo "
966  "tag while loading NON-STASH account. \n";
967  return -1;
968  }
969 
970  int64_t lTransNum = 0;
971  OTString strStashTransNum = xml->getAttributeValue("cronItemNum");
972  if (!strStashTransNum.Exists() ||
973  ((lTransNum = atol(strStashTransNum.Get())) <= 0)) {
974  stashTransNum_ = 0;
975  otErr << "OTAccount::ProcessXMLNode: Error: Bad transaction number "
976  "for supposed corresponding cron item: " << lTransNum
977  << " \n";
978  return -1;
979  }
980  else {
981  stashTransNum_ = lTransNum;
982  }
983 
984  otLog3 << "\nSTASH INFO: CronItemNum -- " << stashTransNum_
985  << "\n";
986 
987  retval = 1;
988  }
989 
990  return retval;
991 }
int64_t stashTransNum_
Definition: OTAccount.hpp:293
OTString balanceDate_
Definition: OTAccount.hpp:289
OTLOG_IMPORT OTLogStream otLog3
EXPORT bool IsStashAcct() const
Definition: OTAccount.hpp:205
OTIdentifier inboxHash_
Definition: OTAccount.hpp:299
EXPORT void SetString(const char *szString)
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
OTAccount::AccountType TranslateAccountTypeStringToEnum(const OTString &acctType)
Definition: OTAccount.cpp:672
AccountType acctType_
Definition: OTAccount.hpp:286
EXPORT const char * Get() const
Definition: OTString.cpp:1045
void SetUserID(const OTIdentifier &theID)
OTLOG_IMPORT OTLogStream otErr
void SetPurportedServerID(const OTIdentifier &theID)
OTString balanceAmount_
Definition: OTAccount.hpp:290
void SetPurportedAccountID(const OTIdentifier &theID)
OTIdentifier acctAssetTypeId_
Definition: OTAccount.hpp:288
OTIdentifier outboxHash_
Definition: OTAccount.hpp:302
void opentxs::OTAccount::Release ( )
virtual

Reimplemented from opentxs::OTTransactionType.

Definition at line 1077 of file OTAccount.cpp.

1078 {
1079  Release_Account();
1081 }
EXPORT void Release_Account()
Definition: OTAccount.cpp:1069
void opentxs::OTAccount::Release_Account ( )

Definition at line 1069 of file OTAccount.cpp.

1070 {
1073  inboxHash_.Release();
1074  outboxHash_.Release();
1075 }
OTString balanceDate_
Definition: OTAccount.hpp:289
OTIdentifier inboxHash_
Definition: OTAccount.hpp:299
OTString balanceAmount_
Definition: OTAccount.hpp:290
virtual EXPORT void Release()
Definition: OTData.cpp:257
virtual EXPORT void Release()
Definition: OTString.cpp:765
OTIdentifier outboxHash_
Definition: OTAccount.hpp:302
bool opentxs::OTAccount::SaveAccount ( )

Definition at line 379 of file OTAccount.cpp.

380 {
381  OTString id;
382  GetIdentifier(id);
383  return SaveContract(OTFolders::Account().Get(), id.Get());
384 }
EXPORT bool SaveContract()
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
static EXPORT const OTString & Account()
Definition: OTFolders.cpp:295
bool opentxs::OTAccount::SaveContractWallet ( std::ofstream &  ofs) const
virtual

Reimplemented from opentxs::OTTransactionType.

Definition at line 782 of file OTAccount.cpp.

783 {
784  OTString strOutput;
785 
786  if (SaveContractWallet(strOutput)) {
787  ofs << strOutput;
788  return true;
789  }
790  return false;
791 }
virtual EXPORT bool SaveContractWallet(std::ofstream &ofs) const
Definition: OTAccount.cpp:782
bool opentxs::OTAccount::SaveContractWallet ( OTString contents) const
virtual

Reimplemented from opentxs::OTContract.

Definition at line 753 of file OTAccount.cpp.

754 {
755  OTString strAccountID(GetPurportedAccountID());
756  OTString strServerID(GetPurportedServerID());
757  OTString strUserID(GetUserID());
758  OTString strAssetTypeID(acctAssetTypeId_);
759 
760  OTString acctType;
762 
763  OTASCIIArmor ascName;
764  // name is in the clear in memory, and base64 in storage.
765  if (m_strName.Exists()) {
766  ascName.SetString(m_strName, false); // linebreaks == false
767  }
768 
769  contents.Concatenate(
770  "<!-- Last retrieved balance: %s on date: %s -->\n"
771  "<!-- Account type: %s --><assetAccount name=\"%s\"\n"
772  " accountID=\"%s\"\n"
773  " userID=\"%s\"\n"
774  " serverID=\"%s\" />\n"
775  "<!-- assetTypeID: %s -->\n\n",
776  balanceAmount_.Get(), balanceDate_.Get(), acctType.Get(),
777  m_strName.Exists() ? ascName.Get() : "", strAccountID.Get(),
778  strUserID.Get(), strServerID.Get(), strAssetTypeID.Get());
779  return true;
780 }
OTString balanceDate_
Definition: OTAccount.hpp:289
void TranslateAccountTypeToString(OTAccount::AccountType type, OTString &acctType)
Definition: OTAccount.cpp:697
EXPORT bool Exists() const
Definition: OTString.cpp:1035
const OTIdentifier & GetPurportedServerID() const
AccountType acctType_
Definition: OTAccount.hpp:286
EXPORT const char * Get() const
Definition: OTString.cpp:1045
const OTIdentifier & GetPurportedAccountID() const
OTString balanceAmount_
Definition: OTAccount.hpp:290
const OTIdentifier & GetUserID() const
OTIdentifier acctAssetTypeId_
Definition: OTAccount.hpp:288
bool opentxs::OTAccount::SaveInbox ( OTLedger box,
OTIdentifier hash = nullptr 
)

Definition at line 260 of file OTAccount.cpp.

261 {
262  if (!IsSameAccount(box)) {
263  OTString strAcctID(GetRealAccountID());
264  OTString strServerID(GetRealServerID());
265  OTString strBoxAcctID(box.GetRealAccountID());
266  OTString strBoxSvrID(box.GetRealServerID());
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";
272  return false;
273  }
274 
275  OTIdentifier theHash;
276  if (hash == nullptr) hash = &theHash;
277 
278  bool success = box.SaveInbox(hash);
279 
280  if (success) SetInboxHash(*hash);
281 
282  return success;
283 }
EXPORT void SetInboxHash(const OTIdentifier &input)
Definition: OTAccount.cpp:312
bool IsSameAccount(const OTTransactionType &rhs) const
const OTIdentifier & GetRealAccountID() const
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetRealServerID() const
bool opentxs::OTAccount::SaveOutbox ( OTLedger box,
OTIdentifier nash = nullptr 
)

Definition at line 287 of file OTAccount.cpp.

288 {
289  if (!IsSameAccount(box)) {
290  OTString strAcctID(GetRealAccountID());
291  OTString strServerID(GetRealServerID());
292  OTString strBoxAcctID(box.GetRealAccountID());
293  OTString strBoxSvrID(box.GetRealServerID());
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";
299  return false;
300  }
301 
302  OTIdentifier theHash;
303  if (hash == nullptr) hash = &theHash;
304 
305  bool success = box.SaveOutbox(hash);
306 
307  if (success) SetOutboxHash(*hash);
308 
309  return success;
310 }
EXPORT void SetOutboxHash(const OTIdentifier &input)
Definition: OTAccount.cpp:338
bool IsSameAccount(const OTTransactionType &rhs) const
const OTIdentifier & GetRealAccountID() const
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetRealServerID() const
void opentxs::OTAccount::SetInboxHash ( const OTIdentifier input)

Definition at line 312 of file OTAccount.cpp.

313 {
314  inboxHash_ = input;
315 }
OTIdentifier inboxHash_
Definition: OTAccount.hpp:299
void opentxs::OTAccount::SetOutboxHash ( const OTIdentifier input)

Definition at line 338 of file OTAccount.cpp.

339 {
340  outboxHash_ = input;
341 }
OTIdentifier outboxHash_
Definition: OTAccount.hpp:302
EXPORT void opentxs::OTAccount::SetStashTransNum ( const int64_t &  transNum)
inline

Definition at line 215 of file OTAccount.hpp.

216  {
217  stashTransNum_ = transNum;
218  }
int64_t stashTransNum_
Definition: OTAccount.hpp:293
void opentxs::OTAccount::UpdateContents ( )
protectedvirtual

Reimplemented from opentxs::OTContract.

Definition at line 804 of file OTAccount.cpp.

805 {
806  OTString strAssetTYPEID(acctAssetTypeId_);
807 
808  OTString ACCOUNT_ID(GetPurportedAccountID());
809  OTString SERVER_ID(GetPurportedServerID());
810  OTString USER_ID(GetUserID());
811 
812  OTString acctType;
814 
815  // I release this because I'm about to repopulate it.
817 
818  m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");
819 
820  m_xmlUnsigned.Concatenate("<assetAccount\n version=\"%s\"\n type=\"%s\"\n "
821  "accountID=\"%s\"\n userID=\"%s\"\n"
822  " serverID=\"%s\"\n assetTypeID=\"%s\" >\n\n",
823  m_strVersion.Get(), acctType.Get(),
824  ACCOUNT_ID.Get(), USER_ID.Get(), SERVER_ID.Get(),
825  strAssetTYPEID.Get());
826  if (IsStashAcct()) {
827  m_xmlUnsigned.Concatenate("<stashinfo cronItemNum=\"%lld\"/>\n\n",
829  }
830  if (!inboxHash_.IsEmpty()) {
831  OTString strHash(inboxHash_);
832  m_xmlUnsigned.Concatenate("<inboxHash value=\"%s\"/>\n\n",
833  strHash.Get());
834  }
835  if (!outboxHash_.IsEmpty()) {
836  OTString strHash(outboxHash_);
837  m_xmlUnsigned.Concatenate("<outboxHash value=\"%s\"/>\n\n",
838  strHash.Get());
839  }
840 
841  m_xmlUnsigned.Concatenate("<balance date=\"%s\" amount=\"%s\"/>\n\n",
843 
844  if (markForDeletion_) {
846  "<MARKED_FOR_DELETION>\n"
847  "%s</MARKED_FOR_DELETION>\n\n",
848  "THIS ACCOUNT HAS BEEN MARKED FOR DELETION AT ITS OWN REQUEST");
849  }
850  m_xmlUnsigned.Concatenate("</assetAccount>\n");
851 }
int64_t stashTransNum_
Definition: OTAccount.hpp:293
OTString balanceDate_
Definition: OTAccount.hpp:289
EXPORT bool IsStashAcct() const
Definition: OTAccount.hpp:205
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
void TranslateAccountTypeToString(OTAccount::AccountType type, OTString &acctType)
Definition: OTAccount.cpp:697
OTIdentifier inboxHash_
Definition: OTAccount.hpp:299
const OTIdentifier & GetPurportedServerID() const
AccountType acctType_
Definition: OTAccount.hpp:286
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
EXPORT const char * Get() const
Definition: OTString.cpp:1045
const OTIdentifier & GetPurportedAccountID() const
OTString balanceAmount_
Definition: OTAccount.hpp:290
EXPORT bool IsEmpty() const
Definition: OTData.cpp:291
const OTIdentifier & GetUserID() const
virtual EXPORT void Release()
Definition: OTString.cpp:765
OTIdentifier acctAssetTypeId_
Definition: OTAccount.hpp:288
OTIdentifier outboxHash_
Definition: OTAccount.hpp:302
bool opentxs::OTAccount::VerifyOwner ( const OTPseudonym candidate) const

Definition at line 463 of file OTAccount.cpp.

464 {
465  OTIdentifier ID_CANDIDATE;
466  // ID_CANDIDATE now contains the ID of the Nym we're testing.
467  candidate.GetIdentifier(ID_CANDIDATE);
468  return m_AcctUserID == ID_CANDIDATE;
469 }
bool opentxs::OTAccount::VerifyOwnerByID ( const OTIdentifier nymId) const

Definition at line 472 of file OTAccount.cpp.

473 {
474  return nymId == m_AcctUserID;
475 }

Friends And Related Function Documentation

Member Data Documentation

OTIdentifier opentxs::OTAccount::acctAssetTypeId_
protected

Definition at line 288 of file OTAccount.hpp.

AccountType opentxs::OTAccount::acctType_
protected

Definition at line 286 of file OTAccount.hpp.

OTString opentxs::OTAccount::balanceAmount_
protected

Definition at line 290 of file OTAccount.hpp.

OTString opentxs::OTAccount::balanceDate_
protected

Definition at line 289 of file OTAccount.hpp.

OTIdentifier opentxs::OTAccount::inboxHash_
protected

Definition at line 299 of file OTAccount.hpp.

bool opentxs::OTAccount::markForDeletion_
protected

Definition at line 295 of file OTAccount.hpp.

OTIdentifier opentxs::OTAccount::outboxHash_
protected

Definition at line 302 of file OTAccount.hpp.

int64_t opentxs::OTAccount::stashTransNum_
protected

Definition at line 293 of file OTAccount.hpp.


The documentation for this class was generated from the following files: