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

#include <OTLedger.hpp>

Inheritance diagram for opentxs::OTLedger:
Collaboration diagram for opentxs::OTLedger:

Public Types

enum  ledgerType {
  nymbox, inbox, outbox, message,
  paymentInbox, recordBox, expiredBox, error_state
}
 

Public Member Functions

ledgerType GetType () const
 
EXPORT bool LoadedLegacyData () const
 
EXPORT OTItemGenerateBalanceStatement (int64_t lAdjustment, const OTTransaction &theOwner, OTPseudonym &theNym, const OTAccount &theAccount, OTLedger &theOutbox)
 
EXPORT void ProduceOutboxReport (OTItem &theBalanceItem)
 
EXPORT bool AddTransaction (OTTransaction &theTransaction)
 
EXPORT bool RemoveTransaction (int64_t lTransactionNum, bool bDeleteIt=true)
 
EXPORT OTTransactionGetTransaction (OTTransaction::transactionType theType)
 
EXPORT OTTransactionGetTransaction (int64_t lTransactionNum) const
 
EXPORT OTTransactionGetTransactionByIndex (int32_t nIndex) const
 
EXPORT OTTransactionGetFinalReceipt (int64_t lReferenceNum)
 
EXPORT OTTransactionGetTransferReceipt (int64_t lNumberOfOrigin)
 
EXPORT OTTransactionGetChequeReceipt (int64_t lChequeNum, OTCheque **ppChequeOut=nullptr)
 
EXPORT int32_t GetTransactionIndex (int64_t lTransactionNum)
 
EXPORT OTTransactionGetReplyNotice (const int64_t &lRequestNum)
 
virtual EXPORT bool VerifyAccount (const OTPseudonym &theNym)
 
EXPORT bool LoadBoxReceipts (std::set< int64_t > *psetUnloaded=nullptr)
 
EXPORT bool SaveBoxReceipts ()
 
EXPORT bool LoadBoxReceipt (const int64_t &lTransactionNum)
 
EXPORT bool SaveBoxReceipt (const int64_t &lTransactionNum)
 
EXPORT bool DeleteBoxReceipt (const int64_t &lTransactionNum)
 
EXPORT bool LoadInbox ()
 
EXPORT bool SaveInbox (OTIdentifier *pInboxHash=nullptr)
 
EXPORT bool LoadNymbox ()
 
EXPORT bool SaveNymbox (OTIdentifier *pNymboxHash=nullptr)
 
EXPORT bool LoadOutbox ()
 
EXPORT bool SaveOutbox (OTIdentifier *pOutboxHash=nullptr)
 
EXPORT bool CalculateHash (OTIdentifier &theOutput)
 
EXPORT bool CalculateInboxHash (OTIdentifier &theOutput)
 
EXPORT bool CalculateOutboxHash (OTIdentifier &theOutput)
 
EXPORT bool CalculateNymboxHash (OTIdentifier &theOutput)
 
EXPORT bool SavePaymentInbox ()
 
EXPORT bool LoadPaymentInbox ()
 
EXPORT bool SaveRecordBox ()
 
EXPORT bool LoadRecordBox ()
 
EXPORT bool SaveExpiredBox ()
 
EXPORT bool LoadExpiredBox ()
 
EXPORT bool LoadLedgerFromString (const OTString &theStr)
 
EXPORT bool LoadInboxFromString (const OTString &strBox)
 
EXPORT bool LoadOutboxFromString (const OTString &strBox)
 
EXPORT bool LoadNymboxFromString (const OTString &strBox)
 
EXPORT bool LoadPaymentInboxFromString (const OTString &strBox)
 
EXPORT bool LoadRecordBoxFromString (const OTString &strBox)
 
EXPORT bool LoadExpiredBoxFromString (const OTString &strBox)
 
int32_t GetTransactionCount () const
 
EXPORT int32_t GetTransactionCountInRefTo (int64_t lReferenceNum) const
 
EXPORT int64_t GetTotalPendingValue ()
 
EXPORT const mapOfTransactionsGetTransactionMap () const
 
EXPORT OTLedger (const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID)
 
virtual EXPORT ~OTLedger ()
 
virtual EXPORT void Release ()
 
EXPORT void Release_Ledger ()
 
EXPORT void ReleaseTransactions ()
 
EXPORT OTLedger (const OTIdentifier &theAccountID, const OTIdentifier &theServerID)
 
EXPORT void InitLedger ()
 
EXPORT bool GenerateLedger (const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
 
virtual EXPORT bool SaveContractWallet (std::ofstream &ofs) const
 
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
 
 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
 
virtual EXPORT bool LoadContract ()
 
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 SaveContractWallet (OTString &strContents) const
 
virtual EXPORT bool DisplayStatistics (OTString &strContents) 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 OTLedgerGenerateLedger (const OTIdentifier &theUserID, const OTIdentifier &theAcctID, const OTIdentifier &theServerID, ledgerType theType, bool bCreateFile=false)
 
static EXPORT char const * _GetTypeString (ledgerType theType)
 
- 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)
 

Public Attributes

ledgerType m_Type
 
bool m_bLoadedLegacyData
 

Protected Member Functions

virtual int32_t ProcessXMLNode (irr::io::IrrXMLReader *&xml)
 
virtual void UpdateContents ()
 
 OTLedger ()
 
bool LoadGeneric (ledgerType theType, const OTString *pString=nullptr)
 
bool SaveGeneric (ledgerType theType)
 
- Protected Member Functions inherited from opentxs::OTTransactionType
 OTTransactionType ()
 
- Protected Member Functions inherited from opentxs::OTContract
bool LoadContractXML ()
 

Friends

OTTransactionTypeOTTransactionType::TransactionFactory (OTString strInput)
 

Additional Inherited Members

- 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
 

Detailed Description

Definition at line 160 of file OTLedger.hpp.

Member Enumeration Documentation

Enumerator
nymbox 
inbox 
outbox 
message 
paymentInbox 
recordBox 
expiredBox 
error_state 

Definition at line 181 of file OTLedger.hpp.

181  {
182  nymbox, // the nymbox is per user account (versus per asset account) and
183  // is used to receive new transaction numbers (and messages.)
184  inbox, // each asset account has an inbox, with pending transfers as
185  // well as receipts inside.
186  outbox, // if you SEND a pending transfer, it sits in your outbox until
187  // it's accepted, rejected, or canceled.
188  message, // used in OTMessages, to send various lists of transactions
189  // back and forth.
190  paymentInbox, // Used for client-side-only storage of incoming cheques,
191  // invoices, payment plan requests, etc. (Coming in from
192  // the Nymbox.)
193  recordBox, // Used for client-side-only storage of completed items from
194  // the inbox, and the paymentInbox.
195  expiredBox, // Used for client-side-only storage of expired items from
196  // the paymentInbox.
198  }; // If you add any types to this list, update the list of strings at the

Constructor & Destructor Documentation

opentxs::OTLedger::OTLedger ( )
protected

Definition at line 1152 of file OTLedger.cpp.

1153  : OTTransactionType()
1155  , m_bLoadedLegacyData(false)
1156 {
1157  InitLedger();
1158 }
bool m_bLoadedLegacyData
Definition: OTLedger.hpp:202
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT void InitLedger()
Definition: OTLedger.cpp:1105
opentxs::OTLedger::OTLedger ( const OTIdentifier theUserID,
const OTIdentifier theAccountID,
const OTIdentifier theServerID 
)

Definition at line 1122 of file OTLedger.cpp.

1125  : OTTransactionType(theUserID, theAccountID, theServerID)
1127  , m_bLoadedLegacyData(false)
1128 {
1129  InitLedger();
1130 }
bool m_bLoadedLegacyData
Definition: OTLedger.hpp:202
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT void InitLedger()
Definition: OTLedger.cpp:1105
opentxs::OTLedger::~OTLedger ( )
virtual

Definition at line 2446 of file OTLedger.cpp.

2447 {
2448  Release_Ledger();
2449 }
EXPORT void Release_Ledger()
Definition: OTLedger.cpp:2463
opentxs::OTLedger::OTLedger ( const OTIdentifier theAccountID,
const OTIdentifier theServerID 
)

Definition at line 1139 of file OTLedger.cpp.

1141  : OTTransactionType()
1143  , m_bLoadedLegacyData(false)
1144 {
1145  InitLedger();
1146 
1147  SetRealAccountID(theAccountID);
1148  SetRealServerID(theServerID);
1149 }
bool m_bLoadedLegacyData
Definition: OTLedger.hpp:202
void SetRealAccountID(const OTIdentifier &theID)
void SetRealServerID(const OTIdentifier &theID)
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT void InitLedger()
Definition: OTLedger.cpp:1105

Member Function Documentation

char const * opentxs::OTLedger::_GetTypeString ( ledgerType  theType)
static

Definition at line 171 of file OTLedger.cpp.

172 {
173  int32_t nType = static_cast<int32_t>(theType);
174  return __TypeStrings[nType];
175 }
char const *const __TypeStrings[]
Definition: OTAccount.cpp:161
bool opentxs::OTLedger::AddTransaction ( OTTransaction theTransaction)

Definition at line 1194 of file OTLedger.cpp.

1195 {
1196  // See if there's something else already there with the same transaction
1197  // number.
1198  auto it = m_mapTransactions.find(theTransaction.GetTransactionNum());
1199 
1200  // If it's not already on the list, then add it...
1201  if (it == m_mapTransactions.end()) {
1202  m_mapTransactions[theTransaction.GetTransactionNum()] = &theTransaction;
1203  theTransaction.SetParent(*this); // for convenience
1204  return true;
1205  }
1206  // Otherwise, if it was already there, log an error.
1207  else {
1208  otErr << "Attempt to add Transaction to ledger when already there for "
1209  "that number: " << theTransaction.GetTransactionNum() << "\n";
1210  }
1211 
1212  return false;
1213 }
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::CalculateHash ( OTIdentifier theOutput)

Definition at line 756 of file OTLedger.cpp.

757 {
758  theOutput.Release();
759 
760  bool bCalcDigest = theOutput.CalculateDigest(m_xmlUnsigned);
761  if (!bCalcDigest) {
762  theOutput.Release();
763  otErr << "OTLedger::CalculateHash: Failed trying to calculate hash "
764  "(for a " << GetTypeString() << ")\n";
765  }
766 
767  return bCalcDigest;
768 }
EXPORT char const * GetTypeString() const
Definition: OTLedger.hpp:373
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::CalculateInboxHash ( OTIdentifier theOutput)

Definition at line 770 of file OTLedger.cpp.

771 {
772  if (m_Type != OTLedger::inbox) {
773  otErr << "Wrong ledger type passed to OTLedger::CalculateInboxHash.\n";
774  return false;
775  }
776 
777  return CalculateHash(theOutput);
778 }
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT bool CalculateHash(OTIdentifier &theOutput)
Definition: OTLedger.cpp:756
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::CalculateNymboxHash ( OTIdentifier theOutput)

Definition at line 790 of file OTLedger.cpp.

791 {
792  if (m_Type != OTLedger::nymbox) {
793  otErr << "Wrong ledger type passed to OTLedger::CalculateNymboxHash.\n";
794  return false;
795  }
796 
797  return CalculateHash(theOutput);
798 }
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT bool CalculateHash(OTIdentifier &theOutput)
Definition: OTLedger.cpp:756
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::CalculateOutboxHash ( OTIdentifier theOutput)

Definition at line 780 of file OTLedger.cpp.

781 {
782  if (m_Type != OTLedger::outbox) {
783  otErr << "Wrong ledger type passed to OTLedger::CalculateOutboxHash.\n";
784  return false;
785  }
786 
787  return CalculateHash(theOutput);
788 }
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT bool CalculateHash(OTIdentifier &theOutput)
Definition: OTLedger.cpp:756
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::DeleteBoxReceipt ( const int64_t &  lTransactionNum)

Definition at line 296 of file OTLedger.cpp.

297 {
298 
299  // First, see if the transaction itself exists on this ledger.
300  // Get a pointer to it.
301  OTTransaction* pTransaction = GetTransaction(lTransactionNum);
302 
303  if (nullptr == pTransaction) {
304  otOut << "OTLedger::DeleteBoxReceipt: Unable to delete (overwrite) box "
305  "receipt " << lTransactionNum
306  << ": couldn't find the transaction on this ledger.\n";
307  return false;
308  }
309 
310  return pTransaction->DeleteBoxReceipt(*this);
311 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTTransaction * GetTransaction(OTTransaction::transactionType theType)
Definition: OTLedger.cpp:1215
OTItem * opentxs::OTLedger::GenerateBalanceStatement ( int64_t  lAdjustment,
const OTTransaction theOwner,
OTPseudonym theNym,
const OTAccount theAccount,
OTLedger theOutbox 
)

Only if it is an inbox, a ledger will loop through the transactions and produce the XML output for the report that's necessary during a balance agreement. (Any balance agreement for an account must include the list of transactions the nym has issued for use, as well as a listing of the transactions in the inbox for that account. This function does that last part :)

returns a new balance statement item containing the inbox report CALLER IS RESPONSIBLE TO DELETE.

Definition at line 1532 of file OTLedger.cpp.

1537 {
1538  if (OTLedger::inbox != GetType()) {
1539  otErr << "OTLedger::GenerateBalanceStatement: Wrong ledger type.\n";
1540  return nullptr;
1541  }
1542 
1543  const OTIdentifier theNymID(theNym);
1544 
1545  if ((theAccount.GetPurportedAccountID() != GetPurportedAccountID()) ||
1546  (theAccount.GetPurportedServerID() != GetPurportedServerID()) ||
1547  (theAccount.GetUserID() != GetUserID())) {
1548  otErr << "Wrong Account passed in to "
1549  "OTLedger::GenerateBalanceStatement.\n";
1550  return nullptr;
1551  }
1552  if ((theOutbox.GetPurportedAccountID() != GetPurportedAccountID()) ||
1553  (theOutbox.GetPurportedServerID() != GetPurportedServerID()) ||
1554  (theOutbox.GetUserID() != GetUserID())) {
1555  otErr << "Wrong Outbox passed in to "
1556  "OTLedger::GenerateBalanceStatement.\n";
1557  return nullptr;
1558  }
1559  if ((theNymID != GetUserID())) {
1560  otErr << "Wrong Nym passed in to OTLedger::GenerateBalanceStatement.\n";
1561  return nullptr;
1562  }
1563 
1564  // theOwner is the withdrawal, or deposit, or whatever, that wants to change
1565  // the account balance, and thus that needs a new balance agreement signed.
1566  //
1567  OTItem* pBalanceItem = OTItem::CreateItemFromTransaction(
1568  theOwner, OTItem::balanceStatement); // <=== balanceStatement type, with
1569  // user ID, server ID, account ID,
1570  // transaction ID.
1571 
1572  // The above has an ASSERT, so this this will never actually happen.
1573  if (nullptr == pBalanceItem) return nullptr;
1574 
1575  // COPY THE ISSUED TRANSACTION NUMBERS FROM THE NYM to the MESSAGE NYM.
1576 
1577  OTPseudonym theMessageNym;
1578 
1579  theMessageNym.HarvestIssuedNumbers(
1581  theNym /*unused in this case, not saving to disk*/, theNym,
1582  false); // bSave = false;
1583 
1584  switch (theOwner.GetType()) {
1585  // These six options will remove the transaction number from the issued
1586  // list, SUCCESS OR FAIL.
1587  // Server will expect the number to be missing from the list, in the case of
1588  // these.
1589  // Therefore I remove it here in order to generate a proper balance
1590  // agreement, acceptable to the server.
1597 
1598  theMessageNym.RemoveIssuedNum(
1599  theOwner.GetRealServerID(),
1600  theOwner.GetTransactionNum()); // a transaction number is being
1601  // used, and REMOVED from my list of
1602  // responsibility,
1603  theMessageNym.RemoveTransactionNum(
1604  theOwner.GetRealServerID(),
1605  theOwner.GetTransactionNum()); // a transaction number is being
1606  // used, and REMOVED from my list of
1607  // available numbers.
1608  break;
1609 
1614  // Nothing removed here since the transaction is still in play.
1615  // (Assuming success.)
1616  // If the server replies with rejection for any of these three, then I
1617  // can remove
1618  // the transaction number from my list of issued/signed for. But if
1619  // success, then I
1620  // am responsible for the transaction number until I sign off on closing
1621  // it.
1622  // Since the Balance Statement ANTICIPATES SUCCESS, NOT FAILURE, it
1623  // assumes the number
1624  // to be "in play" here, and thus DOES NOT remove it (vs the cases
1625  // above, which do.)
1626  break;
1627  default:
1628  // Error
1629  otErr << "OTLedger::" << __FUNCTION__
1630  << ": wrong owner transaction type: " << theOwner.GetTypeString()
1631  << "\n";
1632  break;
1633  }
1634 
1635  OTString strMessageNym(theMessageNym); // Okay now we have the transaction
1636  // numbers in this MessageNym string.
1637 
1638  pBalanceItem->SetAttachment(strMessageNym); // <======== This is where the
1639  // server will read the
1640  // transaction numbers from (A
1641  // nym in item.m_ascAttachment)
1642 
1643  int64_t lCurrentBalance = theAccount.GetBalance();
1644 
1645  pBalanceItem->SetAmount(lCurrentBalance + lAdjustment); // <==== Here's the
1646  // new (predicted)
1647  // balance for after
1648  // the transaction
1649  // is complete.
1650  // (item.GetAmount)
1651 
1652  // loop through the INBOX transactions, and produce a sub-item onto
1653  // pBalanceItem for each, which will
1654  // be a report on each transaction in this inbox, therefore added to the
1655  // balance item.
1656  // (So the balance item contains a complete report on the receipts in this
1657  // inbox.)
1658 
1659  otInfo << "About to loop through the inbox items and produce a report for "
1660  "each one...\n";
1661 
1662  for (auto& it : m_mapTransactions) {
1663  OTTransaction* pTransaction = it.second;
1664  OT_ASSERT(nullptr != pTransaction);
1665 
1666  otInfo << "Producing a report...\n";
1667 
1668  // it only reports receipts where we don't yet have balance agreement.
1669  // pTransaction->ProduceInboxReportItem(*pBalanceItem,
1670  // const_cast<OTTransaction&>(theOwner));
1671  pTransaction->ProduceInboxReportItem(
1672  *pBalanceItem); // <======= This function adds a receipt sub-item to
1673  // pBalanceItem, where appropriate for INBOX items.
1674  }
1675 
1676  theOutbox.ProduceOutboxReport(*pBalanceItem); // <======= This function adds
1677  // receipt sub-items to
1678  // pBalanceItem, where
1679  // appropriate for the OUTBOX
1680  // items.
1681 
1682  pBalanceItem->SignContract(theNym); // <=== Sign, save, and return.
1683  // OTTransactionType needs to weasel in
1684  // a "date signed" variable.
1685  pBalanceItem->SaveContract();
1686 
1687  return pBalanceItem;
1688 }
static EXPORT OTItem * CreateItemFromTransaction(const OTTransaction &theOwner, OTItem::itemType theType, const OTIdentifier *pDestinationAcctID=nullptr)
Definition: OTItem.cpp:1451
const OTIdentifier & GetPurportedServerID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otInfo
ledgerType GetType() const
Definition: OTLedger.hpp:212
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetPurportedAccountID() const
const OTIdentifier & GetUserID() const
OTLedger * opentxs::OTLedger::GenerateLedger ( const OTIdentifier theUserID,
const OTIdentifier theAcctID,
const OTIdentifier theServerID,
ledgerType  theType,
bool  bCreateFile = false 
)
static

Definition at line 946 of file OTLedger.cpp.

951 {
952  OTLedger* pLedger = new OTLedger(theUserID, theAcctID, theServerID);
953  OT_ASSERT(nullptr != pLedger);
954 
955  pLedger->GenerateLedger(theAcctID, theServerID, theType, bCreateFile);
956  pLedger->SetUserID(theUserID);
957 
958  return pLedger;
959 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool opentxs::OTLedger::GenerateLedger ( const OTIdentifier theAcctID,
const OTIdentifier theServerID,
ledgerType  theType,
bool  bCreateFile = false 
)

Definition at line 961 of file OTLedger.cpp.

964 {
965  // First we set the "Safe" ID and try to load the file, to make sure it
966  // doesn't already exist.
967  OTString strID(theAcctID), strServerID(theServerID);
968 
969  switch (theType) {
970  case OTLedger::nymbox: // stored by NymID ONLY.
972  m_strFilename.Format("%s%s%s", strServerID.Get(),
973  OTLog::PathSeparator(), strID.Get());
974  break;
975  case OTLedger::inbox: // stored by AcctID ONLY.
977  m_strFilename.Format("%s%s%s", strServerID.Get(),
978  OTLog::PathSeparator(), strID.Get());
979  break;
980  case OTLedger::outbox: // stored by AcctID ONLY.
982  m_strFilename.Format("%s%s%s", strServerID.Get(),
983  OTLog::PathSeparator(), strID.Get());
984  break;
985  case OTLedger::paymentInbox: // stored by NymID ONLY.
987  m_strFilename.Format("%s%s%s", strServerID.Get(),
988  OTLog::PathSeparator(), strID.Get());
989  break;
990  case OTLedger::recordBox: // stored by Acct ID *and* Nym ID (depending on
991  // the box.)
993  m_strFilename.Format("%s%s%s", strServerID.Get(),
994  OTLog::PathSeparator(), strID.Get());
995  break;
996  case OTLedger::expiredBox: // stored by Nym ID only.
998  m_strFilename.Format("%s%s%s", strServerID.Get(),
999  OTLog::PathSeparator(), strID.Get());
1000  break;
1001  case OTLedger::message:
1002  otLog4 << "Generating message ledger...\n";
1003  SetRealAccountID(theAcctID);
1004  SetPurportedAccountID(theAcctID); // It's safe to set these the same
1005  // here, since we're creating the
1006  // ledger now.
1007  SetRealServerID(theServerID);
1008  SetPurportedServerID(theServerID); // Always want the server ID on
1009  // anything that the server signs.
1010  m_Type = theType;
1011  return true;
1012  default:
1013  OT_FAIL_MSG("OTLedger::GenerateLedger: GenerateLedger is only for "
1014  "message, nymbox, inbox, outbox, and paymentInbox "
1015  "ledgers.\n");
1016  }
1017 
1018  m_Type = theType; // Todo make this Get/Set methods
1019 
1020  SetRealAccountID(theAcctID); // set this before calling LoadContract... (In
1021  // this case, will just be the Nym ID as
1022  // well...)
1023  SetRealServerID(theServerID); // (Ledgers/transactions/items were originally
1024  // meant just for account-related functions.)
1025 
1026  if (bCreateFile) {
1027 
1028  OTString strFilename;
1029  strFilename = strID.Get();
1030 
1031  const char* szFolder1name =
1032  m_strFoldername.Get(); // "nymbox" (or "inbox" or "outbox")
1033  const char* szFolder2name = strServerID.Get(); // "nymbox/SERVER_ID"
1034  const char* szFilename =
1035  strFilename.Get(); // "nymbox/SERVER_ID/USER_ID" (or
1036  // "inbox/SERVER_ID/ACCT_ID" or
1037  // "outbox/SERVER_ID/ACCT_ID")
1038 
1039  if (OTDB::Exists(szFolder1name, szFolder2name, szFilename)) {
1040  otOut << "ERROR: trying to generate ledger that already exists: "
1041  << szFolder1name << OTLog::PathSeparator() << szFolder2name
1042  << OTLog::PathSeparator() << szFilename << "\n";
1043  return false;
1044  }
1045 
1046  // Okay, it doesn't already exist. Let's generate it.
1047  otOut << "Generating " << szFolder1name << OTLog::PathSeparator()
1048  << szFolder2name << OTLog::PathSeparator() << szFilename << "\n";
1049  }
1050 
1051  if ((OTLedger::inbox == theType) || (OTLedger::outbox == theType)) {
1052  // Have to look up the UserID here. No way around it. We need that ID.
1053  // Plus it helps verify things.
1054  std::unique_ptr<OTAccount> pAccount(
1055  OTAccount::LoadExistingAccount(theAcctID, theServerID));
1056 
1057  if (nullptr != pAccount)
1058  SetUserID(pAccount->GetUserID());
1059  else {
1060  otErr << "OTLedger::GenerateLedger: Failed in "
1061  "OTAccount::LoadExistingAccount().\n";
1062  return false;
1063  }
1064  }
1065  else if (OTLedger::recordBox == theType) {
1066  // RecordBox COULD be by NymID OR AcctID.
1067  // So we TRY to lookup the acct.
1068  //
1069  std::unique_ptr<OTAccount> pAccount(
1070  OTAccount::LoadExistingAccount(theAcctID, theServerID));
1071 
1072  if (nullptr != pAccount) // Found it!
1073  SetUserID(pAccount->GetUserID());
1074  else // Must be based on NymID, not AcctID (like Nymbox. But RecordBox
1075  // can go either way.)
1076  {
1077  SetUserID(theAcctID); // In the case of nymbox, and sometimes with
1078  // recordBox, the acct ID IS the user ID.
1079  }
1080  }
1081  else {
1082  // In the case of paymentInbox, expired box, and nymbox, the acct ID IS
1083  // the user ID.
1084  // (Should change it to "owner ID" to make it sound right either way.)
1085  //
1086  SetUserID(theAcctID);
1087  }
1088 
1089  // Notice I still don't actually create the file here. The programmer still
1090  // has to call
1091  // "SaveNymbox", "SaveInbox" or "SaveOutbox" or "SaveRecordBox" or
1092  // "SavePaymentInbox" to
1093  // actually save the file. But he cannot do that unless he generates it
1094  // first here, and
1095  // the "bCreateFile" parameter insures that he isn't overwriting one that is
1096  // already there
1097  // (even if we don't actually save the file in this function.)
1098  //
1099  SetPurportedAccountID(theAcctID);
1100  SetPurportedServerID(theServerID);
1101 
1102  return true;
1103 }
OTLOG_IMPORT OTLogStream otLog4
static EXPORT const OTString & PaymentInbox()
Definition: OTFolders.cpp:339
static EXPORT const OTString & ExpiredBox()
Definition: OTFolders.cpp:363
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otOut
void SetRealAccountID(const OTIdentifier &theID)
static EXPORT const OTString & Inbox()
Definition: OTFolders.cpp:315
void SetRealServerID(const OTIdentifier &theID)
static EXPORT const OTString & Nymbox()
Definition: OTFolders.cpp:331
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
ledgerType m_Type
Definition: OTLedger.hpp:200
static EXPORT const OTString & Outbox()
Definition: OTFolders.cpp:335
#define OT_FAIL_MSG(s)
Definition: Assert.hpp:144
EXPORT const char * Get() const
Definition: OTString.cpp:1045
void SetUserID(const OTIdentifier &theID)
OTLOG_IMPORT OTLogStream otErr
void SetPurportedServerID(const OTIdentifier &theID)
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
static EXPORT const OTString & RecordBox()
Definition: OTFolders.cpp:359
static EXPORT OTAccount * LoadExistingAccount(const OTIdentifier &accountId, const OTIdentifier &serverId)
Definition: OTAccount.cpp:480
void SetPurportedAccountID(const OTIdentifier &theID)
OTString m_strFoldername
Definition: OTContract.hpp:169
OTTransaction * opentxs::OTLedger::GetChequeReceipt ( int64_t  lChequeNum,
OTCheque **  ppChequeOut = nullptr 
)

Definition at line 1402 of file OTLedger.cpp.

1406 {
1407  for (auto& it : m_mapTransactions) {
1408  OTTransaction* pCurrentReceipt = it.second;
1409  OT_ASSERT(nullptr != pCurrentReceipt);
1410 
1411  if ((pCurrentReceipt->GetType() != OTTransaction::chequeReceipt) &&
1412  (pCurrentReceipt->GetType() != OTTransaction::voucherReceipt))
1413  continue;
1414 
1415  OTString strDepositChequeMsg;
1416  pCurrentReceipt->GetReferenceString(strDepositChequeMsg);
1417 
1418  std::unique_ptr<OTItem> pOriginalItem(OTItem::CreateItemFromString(
1419  strDepositChequeMsg, GetPurportedServerID(),
1420  pCurrentReceipt->GetReferenceToNum()));
1421 
1422  if (nullptr == pOriginalItem) {
1423  otErr << __FUNCTION__
1424  << ": Expected original depositCheque request item to be "
1425  "inside the chequeReceipt "
1426  "(but failed to load it...)\n";
1427  }
1428  else if (OTItem::depositCheque != pOriginalItem->GetType()) {
1429  OTString strItemType;
1430  pOriginalItem->GetTypeString(strItemType);
1431  otErr << __FUNCTION__
1432  << ": Expected original depositCheque request item to be "
1433  "inside the chequeReceipt, "
1434  "but somehow what we found instead was a " << strItemType
1435  << "...\n";
1436  }
1437  else {
1438  // Get the cheque from the Item and load it up into a Cheque object.
1439  //
1440  OTString strCheque;
1441  pOriginalItem->GetAttachment(strCheque);
1442 
1443  OTCheque* pCheque = new OTCheque;
1444  OT_ASSERT(nullptr != pCheque);
1445  std::unique_ptr<OTCheque> theChequeAngel(pCheque);
1446 
1447  if (!((strCheque.GetLength() > 2) &&
1448  pCheque->LoadContractFromString(strCheque))) {
1449  otErr << __FUNCTION__ << ": Error loading cheque from string:\n"
1450  << strCheque << "\n";
1451  }
1452  // NOTE: Technically we don'T NEED to load up the cheque anymore,
1453  // since
1454  // we could just check the NumberOfOrigin, which should already
1455  // match the
1456  // transaction number on the cheque.
1457  // However, even that would have to load up the cheque once, if it
1458  // wasn't
1459  // already set, and this function already must RETURN a copy of the
1460  // cheque
1461  // (at least optionally), so we might as well just load it up,
1462  // verify it,
1463  // and return it. (That's why we are still loading the cheque here
1464  // instead
1465  // of checking the number of origin.)
1466  else {
1467  // Success loading the cheque.
1468  // Let's see if it's the right cheque...
1469  if (pCheque->GetTransactionNum() == lChequeNum) {
1470  // We found it! Let's return a pointer to pCurrentReceipt
1471 
1472  // Also return pCheque, if the caller wants it (otherwise
1473  // delete it.)
1474  //
1475  if (nullptr != ppChequeOut) // caller wants us to return the
1476  // cheque pointer as well.
1477  {
1478  (*ppChequeOut) =
1479  pCheque; // now caller is responsible to delete.
1480  theChequeAngel.release();
1481  }
1482 
1483  return pCurrentReceipt;
1484  }
1485  }
1486  }
1487  }
1488 
1489  return nullptr;
1490 }
static EXPORT OTItem * CreateItemFromString(const OTString &strItem, const OTIdentifier &theServerID, int64_t lTransactionNumber)
Definition: OTItem.cpp:1473
const OTIdentifier & GetPurportedServerID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
OTTransaction * opentxs::OTLedger::GetFinalReceipt ( int64_t  lReferenceNum)

Definition at line 1506 of file OTLedger.cpp.

1507 {
1508  // loop through the transactions that make up this ledger.
1509  for (auto& it : m_mapTransactions) {
1510  OTTransaction* pTransaction = it.second;
1511  OT_ASSERT(nullptr != pTransaction);
1512 
1513  if (OTTransaction::finalReceipt != pTransaction->GetType()) // <=======
1514  continue;
1515 
1516  if (pTransaction->GetReferenceToNum() == lReferenceNum)
1517  return pTransaction;
1518  }
1519 
1520  return nullptr;
1521 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTTransaction * opentxs::OTLedger::GetReplyNotice ( const int64_t &  lRequestNum)

Definition at line 1312 of file OTLedger.cpp.

1313 {
1314  // loop through the transactions that make up this ledger.
1315  for (auto& it : m_mapTransactions) {
1316  OTTransaction* pTransaction = it.second;
1317  OT_ASSERT(nullptr != pTransaction);
1318 
1319  if (OTTransaction::replyNotice != pTransaction->GetType()) // <=======
1320  continue;
1321 
1322  if (pTransaction->GetRequestNum() == lRequestNum) return pTransaction;
1323  }
1324 
1325  return nullptr;
1326 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int64_t opentxs::OTLedger::GetTotalPendingValue ( )

Definition at line 1695 of file OTLedger.cpp.

1696 {
1697  int64_t lTotalPendingValue = 0;
1698 
1699  if (OTLedger::inbox != GetType()) {
1700  otErr << "OTLedger::GetTotalPendingValue: Wrong ledger type (expected "
1701  "inbox).\n";
1702  return 0;
1703  }
1704 
1705  for (auto& it : m_mapTransactions) {
1706  OTTransaction* pTransaction = it.second;
1707  OT_ASSERT(nullptr != pTransaction);
1708 
1709  if (pTransaction->GetType() == OTTransaction::pending)
1710  lTotalPendingValue +=
1711  pTransaction->GetReceiptAmount(); // this actually loads up the
1712  // original item and reads the
1713  // amount.
1714  }
1715 
1716  return lTotalPendingValue;
1717 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
ledgerType GetType() const
Definition: OTLedger.hpp:212
OTLOG_IMPORT OTLogStream otErr
OTTransaction * opentxs::OTLedger::GetTransaction ( OTTransaction::transactionType  theType)

Definition at line 1215 of file OTLedger.cpp.

1216 {
1217  // loop through the items that make up this transaction
1218 
1219  for (auto& it : m_mapTransactions) {
1220  OTTransaction* pTransaction = it.second;
1221  OT_ASSERT(nullptr != pTransaction);
1222 
1223  if (theType == pTransaction->GetType()) return pTransaction;
1224  }
1225 
1226  return nullptr;
1227 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTTransaction * opentxs::OTLedger::GetTransaction ( int64_t  lTransactionNum) const

Definition at line 1252 of file OTLedger.cpp.

1253 {
1254  // loop through the transactions inside this ledger
1255 
1256  for (auto& it : m_mapTransactions) {
1257  OTTransaction* pTransaction = it.second;
1258  OT_ASSERT(nullptr != pTransaction);
1259 
1260  if (pTransaction->GetTransactionNum() == lTransactionNum) {
1261  return pTransaction;
1262  }
1263  }
1264  return nullptr;
1265 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTTransaction * opentxs::OTLedger::GetTransactionByIndex ( int32_t  nIndex) const

Definition at line 1288 of file OTLedger.cpp.

1289 {
1290  // Out of bounds.
1291  if ((nIndex < 0) || (nIndex >= GetTransactionCount())) return nullptr;
1292 
1293  int32_t nIndexCount = -1;
1294 
1295  for (auto& it : m_mapTransactions) {
1296  nIndexCount++; // On first iteration, this is now 0, same as nIndex.
1297  OTTransaction* pTransaction = it.second;
1298  OT_ASSERT((nullptr != pTransaction)); // Should always be good.
1299 
1300  // If this transaction is the one at the requested index
1301  if (nIndexCount == nIndex) return pTransaction;
1302  }
1303 
1304  return nullptr; // Should never reach this point, since bounds are checked
1305  // at
1306  // the top.
1307 }
int32_t GetTransactionCount() const
Definition: OTLedger.hpp:332
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int32_t opentxs::OTLedger::GetTransactionCount ( ) const
inline

Definition at line 332 of file OTLedger.hpp.

333  {
334  return static_cast<int32_t>(m_mapTransactions.size());
335  }
int32_t opentxs::OTLedger::GetTransactionCountInRefTo ( int64_t  lReferenceNum) const

Definition at line 1272 of file OTLedger.cpp.

1273 {
1274  int32_t nCount = 0;
1275 
1276  for (auto& it : m_mapTransactions) {
1277  OTTransaction* pTransaction = it.second;
1278  OT_ASSERT(nullptr != pTransaction);
1279 
1280  if (pTransaction->GetReferenceToNum() == lReferenceNum) nCount++;
1281  }
1282 
1283  return nCount;
1284 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
int32_t opentxs::OTLedger::GetTransactionIndex ( int64_t  lTransactionNum)

Definition at line 1230 of file OTLedger.cpp.

1231 {
1232  // loop through the transactions inside this ledger
1233  // If a specific transaction is found, returns its index inside the ledger
1234  //
1235  int32_t nIndex = -1;
1236 
1237  for (auto& it : m_mapTransactions) {
1238  OTTransaction* pTransaction = it.second;
1239  OT_ASSERT(nullptr != pTransaction);
1240 
1241  ++nIndex; // 0 on first iteration.
1242 
1243  if (pTransaction->GetTransactionNum() == lTransactionNum) {
1244  return nIndex;
1245  }
1246  }
1247  return -1;
1248 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
const mapOfTransactions & opentxs::OTLedger::GetTransactionMap ( ) const

Definition at line 1160 of file OTLedger.cpp.

1161 {
1162  return m_mapTransactions;
1163 }
OTTransaction * opentxs::OTLedger::GetTransferReceipt ( int64_t  lNumberOfOrigin)

Definition at line 1328 of file OTLedger.cpp.

1329 {
1330  // loop through the transactions that make up this ledger.
1331  for (auto& it : m_mapTransactions) {
1332  OTTransaction* pTransaction = it.second;
1333  OT_ASSERT(nullptr != pTransaction);
1334 
1335  if (OTTransaction::transferReceipt == pTransaction->GetType()) {
1336  OTString strReference;
1337  pTransaction->GetReferenceString(strReference);
1338 
1339  std::unique_ptr<OTItem> pOriginalItem(OTItem::CreateItemFromString(
1340  strReference, pTransaction->GetPurportedServerID(),
1341  pTransaction->GetReferenceToNum()));
1342  OT_ASSERT(nullptr != pOriginalItem);
1343 
1344  if (pOriginalItem->GetType() != OTItem::acceptPending) {
1345  otErr << "OTLedger::" << __FUNCTION__
1346  << ": Wrong item type attached to transferReceipt!\n";
1347  return nullptr;
1348  }
1349  else {
1350  // Note: the acceptPending USED to be "in reference to" whatever
1351  // the pending
1352  // was in reference to. (i.e. the original transfer.) But since
1353  // the KacTech
1354  // bug fix (for accepting multiple transfer receipts) the
1355  // acceptPending is now
1356  // "in reference to" the pending itself, instead of the original
1357  // transfer.
1358  //
1359  // It used to be that a caller of GetTransferReceipt would pass
1360  // in the InRefTo
1361  // expected from the pending in the outbox, and match it to the
1362  // InRefTo found
1363  // on the acceptPending (inside the transferReceipt) in the
1364  // inbox.
1365  // But this is no longer possible, since the acceptPending is no
1366  // longer InRefTo
1367  // whatever the pending is InRefTo.
1368  //
1369  // Therefore, in this place, it is now necessary to pass in the
1370  // NumberOfOrigin,
1371  // and compare it to the NumberOfOrigin, to find the match.
1372  //
1373  if (pOriginalItem->GetNumberOfOrigin() == lNumberOfOrigin)
1374  // if (pOriginalItem->GetReferenceToNum() ==
1375  // lTransactionNum)
1376  return pTransaction; // FOUND IT!
1377  }
1378  }
1379  }
1380 
1381  return nullptr;
1382 }
static EXPORT OTItem * CreateItemFromString(const OTString &strItem, const OTIdentifier &theServerID, int64_t lTransactionNumber)
Definition: OTItem.cpp:1473
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
ledgerType opentxs::OTLedger::GetType ( ) const
inline

Definition at line 212 of file OTLedger.hpp.

213  {
214  return m_Type;
215  }
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT char const* opentxs::OTLedger::GetTypeString ( ) const
inline

Definition at line 373 of file OTLedger.hpp.

374  {
375  return _GetTypeString(m_Type);
376  }
static EXPORT char const * _GetTypeString(ledgerType theType)
Definition: OTLedger.cpp:171
ledgerType m_Type
Definition: OTLedger.hpp:200
void opentxs::OTLedger::InitLedger ( )

Definition at line 1105 of file OTLedger.cpp.

1106 {
1108  "LEDGER"; // CONTRACT, MESSAGE, TRANSACTION, LEDGER, TRANSACTION ITEM
1109 
1110  // This is the default type for a ledger.
1111  // Inboxes and Outboxes are generated with the right type, with files.
1112  // Until the GenerateLedger function is called, message is the default type.
1114 
1115  m_bLoadedLegacyData = false;
1116 }
bool m_bLoadedLegacyData
Definition: OTLedger.hpp:202
ledgerType m_Type
Definition: OTLedger.hpp:200
OTString m_strContractType
Definition: OTContract.hpp:178
bool opentxs::OTLedger::LoadBoxReceipt ( const int64_t &  lTransactionNum)

Definition at line 393 of file OTLedger.cpp.

394 {
395  // First, see if the transaction itself exists on this ledger.
396  // Get a pointer to it.
397  // Next, see if the appropriate file exists, and load it up from
398  // local storage, into a string.
399  // Finally, try to load the transaction from that string and see if
400  // successful.
401  // If it verifies, then replace the abbreviated receipt with the actual one.
402 
403  // First, see if the transaction itself exists on this ledger.
404  // Get a pointer to it.
405  //
406  OTTransaction* pTransaction = GetTransaction(lTransactionNum);
407 
408  if (nullptr == pTransaction) {
409  otOut
410  << __FUNCTION__ << ": Unable to load box receipt "
411  << lTransactionNum
412  << ": couldn't find abbreviated version already on this ledger.\n";
413  return false;
414  }
415  // Todo: security analysis. By this point we've verified the hash of the
416  // transaction against the stored
417  // hash inside the abbreviated version. (VerifyBoxReceipt) We've also
418  // verified a few other values like transaction
419  // number, and the "in ref to" display number. We're then assuming based on
420  // those, that the adjustment and display
421  // amount are correct. (The hash is actually a zero knowledge proof of this
422  // already.) This is good for speedier
423  // optimization but may be worth revisiting in case any security holes.
424  // UPDATE: We'll save this for optimization needs in the future.
425  // pBoxReceipt->SetAbbrevAdjustment( pTransaction->GetAbbrevAdjustment() );
426  // pBoxReceipt->SetAbbrevDisplayAmount(
427  // pTransaction->GetAbbrevDisplayAmount() );
428 
429  // otOut << "DEBUGGING: OTLedger::LoadBoxReceipt: ledger type: %s \n",
430  // GetTypeString());
431 
432  // LoadBoxReceipt already checks pTransaction to see if it's
433  // abbreviated
434  // (which it must be.) So I don't bother checking twice.
435  //
436  OTTransaction* pBoxReceipt =
437  ::opentxs::LoadBoxReceipt(*pTransaction, *this);
438 
439  // success
440  if (nullptr != pBoxReceipt) {
441  // Remove the existing, abbreviated receipt, and replace it with the
442  // actual receipt.
443  // (If this inbox/outbox/whatever is saved, it will later save in
444  // abbreviated form
445  // again.)
446  //
447  RemoveTransaction(lTransactionNum); // this deletes pTransaction
448  pTransaction = nullptr;
449  AddTransaction(*pBoxReceipt); // takes ownership.
450 
451  return true;
452  }
453 
454  return false;
455 }
EXPORT bool RemoveTransaction(int64_t lTransactionNum, bool bDeleteIt=true)
Definition: OTLedger.cpp:1168
EXPORT bool AddTransaction(OTTransaction &theTransaction)
Definition: OTLedger.cpp:1194
OTLOG_IMPORT OTLogStream otOut
OTTransaction * LoadBoxReceipt(OTTransaction &theAbbrev, OTLedger &theLedger)
Definition: Helpers.cpp:399
EXPORT OTTransaction * GetTransaction(OTTransaction::transactionType theType)
Definition: OTLedger.cpp:1215
bool opentxs::OTLedger::LoadBoxReceipts ( std::set< int64_t > *  psetUnloaded = nullptr)

Definition at line 322 of file OTLedger.cpp.

323 {
324  // Grab a copy of all the transaction #s stored inside this ledger.
325  //
326  std::set<int64_t> the_set;
327 
328  for (auto& it : m_mapTransactions) {
329  OTTransaction* pTransaction = it.second;
330  OT_ASSERT(nullptr != pTransaction);
331  the_set.insert(pTransaction->GetTransactionNum());
332  }
333 
334  // Now iterate through those numbers and for each, load the box receipt.
335  //
336  bool bRetVal = true;
337 
338  for (auto& it : the_set) {
339  int64_t lSetNum = it;
340 
341  OTTransaction* pTransaction = GetTransaction(lSetNum);
342  OT_ASSERT(nullptr != pTransaction);
343 
344  // Failed loading the boxReceipt
345  //
346  if ((true == pTransaction->IsAbbreviated()) &&
347  (false == LoadBoxReceipt(lSetNum))) {
348  // WARNING: pTransaction must be re-Get'd below this point if
349  // needed, since pointer
350  // is bad if success on LoadBoxReceipt() call.
351  //
352  pTransaction = nullptr;
353  bRetVal = false;
354  OTLogStream* pLog = &otOut;
355 
356  if (nullptr != psetUnloaded) {
357  psetUnloaded->insert(lSetNum);
358  pLog = &otLog3;
359  }
360  *pLog << "OTLedger::LoadBoxReceipts: Failed calling LoadBoxReceipt "
361  "on "
362  "abbreviated transaction number:" << lSetNum << ".\n";
363  // If psetUnloaded is passed in, then we don't want to break,
364  // because we want to
365  // populate it with the conmplete list of IDs that wouldn't load as
366  // a Box Receipt.
367  // Thus, we only break if psetUnloaded is nullptr, which is better
368  // optimization in that case.
369  // (If not building a list of all failures, then we can return at
370  // first sign of failure.)
371  //
372  if (nullptr == psetUnloaded) break;
373  }
374  // else (success), no need for a block in that case.
375  }
376 
377  // You might ask, why didn't I just iterate through the transactions
378  // directly and just call
379  // LoadBoxReceipt on each one? Answer: Because that function actually
380  // deletes the transaction
381  // and replaces it with a different object, if successful.
382 
383  return bRetVal;
384 }
EXPORT bool LoadBoxReceipt(const int64_t &lTransactionNum)
Definition: OTLedger.cpp:393
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otLog3
#define OT_ASSERT(x)
Definition: Assert.hpp:150
EXPORT OTTransaction * GetTransaction(OTTransaction::transactionType theType)
Definition: OTLedger.cpp:1215
EXPORT bool opentxs::OTLedger::LoadedLegacyData ( ) const
inline

Definition at line 217 of file OTLedger.hpp.

218  {
219  return m_bLoadedLegacyData;
220  }
bool m_bLoadedLegacyData
Definition: OTLedger.hpp:202
bool opentxs::OTLedger::LoadExpiredBox ( )

Definition at line 512 of file OTLedger.cpp.

513 {
515 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadExpiredBoxFromString ( const OTString strBox)

Definition at line 527 of file OTLedger.cpp.

528 {
529  return LoadGeneric(OTLedger::expiredBox, &strBox);
530 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadGeneric ( OTLedger::ledgerType  theType,
const OTString pString = nullptr 
)
protected

OTLedger::LoadGeneric is called by LoadInbox, LoadOutbox, and LoadNymbox. Does NOT VerifyAccount after loading – caller is responsible to do that.

pString – optional argument, for when you prefer to load from a string instead of from a file.

Definition at line 539 of file OTLedger.cpp.

541 {
542  m_Type = theType;
543 
544  const char* pszType = GetTypeString();
545  const char* pszFolder = nullptr;
546 
547  switch (theType) {
548  case OTLedger::nymbox:
549  pszFolder = OTFolders::Nymbox().Get();
550  break;
551  case OTLedger::inbox:
552  pszFolder = OTFolders::Inbox().Get();
553  break;
554  case OTLedger::outbox:
555  pszFolder = OTFolders::Outbox().Get();
556  break;
558  pszFolder = OTFolders::PaymentInbox().Get();
559  break;
560  case OTLedger::recordBox:
561  pszFolder = OTFolders::RecordBox().Get();
562  break;
564  pszFolder = OTFolders::ExpiredBox().Get();
565  break;
566  /* --- BREAK --- */
567  default:
568  otErr << "OTLedger::LoadGeneric: Error: unknown box type. (This should "
569  "never happen.)\n";
570  return false;
571  }
572  m_strFoldername = pszFolder;
573 
574  OTString strID;
575  GetIdentifier(strID);
576 
577  const OTString strServerID(GetRealServerID());
578 
579  if (!m_strFilename.Exists())
580  m_strFilename.Format("%s%s%s", strServerID.Get(),
581  OTLog::PathSeparator(), strID.Get());
582 
583  OTString strFilename;
584  strFilename = strID.Get();
585 
586  const char* szFolder1name =
587  m_strFoldername.Get(); // "nymbox" (or "inbox" or "outbox")
588  const char* szFolder2name = strServerID.Get(); // "nymbox/SERVER_ID"
589  const char* szFilename = strFilename.Get(); // "nymbox/SERVER_ID/USER_ID"
590  // (or "inbox/SERVER_ID/ACCT_ID"
591  // or
592  // "outbox/SERVER_ID/ACCT_ID")
593 
594  OTString strRawFile;
595 
596  if (nullptr != pString) // Loading FROM A STRING.
597  strRawFile.Set(*pString);
598  else // Loading FROM A FILE.
599  {
600  if (!OTDB::Exists(szFolder1name, szFolder2name, szFilename)) {
601  otLog3 << pszType << " does not exist in OTLedger::Load" << pszType
602  << ": " << szFolder1name << OTLog::PathSeparator()
603  << szFolder2name << OTLog::PathSeparator() << szFilename
604  << "\n";
605  return false;
606  }
607 
608  // Try to load the ledger from local storage.
609  //
610  std::string strFileContents(OTDB::QueryPlainString(
611  szFolder1name, szFolder2name,
612  szFilename)); // <=== LOADING FROM DATA STORE.
613 
614  if (strFileContents.length() < 2) {
615  otErr << "OTLedger::LoadGeneric: Error reading file: "
616  << szFolder1name << OTLog::PathSeparator() << szFolder2name
617  << OTLog::PathSeparator() << szFilename << "\n";
618  return false;
619  }
620 
621  strRawFile.Set(strFileContents.c_str());
622  }
623  // NOTE: No need to deal with OT ARMORED INBOX file format here, since
624  // LoadContractFromString already handles that automatically.
625 
626  if (!strRawFile.Exists()) {
627  otErr << "OTLedger::LoadGeneric: Unable to load box (" << szFolder1name
628  << OTLog::PathSeparator() << szFolder2name
629  << OTLog::PathSeparator() << szFilename
630  << ") from empty string.\n";
631  return false;
632  }
633 
634  bool bSuccess = LoadContractFromString(strRawFile);
635 
636  if (!bSuccess) {
637  otErr << "Failed loading " << pszType << " "
638  << ((nullptr != pString) ? "from string" : "from file")
639  << " in OTLedger::Load" << pszType << ": " << szFolder1name
640  << OTLog::PathSeparator() << szFolder2name
641  << OTLog::PathSeparator() << szFilename << "\n";
642  return false;
643  }
644  else {
645  otInfo << "Successfully loaded " << pszType << " "
646  << ((nullptr != pString) ? "from string" : "from file")
647  << " in OTLedger::Load" << pszType << ": " << szFolder1name
648  << OTLog::PathSeparator() << szFolder2name
649  << OTLog::PathSeparator() << szFilename << "\n";
650  }
651 
652  return bSuccess;
653 }
static EXPORT const OTString & PaymentInbox()
Definition: OTFolders.cpp:339
EXPORT char const * GetTypeString() const
Definition: OTLedger.hpp:373
static EXPORT const OTString & ExpiredBox()
Definition: OTFolders.cpp:363
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otLog3
static EXPORT const OTString & Inbox()
Definition: OTFolders.cpp:315
static EXPORT const OTString & Nymbox()
Definition: OTFolders.cpp:331
EXPORT bool Exists() const
Definition: OTString.cpp:1035
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
static EXPORT const OTString & Outbox()
Definition: OTFolders.cpp:335
OTLOG_IMPORT OTLogStream otInfo
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
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 & RecordBox()
Definition: OTFolders.cpp:359
EXPORT bool LoadContractFromString(const OTString &theStr)
const OTIdentifier & GetRealServerID() const
OTString m_strFoldername
Definition: OTContract.hpp:169
bool opentxs::OTLedger::LoadInbox ( )

Definition at line 463 of file OTLedger.cpp.

464 {
465  // print_stacktrace();
466 
467  bool bRetVal = LoadGeneric(OTLedger::inbox);
468 
469  return bRetVal;
470 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadInboxFromString ( const OTString strBox)

Definition at line 487 of file OTLedger.cpp.

488 {
489  return LoadGeneric(OTLedger::inbox, &strBox);
490 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadLedgerFromString ( const OTString theStr)

Definition at line 1752 of file OTLedger.cpp.

1753 {
1754  bool bLoaded = false;
1755 
1756  // Todo security: Look how this is done...
1757  // Any vulnerabilities?
1758  //
1759  if (theStr.Contains("\"\n type=\"nymbox\""))
1760  bLoaded = LoadNymboxFromString(theStr);
1761  else if (theStr.Contains("\"\n type=\"inbox\""))
1762  bLoaded = LoadInboxFromString(theStr);
1763  else if (theStr.Contains("\"\n type=\"outbox\""))
1764  bLoaded = LoadOutboxFromString(theStr);
1765  else if (theStr.Contains("\"\n type=\"paymentInbox\""))
1766  bLoaded = LoadPaymentInboxFromString(theStr);
1767  else if (theStr.Contains("\"\n type=\"recordBox\""))
1768  bLoaded = LoadRecordBoxFromString(theStr);
1769  else if (theStr.Contains("\"\n type=\"expiredBox\""))
1770  bLoaded = LoadExpiredBoxFromString(theStr);
1771  else if (theStr.Contains("\"\n type=\"message\"")) {
1773  bLoaded = LoadContractFromString(theStr);
1774  }
1775  return bLoaded;
1776 }
EXPORT bool LoadInboxFromString(const OTString &strBox)
Definition: OTLedger.cpp:487
EXPORT bool LoadRecordBoxFromString(const OTString &strBox)
Definition: OTLedger.cpp:522
ledgerType m_Type
Definition: OTLedger.hpp:200
EXPORT bool LoadOutboxFromString(const OTString &strBox)
Definition: OTLedger.cpp:492
EXPORT bool LoadNymboxFromString(const OTString &strBox)
Definition: OTLedger.cpp:497
EXPORT bool LoadPaymentInboxFromString(const OTString &strBox)
Definition: OTLedger.cpp:517
EXPORT bool LoadContractFromString(const OTString &theStr)
EXPORT bool LoadExpiredBoxFromString(const OTString &strBox)
Definition: OTLedger.cpp:527
bool opentxs::OTLedger::LoadNymbox ( )

Definition at line 482 of file OTLedger.cpp.

483 {
485 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadNymboxFromString ( const OTString strBox)

Definition at line 497 of file OTLedger.cpp.

498 {
499  return LoadGeneric(OTLedger::nymbox, &strBox);
500 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadOutbox ( )

Definition at line 477 of file OTLedger.cpp.

478 {
480 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadOutboxFromString ( const OTString strBox)

Definition at line 492 of file OTLedger.cpp.

493 {
494  return LoadGeneric(OTLedger::outbox, &strBox);
495 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadPaymentInbox ( )

Definition at line 502 of file OTLedger.cpp.

503 {
505 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadPaymentInboxFromString ( const OTString strBox)

Definition at line 517 of file OTLedger.cpp.

518 {
519  return LoadGeneric(OTLedger::paymentInbox, &strBox);
520 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadRecordBox ( )

Definition at line 507 of file OTLedger.cpp.

508 {
510 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
bool opentxs::OTLedger::LoadRecordBoxFromString ( const OTString strBox)

Definition at line 522 of file OTLedger.cpp.

523 {
524  return LoadGeneric(OTLedger::recordBox, &strBox);
525 }
bool LoadGeneric(ledgerType theType, const OTString *pString=nullptr)
Definition: OTLedger.cpp:539
int32_t opentxs::OTLedger::ProcessXMLNode ( irr::io::IrrXMLReader *&  xml)
protectedvirtual

Reimplemented from opentxs::OTContract.

Definition at line 1922 of file OTLedger.cpp.

1923 {
1924  const char* szFunc = "OTLedger::ProcessXMLNode";
1925 
1926  const OTString strNodeName = xml->getNodeName();
1927 
1928  if (strNodeName.Compare("accountLedger")) {
1929  OTString strType, // ledger type
1930  strLedgerAcctID, // purported
1931  strLedgerAcctServerID, // purported
1932  strUserID, strNumPartialRecords; // Ledger contains either full
1933  // receipts, or abbreviated
1934  // receipts with hashes and partial
1935  // data.
1936 
1937  strType = xml->getAttributeValue("type");
1938  m_strVersion = xml->getAttributeValue("version");
1939 
1940  if (strType.Compare("message")) // These are used for sending
1941  // transactions in messages. (Withdrawal
1942  // request, etc.)
1944  else if (strType.Compare("nymbox")) // Used for receiving new
1945  // transaction numbers, and for
1946  // receiving notices.
1948  else if (strType.Compare("inbox")) // These are used for storing the
1949  // receipts in your inbox. (That
1950  // server must store until
1951  // signed-off.)
1953  else if (strType.Compare("outbox")) // Outgoing, pending transfers.
1955  else if (strType.Compare("paymentInbox")) // Receiving invoices, etc.
1957  else if (strType.Compare("recordBox")) // Where receipts go to die
1958  // (awaiting user deletion,
1959  // completed from other boxes
1960  // already.)
1962  else if (strType.Compare("expiredBox")) // Where expired payments go to
1963  // die (awaiting user deletion,
1964  // completed from other boxes
1965  // already.)
1967  else
1968  m_Type = OTLedger::error_state; // Danger, Will Robinson.
1969 
1970  strLedgerAcctID = xml->getAttributeValue("accountID");
1971  strLedgerAcctServerID = xml->getAttributeValue("serverID");
1972  strUserID = xml->getAttributeValue("userID");
1973 
1974  if (!strLedgerAcctID.Exists() || !strLedgerAcctServerID.Exists() ||
1975  !strUserID.Exists()) {
1976  otOut << szFunc << ": Failure: missing strLedgerAcctID ("
1977  << strLedgerAcctID << ") or "
1978  "strLedgerAcctServerID ("
1979  << strLedgerAcctServerID << ") or strUserID (" << strUserID
1980  << ") while loading transaction "
1981  "from " << strType << " ledger. \n";
1982  return (-1);
1983  }
1984 
1985  OTIdentifier ACCOUNT_ID(strLedgerAcctID),
1986  SERVER_ID(strLedgerAcctServerID), USER_ID(strUserID);
1987 
1988  SetPurportedAccountID(ACCOUNT_ID);
1989  SetPurportedServerID(SERVER_ID);
1990  SetUserID(USER_ID);
1991 
1992  if (!m_bLoadSecurely) {
1993  SetRealAccountID(ACCOUNT_ID);
1994  SetRealServerID(SERVER_ID);
1995  // OTString str1(GetRealAccountID()),
1996  // str2(GetRealServerID());
1997  // otErr << "DEBUGGING:\nReal Acct ID: %s\nReal Server
1998  // ID: %s\n",
1999  // str1.Get(), str2.Get());
2000  }
2001 
2002  // Load up the partial records, based on the expected count...
2003  //
2004  strNumPartialRecords = xml->getAttributeValue("numPartialRecords");
2005  int32_t nPartialRecordCount =
2006  (strNumPartialRecords.Exists() ? atoi(strNumPartialRecords.Get())
2007  : 0);
2008 
2009  OTString strExpected; // The record type has a different name for each
2010  // box.
2011  OTNumList theNumList;
2012  OTNumList* pNumList = nullptr;
2013  switch (m_Type) {
2014  case OTLedger::nymbox:
2015  strExpected.Set("nymboxRecord");
2016  pNumList = &theNumList;
2017  break;
2018  case OTLedger::inbox:
2019  strExpected.Set("inboxRecord");
2020  break;
2021  case OTLedger::outbox:
2022  strExpected.Set("outboxRecord");
2023  break;
2025  strExpected.Set("paymentInboxRecord");
2026  break;
2027  case OTLedger::recordBox:
2028  strExpected.Set("recordBoxRecord");
2029  break;
2030  case OTLedger::expiredBox:
2031  strExpected.Set("expiredBoxRecord");
2032  break;
2033  /* --- BREAK --- */
2034  case OTLedger::message:
2035  if (nPartialRecordCount > 0) {
2036  otErr << szFunc << ": Error: There are " << nPartialRecordCount
2037  << " unexpected abbreviated records in an "
2038  "OTLedger::message type ledger. (Failed loading "
2039  "ledger with accountID: " << strLedgerAcctID << ")\n";
2040  return (-1);
2041  }
2042 
2043  break;
2044  default:
2045  otErr << "OTLedger::ProcessXMLNode: Unexpected ledger type ("
2046  << strType << "). (Failed loading "
2047  "ledger for account: " << strLedgerAcctID
2048  << ")\n";
2049  return (-1);
2050  } // switch (to set strExpected to the abbreviated record type.)
2051 
2052  if (nPartialRecordCount > 0) // message ledger will never enter this
2053  // block due to switch block (above.)
2054  {
2055 
2056  // We iterate to read the expected number of partial records from
2057  // the xml.
2058  // (They had better be there...)
2059  //
2060  while (nPartialRecordCount-- > 0) {
2061  // xml->read(); // <==================
2062  if (!SkipToElement(xml)) {
2063  otOut << szFunc << ": Failure: Unable to find element when "
2064  "one was expected (" << strExpected
2065  << ") "
2066  "for abbreviated record of receipt in "
2067  << GetTypeString() << " box:\n\n" << m_strRawFile
2068  << "\n\n";
2069  return (-1);
2070  }
2071 
2072  // strExpected can be one of:
2073  //
2074  // strExpected.Set("nymboxRecord");
2075  // strExpected.Set("inboxRecord");
2076  // strExpected.Set("outboxRecord");
2077  //
2078  // We're loading here either a nymboxRecord, inboxRecord, or
2079  // outboxRecord...
2080  //
2081  const OTString strLoopNodeName = xml->getNodeName();
2082 
2083  if (strLoopNodeName.Exists() &&
2084  (xml->getNodeType() == irr::io::EXN_ELEMENT) &&
2085  (strExpected.Compare(strLoopNodeName))) {
2086  int64_t lNumberOfOrigin = 0;
2087  int64_t lTransactionNum = 0;
2088  int64_t lInRefTo = 0;
2089  int64_t lInRefDisplay = 0;
2090 
2091  time64_t the_DATE_SIGNED = OT_TIME_ZERO;
2092  int theType = OTTransaction::error_state; // default
2093  OTString strHash;
2094 
2095  int64_t lAdjustment = 0;
2096  int64_t lDisplayValue = 0;
2097  int64_t lClosingNum = 0;
2098  int64_t lRequestNum = 0;
2099  bool bReplyTransSuccess = false;
2100 
2101  int32_t nAbbrevRetVal = LoadAbbreviatedRecord(
2102  xml, lNumberOfOrigin, lTransactionNum, lInRefTo,
2103  lInRefDisplay, the_DATE_SIGNED, theType, strHash,
2104  lAdjustment, lDisplayValue, lClosingNum, lRequestNum,
2105  bReplyTransSuccess,
2106  pNumList); // This is for "OTTransaction::blank" and
2107  // "OTTransaction::successNotice",
2108  // otherwise nullptr.
2109  if ((-1) == nAbbrevRetVal)
2110  return (-1); // The function already logs appropriately.
2111 
2112  //
2113  // See if the same-ID transaction already exists in the
2114  // ledger.
2115  // (There can only be one.)
2116  //
2117  OTTransaction* pExistingTrans =
2118  GetTransaction(lTransactionNum);
2119  if (nullptr != pExistingTrans) // Uh-oh, it's already there!
2120  {
2121  otOut << szFunc << ": Error loading transaction "
2122  << lTransactionNum << " (" << strExpected
2123  << "), since one was already there, in box for "
2124  "account: " << strLedgerAcctID << ".\n";
2125  return (-1);
2126  }
2127 
2128  // CONSTRUCT THE ABBREVIATED RECEIPT HERE...
2129 
2130  // Set all the values we just loaded here during actual
2131  // construction of transaction
2132  // (as abbreviated transaction) i.e. make a special
2133  // constructor for abbreviated transactions
2134  // which is ONLY used here.
2135  //
2136  OTTransaction* pTransaction = new OTTransaction(
2137  USER_ID, ACCOUNT_ID, SERVER_ID, lNumberOfOrigin,
2138  lTransactionNum, lInRefTo, // lInRefTo
2139  lInRefDisplay, the_DATE_SIGNED,
2140  static_cast<OTTransaction::transactionType>(theType),
2141  strHash, lAdjustment, lDisplayValue, lClosingNum,
2142  lRequestNum, bReplyTransSuccess,
2143  pNumList); // This is for "OTTransaction::blank" and
2144  // "OTTransaction::successNotice", otherwise
2145  // nullptr.
2146  OT_ASSERT(nullptr != pTransaction);
2147  //
2148  // NOTE: For THIS CONSTRUCTOR ONLY, we DO set the purported
2149  // AcctID and purported ServerID.
2150  // WHY? Normally you set the "real" IDs at construction, and
2151  // then set the "purported" IDs
2152  // when loading from string. But this constructor (only this
2153  // one) is actually used when
2154  // loading abbreviated receipts as you load their
2155  // inbox/outbox/nymbox.
2156  // Abbreviated receipts are not like real transactions,
2157  // which have serverID, AcctID, userID,
2158  // and signature attached, and the whole thing is
2159  // base64-encoded and then added to the ledger
2160  // as part of a list of contained objects. Rather, with
2161  // abbreviated receipts, there are a series
2162  // of XML records loaded up as PART OF the ledger itself.
2163  // None of these individual XML records
2164  // has its own signature, or its own record of the main IDs
2165  // -- those are assumed to be on the parent
2166  // ledger.
2167  // That's the whole point: abbreviated records don't store
2168  // redundant info, and don't each have their
2169  // own signature, because we want them to be as small as
2170  // possible inside their parent ledger.
2171  // Therefore I will pass in the parent ledger's "real" IDs
2172  // at construction, and immediately thereafter
2173  // set the parent ledger's "purported" IDs onto the
2174  // abbreviated transaction. That way, VerifyContractID()
2175  // will still work and do its job properly with these
2176  // abbreviated records.
2177  //
2178  // This part normally happens in "GenerateTransaction".
2179  // NOTE: Moved to OTTransaction constructor (for
2180  // abbreviateds) for now.
2181  //
2182  // pTransaction->SetPurportedAccountID(
2183  // GetPurportedAccountID());
2184  // pTransaction->SetPurportedServerID(
2185  // GetPurportedServerID());
2186 
2187  // Add it to the ledger's list of transactions...
2188  //
2189 
2190  if (pTransaction->VerifyContractID()) {
2191  // Add it to the ledger...
2192  //
2193  m_mapTransactions[pTransaction->GetTransactionNum()] =
2194  pTransaction;
2195  pTransaction->SetParent(*this);
2196  // otLog5 << "Loaded abbreviated
2197  // transaction and adding to m_mapTransactions in
2198  // OTLedger\n");
2199  }
2200  else {
2201  otErr << szFunc << ": ERROR: verifying contract ID on "
2202  "abbreviated transaction "
2203  << pTransaction->GetTransactionNum() << "\n";
2204  delete pTransaction;
2205  pTransaction = nullptr;
2206  return (-1);
2207  }
2208  // xml->read(); // <==================
2209  // MIGHT need to add "skip after element" here.
2210  //
2211  // Update: Nope.
2212  }
2213  else {
2214  otErr << szFunc
2215  << ": Expected abbreviated record element.\n";
2216  return (-1); // error condition
2217  }
2218  } // while
2219  } // if (number of partial records > 0)
2220 
2221  otLog4 << szFunc << ": Loading account ledger of type \"" << strType
2222  << "\", version: " << m_strVersion << "\n";
2223  // "accountID: %s\n userID: %s\n serverID:
2224  // %s\n----------\n", szFunc,
2225  // strLedgerAcctID.Get(), strUserID.Get(),
2226  // strLedgerAcctServerID.Get()
2227 
2228  // Since we just loaded this stuff, let's verify it.
2229  // We may have to remove this verification here and do it outside this
2230  // call.
2231  // But for now...
2232 
2233  if (VerifyContractID())
2234  return 1;
2235  else
2236  return (-1);
2237  }
2238 
2239  // Todo: When loading abbreviated list of records, set the m_bAbbreviated to
2240  // true.
2241  // Then in THIS block below, if that is set to true, then seek an existing
2242  // transaction instead of
2243  // instantiating a new one. Then repopulate the new one and verify the new
2244  // values against the ones
2245  // that were already there before overwriting anything.
2246 
2247  // Hmm -- technically this code should only execute for OTLedger::message,
2248  // and thus only if
2249  // m_bIsAbbreviated is FALSE. When the complete receipt is loaded,
2250  // "LoadBoxReceipt()" will be
2251  // called, and it will directly load the transaction starting in
2252  // OTTransaction::ProcessXMLNode().
2253  // THAT is where we must check for abbreviated mode and expect it already
2254  // loaded etc etc. Whereas
2255  // here in this spot, we basically want to error out if it's not a message
2256  // ledger.
2257  // UPDATE: However, I must consider legacy data. For now, I'll allow this to
2258  // load in any type of box.
2259  // I also need to check and see if the box receipt already exists (since its
2260  // normal creation point
2261  // may not have happened, when taking legacy data into account.) If it
2262  // doesn't already exist, then I
2263  // should save it again at this point.
2264  //
2265  else if (strNodeName.Compare("transaction")) {
2266  OTString strTransaction;
2267  OTASCIIArmor ascTransaction;
2268 
2269  // go to the next node and read the text.
2270  // xml->read(); // <==================
2271  if (!SkipToTextField(xml)) {
2272  otOut << __FUNCTION__
2273  << ": Failure: Unable to find expected text field "
2274  "containing receipt transaction in box. \n";
2275  return (-1);
2276  }
2277 
2278  if (irr::io::EXN_TEXT == xml->getNodeType()) {
2279  // the ledger contains a series of transactions.
2280  // Each transaction is initially stored as an OTASCIIArmor string.
2281  const OTString strLoopNodeData = xml->getNodeData();
2282 
2283  if (strLoopNodeData.Exists())
2284  ascTransaction.Set(strLoopNodeData); // Put the ascii-armored
2285  // node data into the
2286  // ascii-armor object
2287 
2288  // Decode that into strTransaction, so we can load the transaction
2289  // object from that string.
2290  if (!ascTransaction.Exists() ||
2291  !ascTransaction.GetString(strTransaction)) {
2292  otErr << __FUNCTION__
2293  << ": ERROR: Missing expected transaction contents. "
2294  "Ledger contents:\n\n" << m_strRawFile << "\n\n";
2295  return (-1);
2296  }
2297 
2298  // I belive we're only supposed to use purported numbers when
2299  // loading/saving, and to compare them (as distrusted)
2300  // against a more-trusted source, in order to verify them. Whereas
2301  // when actually USING the numbers (such as here,
2302  // when "GetRealAccountID()" is being used to instantiate the
2303  // transaction, then you ONLY use numbers that you KNOW
2304  // are good (the number you were expecting) versus whatever number
2305  // was actually in the file.
2306  // But wait, you ask, how do I know they are the same number then?
2307  // Because you verified that when you first loaded
2308  // everything into memory. Right after "load" was a "verify" that
2309  // makes sure the "real" account ID and the "purported"
2310  // account ID are actually the same.
2311  //
2312  // UPDATE: If this ledger is loaded from string, there's no
2313  // guarantee that the real IDs have even been set.
2314  // In some cases (Factory...) they definitely have not been. It
2315  // makes sense here when loading, to set the member
2316  // transactions to the same account/server IDs that were actually
2317  // loaded for their parent ledger. Therefore, changing
2318  // back here to Purported values.
2319  //
2320  // OTTransaction * pTransaction = new
2321  // OTTransaction(GetUserID(), GetRealAccountID(),
2322  // GetRealServerID());
2323  OTTransaction* pTransaction = new OTTransaction(
2325  OT_ASSERT(nullptr != pTransaction);
2326 
2327  // Need this set before the LoadContractFromString().
2328  //
2329  if (!m_bLoadSecurely) pTransaction->SetLoadInsecure();
2330 
2331  // If we're able to successfully base64-decode the string and load
2332  // it up as
2333  // a transaction, then let's add it to the ledger's list of
2334  // transactions
2335  if (strTransaction.Exists() &&
2336  pTransaction->LoadContractFromString(strTransaction) &&
2337  pTransaction->VerifyContractID())
2338  // I responsible here to call pTransaction->VerifyContractID()
2339  // since
2340  // I am loading it here and adding it to the ledger. (So I do.)
2341  {
2342 
2343  OTTransaction* pExistingTrans =
2344  GetTransaction(pTransaction->GetTransactionNum());
2345  if (nullptr != pExistingTrans) // Uh-oh, it's already there!
2346  {
2347  const OTString strPurportedAcctID(GetPurportedAccountID());
2348  otOut
2349  << szFunc << ": Error loading full transaction "
2350  << pTransaction->GetTransactionNum()
2351  << ", since one was already there, in box for account: "
2352  << strPurportedAcctID << ".\n";
2353  delete pTransaction;
2354  pTransaction = nullptr;
2355  return (-1);
2356  }
2357 
2358  // It's not already there on this ledger -- so add it!
2359  // (Below this point, no need to delete pTransaction upon
2360  // returning.)
2361  //
2362  m_mapTransactions[pTransaction->GetTransactionNum()] =
2363  pTransaction;
2364  pTransaction->SetParent(*this);
2365  // otLog5 << "Loaded full transaction and adding
2366  // to m_mapTransactions in OTLedger\n");
2367 
2368  switch (GetType()) {
2369  case OTLedger::message:
2370  break;
2371  case OTLedger::nymbox:
2372  case OTLedger::inbox:
2373  case OTLedger::outbox:
2375  case OTLedger::recordBox:
2376  case OTLedger::expiredBox: {
2377  // For the sake of legacy data, check for existence of box
2378  // receipt here,
2379  // and re-save that box receipt if it doesn't exist.
2380  //
2381  otOut << "--- Apparently this is old data (the transaction "
2382  "is still stored inside the ledger itself)... \n";
2383  m_bLoadedLegacyData = true; // Only place this is set true.
2384 
2385  const int32_t nBoxType = static_cast<int32_t>(GetType());
2386 
2387  const bool bBoxReceiptAlreadyExists =
2389  pTransaction->GetRealServerID(),
2390  pTransaction->GetUserID(),
2391  pTransaction->GetRealAccountID(), // If Nymbox (vs
2392  // inbox/outbox)
2393  // the USER_ID
2394  // will be in this
2395  // field also.
2396  nBoxType, // 0/nymbox, 1/inbox, 2/outbox
2397  pTransaction->GetTransactionNum());
2398  if (!bBoxReceiptAlreadyExists) // Doesn't already
2399  // exist separately.
2400  {
2401  // Okay then, let's create it...
2402  //
2403  otOut << "--- The BoxReceipt doesn't exist separately "
2404  "(yet.) Creating it in local storage...\n";
2405 
2406  const int64_t lBoxType = static_cast<int64_t>(nBoxType);
2407 
2408  if (false ==
2409  pTransaction->SaveBoxReceipt(
2410  lBoxType)) // <======== SAVE BOX RECEIPT
2411  otErr << "--- FAILED trying to save BoxReceipt "
2412  "from legacy data to local storage!\n";
2413  }
2414  } break;
2415  default:
2416  otErr << szFunc
2417  << ": Unknown ledger type while loading transaction!"
2418  " (Should never happen.)\n"; // todo: assert here?
2419  // "should never
2420  // happen" ...
2421  return (-1);
2422  } // switch (GetType())
2423 
2424  } // if transaction loads and verifies.
2425  else {
2426  otErr << "ERROR: loading or verifying transaction in "
2427  "OTLedger::ProcessXMLNode\n";
2428  if (nullptr != pTransaction) {
2429  delete pTransaction;
2430  pTransaction = nullptr;
2431  }
2432  return (-1);
2433  }
2434  }
2435  else {
2436  otErr << "Error in OTLedger::ProcessXMLNode: transaction without "
2437  "value.\n";
2438  return (-1); // error condition
2439  }
2440  return 1;
2441  }
2442 
2443  return 0;
2444 }
OTLOG_IMPORT OTLogStream otLog4
int32_t LoadAbbreviatedRecord(irr::io::IrrXMLReader *&xml, int64_t &lNumberOfOrigin, int64_t &lTransactionNum, int64_t &lInRefTo, int64_t &lInRefDisplay, time64_t &the_DATE_SIGNED, int &theType, OTString &strHash, int64_t &lAdjustment, int64_t &lDisplayValue, int64_t &lClosingNum, int64_t &lRequestNum, bool &bReplyTransSuccess, OTNumList *pNumList=nullptr)
Definition: Helpers.cpp:218
EXPORT bool VerifyBoxReceiptExists(const OTIdentifier &SERVER_ID, const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, int32_t nBoxType, const int64_t &lTransactionNum)
Definition: Helpers.cpp:358
EXPORT char const * GetTypeString() const
Definition: OTLedger.hpp:373
bool m_bLoadedLegacyData
Definition: OTLedger.hpp:202
OTLOG_IMPORT OTLogStream otOut
void SetRealAccountID(const OTIdentifier &theID)
int64_t time64_t
Definition: Common.hpp:209
void SetRealServerID(const OTIdentifier &theID)
ledgerType m_Type
Definition: OTLedger.hpp:200
const OTIdentifier & GetPurportedServerID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
ledgerType GetType() const
Definition: OTLedger.hpp:212
static bool SkipToTextField(irr::io::IrrXMLReader *&xml)
void SetUserID(const OTIdentifier &theID)
static bool SkipToElement(irr::io::IrrXMLReader *&xml)
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetPurportedAccountID() const
void SetPurportedServerID(const OTIdentifier &theID)
virtual EXPORT bool VerifyContractID() const
const OTIdentifier & GetUserID() const
#define OT_TIME_ZERO
Definition: Common.hpp:180
void SetPurportedAccountID(const OTIdentifier &theID)
EXPORT OTTransaction * GetTransaction(OTTransaction::transactionType theType)
Definition: OTLedger.cpp:1215
void opentxs::OTLedger::ProduceOutboxReport ( OTItem theBalanceItem)

Definition at line 1723 of file OTLedger.cpp.

1724 {
1725  if (OTLedger::outbox != GetType()) {
1726  otErr << __FUNCTION__ << ": Wrong ledger type.\n";
1727  return;
1728  }
1729 
1730  // loop through the OUTBOX transactions, and produce a sub-item onto
1731  // theBalanceItem for each, which will
1732  // be a report on each pending transfer in this outbox, therefore added to
1733  // the balance item.
1734  // (So the balance item contains a complete report on the outoing transfers
1735  // in this outbox.)
1736  for (auto& it : m_mapTransactions) {
1737  OTTransaction* pTransaction = it.second;
1738  OT_ASSERT(nullptr != pTransaction);
1739 
1740  // it only reports receipts where we don't yet have balance agreement.
1741  pTransaction->ProduceOutboxReportItem(
1742  theBalanceItem); // <======= This function adds a pending transfer
1743  // sub-item to theBalanceItem, where appropriate.
1744  }
1745 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
ledgerType GetType() const
Definition: OTLedger.hpp:212
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTLedger::Release ( )
virtual

Reimplemented from opentxs::OTTransactionType.

Definition at line 2468 of file OTLedger.cpp.

2469 {
2470  Release_Ledger();
2471 
2472  ot_super::Release(); // since I've overridden the base class, I call it
2473  // now...
2474 }
EXPORT void Release_Ledger()
Definition: OTLedger.cpp:2463
void opentxs::OTLedger::Release_Ledger ( )

Definition at line 2463 of file OTLedger.cpp.

2464 {
2466 }
EXPORT void ReleaseTransactions()
Definition: OTLedger.cpp:2451
void opentxs::OTLedger::ReleaseTransactions ( )

Definition at line 2451 of file OTLedger.cpp.

2452 {
2453  // If there were any dynamically allocated objects, clean them up here.
2454 
2455  while (!m_mapTransactions.empty()) {
2456  OTTransaction* pTransaction = m_mapTransactions.begin()->second;
2457  m_mapTransactions.erase(m_mapTransactions.begin());
2458  delete pTransaction;
2459  pTransaction = nullptr;
2460  }
2461 }
bool opentxs::OTLedger::RemoveTransaction ( int64_t  lTransactionNum,
bool  bDeleteIt = true 
)

If transaction #87, in reference to #74, is in the inbox, you can remove it by calling this function and passing in 87. Deletes.

Definition at line 1168 of file OTLedger.cpp.

1169 {
1170  // See if there's something there with that transaction number.
1171  auto it = m_mapTransactions.find(lTransactionNum);
1172 
1173  // If it's not already on the list, then there's nothing to remove.
1174  if (it == m_mapTransactions.end()) {
1175  otErr << "OTLedger::RemoveTransaction"
1176  << ": Attempt to remove Transaction from ledger, when "
1177  "not already there: " << lTransactionNum << "\n";
1178  return false;
1179  }
1180  // Otherwise, if it WAS already there, remove it properly.
1181  else {
1182  OTTransaction* pTransaction = it->second;
1183  OT_ASSERT(nullptr != pTransaction);
1184  m_mapTransactions.erase(it);
1185 
1186  if (bDeleteIt) {
1187  delete pTransaction;
1188  pTransaction = nullptr;
1189  }
1190  return true;
1191  }
1192 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::SaveBoxReceipt ( const int64_t &  lTransactionNum)

Definition at line 278 of file OTLedger.cpp.

279 {
280 
281  // First, see if the transaction itself exists on this ledger.
282  // Get a pointer to it.
283  OTTransaction* pTransaction = GetTransaction(lTransactionNum);
284 
285  if (nullptr == pTransaction) {
286  otOut << "OTLedger::SaveBoxReceipt: Unable to save box receipt "
287  << lTransactionNum
288  << ": "
289  "couldn't find the transaction on this ledger.\n";
290  return false;
291  }
292 
293  return pTransaction->SaveBoxReceipt(*this);
294 }
OTLOG_IMPORT OTLogStream otOut
EXPORT OTTransaction * GetTransaction(OTTransaction::transactionType theType)
Definition: OTLedger.cpp:1215
bool opentxs::OTLedger::SaveBoxReceipts ( )

Definition at line 251 of file OTLedger.cpp.

253 {
254  bool bRetVal = true;
255  for (auto& it : m_mapTransactions) {
256  OTTransaction* pTransaction = it.second;
257  OT_ASSERT(nullptr != pTransaction);
258 
259  // We only save full versions of transactions as box receipts, not
260  // abbreviated versions.
261  // (If it's not abbreviated, therefore it's the full version.)
262  //
263  if (!pTransaction->IsAbbreviated()) // This way we won't see an
264  // error if it's not
265  // abbreviated.
266  bRetVal = pTransaction->SaveBoxReceipt(*this);
267 
268  if (!bRetVal) {
269  otErr << "OTLedger::SaveBoxReceipts: Failed calling SaveBoxReceipt "
270  "on transaction: " << pTransaction->GetTransactionNum()
271  << ".\n";
272  break;
273  }
274  }
275  return bRetVal;
276 }
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::SaveContractWallet ( std::ofstream &  ofs) const
virtual

Reimplemented from opentxs::OTTransactionType.

Definition at line 2476 of file OTLedger.cpp.

2477 {
2478  return true;
2479 }
bool opentxs::OTLedger::SaveExpiredBox ( )

Definition at line 935 of file OTLedger.cpp.

936 {
937  if (m_Type != OTLedger::expiredBox) {
938  otErr << "Wrong ledger type passed to OTLedger::SaveExpiredBox.\n";
939  return false;
940  }
941 
942  return SaveGeneric(m_Type);
943 }
bool SaveGeneric(ledgerType theType)
Definition: OTLedger.cpp:655
ledgerType m_Type
Definition: OTLedger.hpp:200
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::SaveGeneric ( OTLedger::ledgerType  theType)
protected

Definition at line 655 of file OTLedger.cpp.

656 {
657  m_Type = theType;
658 
659  const char* pszFolder = nullptr;
660  const char* pszType = GetTypeString();
661 
662  switch (theType) {
663  case OTLedger::nymbox:
664  pszFolder = OTFolders::Nymbox().Get();
665  break;
666  case OTLedger::inbox:
667  pszFolder = OTFolders::Inbox().Get();
668  break;
669  case OTLedger::outbox:
670  pszFolder = OTFolders::Outbox().Get();
671  break;
673  pszFolder = OTFolders::PaymentInbox().Get();
674  break;
675  case OTLedger::recordBox:
676  pszFolder = OTFolders::RecordBox().Get();
677  break;
679  pszFolder = OTFolders::ExpiredBox().Get();
680  break;
681  /* --- BREAK --- */
682  default:
683  otErr << "OTLedger::SaveGeneric: Error: unknown box type. (This should "
684  "never happen.)\n";
685  return false;
686  }
687 
688  m_strFoldername = pszFolder; // <=======
689 
690  OTString strID;
691  GetIdentifier(strID);
692  const OTString strServerID(GetRealServerID());
693 
694  if (!m_strFilename.Exists())
695  m_strFilename.Format("%s%s%s", strServerID.Get(),
696  OTLog::PathSeparator(), strID.Get());
697 
698  OTString strFilename;
699  strFilename = strID.Get();
700 
701  const char* szFolder1name =
702  m_strFoldername.Get(); // "nymbox" (or "inbox" or "outbox")
703  const char* szFolder2name = strServerID.Get(); // "nymbox/SERVER_ID"
704  const char* szFilename = strFilename.Get(); // "nymbox/SERVER_ID/USER_ID"
705  // (or "inbox/SERVER_ID/ACCT_ID"
706  // or
707  // "outbox/SERVER_ID/ACCT_ID")
708 
711 
712  OTString strRawFile;
713 
714  if (!SaveContractRaw(strRawFile)) {
715  otErr << "OTLedger::SaveGeneric: Error saving " << pszType
716  << " (to string):\n" << szFolder1name << OTLog::PathSeparator()
717  << szFolder2name << OTLog::PathSeparator() << szFilename << "\n";
718  return false;
719  }
720 
721  OTString strFinal;
722  OTASCIIArmor ascTemp(strRawFile);
723 
724  if (false ==
725  ascTemp.WriteArmoredString(strFinal, m_strContractType.Get())) {
726  otErr << "OTLedger::SaveGeneric: Error saving " << pszType
727  << " (failed writing armored string):\n" << szFolder1name
728  << OTLog::PathSeparator() << szFolder2name
729  << OTLog::PathSeparator() << szFilename << "\n";
730  return false;
731  }
732 
733  bool bSaved =
734  OTDB::StorePlainString(strFinal.Get(), szFolder1name, szFolder2name,
735  szFilename); // <=== SAVING TO DATA STORE.
736  if (!bSaved) {
737  otErr << "OTLedger::SaveGeneric: Error writing " << pszType
738  << " to file: " << szFolder1name << OTLog::PathSeparator()
739  << szFolder2name << OTLog::PathSeparator() << szFilename << "\n";
740  return false;
741  }
742  else
743  otInfo << "Successfully saved " << pszType << ": " << szFolder1name
744  << OTLog::PathSeparator() << szFolder2name
745  << OTLog::PathSeparator() << szFilename << "\n";
746 
747  return bSaved;
748 }
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:698
static EXPORT const OTString & PaymentInbox()
Definition: OTFolders.cpp:339
EXPORT char const * GetTypeString() const
Definition: OTLedger.hpp:373
static EXPORT const OTString & ExpiredBox()
Definition: OTFolders.cpp:363
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
EXPORT bool SaveContractRaw(OTString &strOutput) const
EXPORT uint32_t GetLength() const
Definition: OTString.cpp:1040
static EXPORT const OTString & Inbox()
Definition: OTFolders.cpp:315
static EXPORT const OTString & Nymbox()
Definition: OTFolders.cpp:331
EXPORT bool Exists() const
Definition: OTString.cpp:1035
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
ledgerType m_Type
Definition: OTLedger.hpp:200
#define OT_ASSERT(x)
Definition: Assert.hpp:150
OTString m_strContractType
Definition: OTContract.hpp:178
static EXPORT const OTString & Outbox()
Definition: OTFolders.cpp:335
OTLOG_IMPORT OTLogStream otInfo
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
static EXPORT const OTString & RecordBox()
Definition: OTFolders.cpp:359
const OTIdentifier & GetRealServerID() const
OTString m_strFoldername
Definition: OTContract.hpp:169
bool opentxs::OTLedger::SaveInbox ( OTIdentifier pInboxHash = nullptr)

Definition at line 836 of file OTLedger.cpp.

840 {
841 
842  // OTString strTempBlah, strTempBlah2(*this);
843  // GetIdentifier(strTempBlah);
844  // otErr << "OTLedger::SaveInbox: DEBUGGING: SAVING INBOX for account:
845  // %s, number of transactions currently in the inbox: %d \n\n STACK
846  // TRACE:\n\n",
847  // strTempBlah.Get(), GetTransactionCount());
848  //
849  // print_stacktrace();
850 
851  // otErr << "OTLedger::SaveInbox: (CONTINUED DEBUGGING): INBOX CONTENTS:
852  // \n\n%s\n\n",
853  // strTempBlah2.Get());
854 
855  if (m_Type != OTLedger::inbox) {
856  otErr << "Wrong ledger type passed to OTLedger::SaveInbox.\n";
857  return false;
858  }
859 
860  const bool bSaved = SaveGeneric(m_Type);
861 
862  // Sometimes the caller, when saving the Inbox, wants to know what the
863  // latest Inbox hash is. FYI, the InboxHash is calculated on the UNSIGNED
864  // contents of the Inbox. So if pInboxHash is not nullptr, then that is
865  // where
866  // I will put the new hash, as output for the caller of this function.
867  //
868  if (bSaved && (nullptr != pInboxHash)) {
869  pInboxHash->Release();
870 
871  if (!CalculateInboxHash(*pInboxHash))
872  // if (!pInboxHash->CalculateDigest(m_xmlUnsigned))
873  otErr << "OTLedger::SaveInbox: Failed trying to calculate Inbox "
874  "hash.\n";
875  }
876 
877  return bSaved;
878 }
bool SaveGeneric(ledgerType theType)
Definition: OTLedger.cpp:655
ledgerType m_Type
Definition: OTLedger.hpp:200
OTLOG_IMPORT OTLogStream otErr
EXPORT bool CalculateInboxHash(OTIdentifier &theOutput)
Definition: OTLedger.cpp:770
bool opentxs::OTLedger::SaveNymbox ( OTIdentifier pNymboxHash = nullptr)

Definition at line 801 of file OTLedger.cpp.

806 {
807  if (m_Type != OTLedger::nymbox) {
808  otErr << "Wrong ledger type passed to OTLedger::SaveNymbox.\n";
809  return false;
810  }
811 
812  const bool bSaved = SaveGeneric(m_Type);
813 
814  // Sometimes the caller, when saving the Nymbox, wants to know what the
815  // latest Nymbox hash is. FYI, the NymboxHash is calculated on the UNSIGNED
816  // contents of the Nymbox. So if pNymboxHash is not nullptr, then that is
817  // where
818  // I will put the new hash, as output for the caller of this function.
819  //
820  if (bSaved && (nullptr != pNymboxHash)) {
821  pNymboxHash->Release();
822 
823  if (!CalculateNymboxHash(*pNymboxHash))
824  otErr << "OTLedger::SaveNymbox: Failed trying to calculate nymbox "
825  "hash.\n";
826  //
827  // if (!pNymboxHash->CalculateDigest(m_xmlUnsigned))
828  // otErr << "OTLedger::SaveNymbox: Failed trying to calculate
829  // nymbox hash.\n";
830  }
831 
832  return bSaved;
833 }
EXPORT bool CalculateNymboxHash(OTIdentifier &theOutput)
Definition: OTLedger.cpp:790
bool SaveGeneric(ledgerType theType)
Definition: OTLedger.cpp:655
ledgerType m_Type
Definition: OTLedger.hpp:200
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::SaveOutbox ( OTIdentifier pOutboxHash = nullptr)

Definition at line 881 of file OTLedger.cpp.

886 {
887  if (m_Type != OTLedger::outbox) {
888  otErr << "Wrong ledger type passed to OTLedger::SaveOutbox.\n";
889  return false;
890  }
891 
892  const bool bSaved = SaveGeneric(m_Type);
893 
894  // Sometimes the caller, when saving the Outbox, wants to know what the
895  // latest Outbox hash is. FYI, the OutboxHash is calculated on the UNSIGNED
896  // contents of the Outbox. So if pOutboxHash is not nullptr, then that is
897  // where
898  // I will put the new hash, as output for the caller of this function.
899  //
900  if (bSaved && (nullptr != pOutboxHash)) {
901  pOutboxHash->Release();
902 
903  if (!CalculateOutboxHash(*pOutboxHash))
904  // if (!pOutboxHash->CalculateDigest(m_xmlUnsigned))
905  otErr << "OTLedger::SaveOutbox: Failed trying to calculate Outbox "
906  "hash.\n";
907  }
908 
909  return bSaved;
910 }
bool SaveGeneric(ledgerType theType)
Definition: OTLedger.cpp:655
EXPORT bool CalculateOutboxHash(OTIdentifier &theOutput)
Definition: OTLedger.cpp:780
ledgerType m_Type
Definition: OTLedger.hpp:200
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::SavePaymentInbox ( )

Definition at line 913 of file OTLedger.cpp.

914 {
916  otErr << "Wrong ledger type passed to OTLedger::SavePaymentInbox.\n";
917  return false;
918  }
919 
920  return SaveGeneric(m_Type);
921 }
bool SaveGeneric(ledgerType theType)
Definition: OTLedger.cpp:655
ledgerType m_Type
Definition: OTLedger.hpp:200
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTLedger::SaveRecordBox ( )

Definition at line 924 of file OTLedger.cpp.

925 {
926  if (m_Type != OTLedger::recordBox) {
927  otErr << "Wrong ledger type passed to OTLedger::SaveRecordBox.\n";
928  return false;
929  }
930 
931  return SaveGeneric(m_Type);
932 }
bool SaveGeneric(ledgerType theType)
Definition: OTLedger.cpp:655
ledgerType m_Type
Definition: OTLedger.hpp:200
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTLedger::UpdateContents ( )
protectedvirtual

Reimplemented from opentxs::OTContract.

Definition at line 1779 of file OTLedger.cpp.

1781 {
1782  bool bSavingAbbreviated =
1783  true; // The default. Only OTLedger::message changes this to false.
1784  int32_t nPartialRecordCount = 0; // We store this, so we know how many
1785  // abbreviated records to read back later.
1786 
1787  switch (GetType()) {
1788  // a message ledger stores the full receipts directly inside itself. (No
1789  // separate files.)
1790  case OTLedger::message:
1791  bSavingAbbreviated = false;
1792  nPartialRecordCount = 0; // In this case (OTLedger::message), they are
1793  // all FULL records, not abbreviated.
1794  break;
1795 
1796  // These store abbreviated versions of themselves, with the actual receipts
1797  // in separate files.
1798  // Those separate files are created on server side when first added to the
1799  // box, and on client
1800  // side when downloaded from the server. They must match the hash that
1801  // appears in the box.
1802  case OTLedger::nymbox:
1803  case OTLedger::inbox:
1804  case OTLedger::outbox:
1806  case OTLedger::recordBox:
1807  case OTLedger::expiredBox:
1808  bSavingAbbreviated = true;
1809  nPartialRecordCount = static_cast<int32_t>(
1810  m_mapTransactions.size()); // We store this, so we know how many
1811  // abbreviated records to read back
1812  // later.
1813  break;
1814 
1815  default:
1816  otErr << "OTLedger::UpdateContents: Error: unexpected box type (1st "
1817  "block). (This should never happen.)\n";
1818  return;
1819  }
1820 
1821  //
1822  // Notice I use the PURPORTED Account ID and Server ID to create the output.
1823  // That's because
1824  // I don't want to inadvertantly substitute the real ID for a bad one and
1825  // then sign it.
1826  // So if there's a bad one in there when I read it, THAT's the one that I
1827  // write as well!
1828  //
1829  OTString strType(GetTypeString()), strLedgerAcctID(GetPurportedAccountID()),
1830  strLedgerAcctServerID(GetPurportedServerID()), strUserID(GetUserID());
1831 
1832  // I release this because I'm about to repopulate it.
1834 
1835  // m_xmlUnsigned.Concatenate("<?xml version=\"%s\"?>\n\n", "1.0");
1836 
1837  OTString strLedgerContents = "";
1838 
1839  int32_t nPartialACTUALCount = 0;
1840 
1841  // loop through the transactions and print them out here.
1842  for (auto& it : m_mapTransactions) {
1843  OTTransaction* pTransaction = it.second;
1844  OT_ASSERT(nullptr != pTransaction);
1845 
1846  OTString strTransaction;
1847 
1848  if (false ==
1849  bSavingAbbreviated) // only OTLedger::message uses this block.
1850  { // Save the FULL version of the receipt inside the box, so no separate
1851  // files are necessary.
1852  //
1853  pTransaction->SaveContractRaw(strTransaction);
1854  OTASCIIArmor ascTransaction;
1855  ascTransaction.SetString(strTransaction, true); // linebreaks = true
1856  strLedgerContents.Concatenate("<transaction>\n%s</transaction>\n\n",
1857  ascTransaction.Get());
1858  }
1859  else // true == bSavingAbbreviated // ALL OTHER ledger types are
1860  // saved here in abbreviated form.
1861  {
1862  switch (GetType()) {
1863 
1864  case OTLedger::nymbox:
1865  pTransaction->SaveAbbreviatedNymboxRecord(strTransaction);
1866  break;
1867  case OTLedger::inbox:
1868  pTransaction->SaveAbbreviatedInboxRecord(strTransaction);
1869  break;
1870  case OTLedger::outbox:
1871  pTransaction->SaveAbbreviatedOutboxRecord(strTransaction);
1872  break;
1874  pTransaction->SaveAbbrevPaymentInboxRecord(strTransaction);
1875  break;
1876  case OTLedger::recordBox:
1877  pTransaction->SaveAbbrevRecordBoxRecord(strTransaction);
1878  break;
1879  case OTLedger::expiredBox:
1880  pTransaction->SaveAbbrevExpiredBoxRecord(strTransaction);
1881  break;
1882 
1883  default: // todo: possibly change this to an OT_ASSERT. security.
1884  otErr << "OTLedger::UpdateContents: Error: unexpected box type "
1885  "(2nd block). (This should never happen. Skipping.)\n";
1886 
1887  OT_FAIL_MSG("ASSERT: OTLedger::UpdateContents: Unexpected "
1888  "ledger type.");
1889 
1890  continue;
1891  }
1892 
1893  nPartialACTUALCount++; // Just in case the number actually written
1894  // matches the count in the map.
1895 
1896  strLedgerContents.Concatenate("%s", strTransaction.Get());
1897  }
1898  }
1899 
1900  OT_ASSERT_MSG(nPartialACTUALCount == nPartialRecordCount,
1901  "ASSERT: OTLedger::UpdateContents: "
1902  "OT_ASSERT_MSG(nPartialACTUALCount == nPartialRecordCount)");
1903 
1904  // HERE IS WHERE WE ACTUALLY BUILD THE STRING:
1905  //
1906  m_xmlUnsigned.Concatenate("<accountLedger version=\"%s\"\n "
1907  "type=\"%s\"\n "
1908  "numPartialRecords=\"%d\"\n "
1909  "accountID=\"%s\"\n "
1910  "userID=\"%s\"\n "
1911  "serverID=\"%s\" >\n\n",
1912  m_strVersion.Get(), strType.Get(),
1913  nPartialRecordCount, strLedgerAcctID.Get(),
1914  strUserID.Get(), strLedgerAcctServerID.Get());
1915 
1916  m_xmlUnsigned.Concatenate("%s", strLedgerContents.Get());
1917  m_xmlUnsigned.Concatenate("</accountLedger>\n");
1918 }
EXPORT char const * GetTypeString() const
Definition: OTLedger.hpp:373
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
const OTIdentifier & GetPurportedServerID() const
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
ledgerType GetType() const
Definition: OTLedger.hpp:212
OTStringXML m_xmlUnsigned
Definition: OTContract.hpp:174
#define OT_FAIL_MSG(s)
Definition: Assert.hpp:144
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
const OTIdentifier & GetPurportedAccountID() const
const OTIdentifier & GetUserID() const
virtual EXPORT void Release()
Definition: OTString.cpp:765
bool opentxs::OTLedger::VerifyAccount ( const OTPseudonym theNym)
virtual

Reimplemented from opentxs::OTTransactionType.

Definition at line 187 of file OTLedger.cpp.

188 {
189  switch (GetType()) {
190  case OTLedger::message: // message ledgers do not load Box Receipts. (They
191  // store full version internally already.)
192  break;
193  case OTLedger::nymbox:
194  case OTLedger::inbox:
195  case OTLedger::outbox:
197  case OTLedger::recordBox:
198  case OTLedger::expiredBox: {
199  std::set<int64_t> setUnloaded;
200  // if psetUnloaded passed in, then use it to return the #s that weren't
201  // there as box receipts.
202  // bool bLoadedBoxReceipts =
204  &setUnloaded); // Note: Also useful for suppressing errors here.
205  } break;
206  default: {
207  const int32_t nLedgerType = static_cast<int32_t>(GetType());
208  const OTIdentifier theNymID(theNym);
209  const OTString strNymID(theNymID);
210  OTString strAccountID;
211  GetIdentifier(strAccountID);
212  otErr << "OTLedger::VerifyAccount: Failure: Bad ledger type: "
213  << nLedgerType << ", UserID: " << strNymID
214  << ", AcctID: " << strAccountID << "\n";
215  }
216  return false;
217  }
218 
219  return OTTransactionType::VerifyAccount(theNym);
220 }
ledgerType GetType() const
Definition: OTLedger.hpp:212
EXPORT bool LoadBoxReceipts(std::set< int64_t > *psetUnloaded=nullptr)
Definition: OTLedger.cpp:322
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
OTLOG_IMPORT OTLogStream otErr
virtual bool VerifyAccount(const OTPseudonym &theNym)

Friends And Related Function Documentation

Member Data Documentation

bool opentxs::OTLedger::m_bLoadedLegacyData

Definition at line 202 of file OTLedger.hpp.

ledgerType opentxs::OTLedger::m_Type

Definition at line 200 of file OTLedger.hpp.


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