Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Helpers.cpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * Helpers.cpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 #include "OTTransaction.hpp"
134 #include "OTLedger.hpp"
135 #include "OTString.hpp"
136 #include "util/OTFolders.hpp"
137 #include "OTLog.hpp"
138 #include "OTStorage.hpp"
139 #include "OTIdentifier.hpp"
140 #include "OTNumList.hpp"
141 #include <irrxml/irrXML.hpp>
142 #include <string>
143 
144 namespace
145 {
146 
147 char const* const TypeStrings[] = {
148  "blank", // freshly issued, not used yet // comes from server, stored on
149  // Nym. (Nymbox.)
150  "message", // in nymbox, message from one user to another.
151  "notice", // in nymbox, notice from the server. Probably contains an updated
152  // smart contract.
153  "replyNotice", // When you send a request to the server, sometimes its reply
154  // is so important,
155  // that it drops a copy into your Nymbox to make you receive and process it.
156  "successNotice", // A transaction # has successfully been signed out.
157  // (Nymbox.)
158  "pending", // Pending transfer, in the inbox/outbox.
159  "transferReceipt", // the server drops this into your inbox, when someone
160  // accepts your transfer.
161  "chequeReceipt", // the server drops this into your inbox, when someone
162  // deposits your cheque.
163  "voucherReceipt", // the server drops this into your inbox, when someone
164  // deposits your voucher.
165  "marketReceipt", // server drops this into inbox periodically, if you have
166  // an offer on the market.
167  "paymentReceipt", // the server drops this into people's inboxes,
168  // periodically, if they have payment plans.
169  "finalReceipt", // the server drops this into your inbox(es), when a
170  // CronItem expires or is canceled.
171  "basketReceipt", // the server drops this into your inboxes, when a basket
172  // exchange is processed.
173  "instrumentNotice", // Receive these in paymentInbox (by way of Nymbox), and
174  // send in Outpayments (like outMail.) (When done, they
175  // go to recordBox or expiredBox to await deletion.)
176  "instrumentRejection", // When someone rejects your invoice from his
177  // paymentInbox, you get one of these in YOUR
178  // paymentInbox.
179  "processNymbox", // process nymbox transaction // comes from client
180  "atProcessNymbox", // process nymbox reply // comes from server
181  "processInbox", // process inbox transaction // comes from client
182  "atProcessInbox", // process inbox reply // comes from server
183  "transfer", // or "spend". This transaction is a transfer from one account
184  // to another
185  "atTransfer", // reply from the server regarding a transfer request
186  "deposit", // this transaction is a deposit of bearer tokens (from client)
187  "atDeposit", // reply from the server regarding a deposit request
188  "withdrawal", // this transaction is a withdrawal of bearer tokens
189  "atWithdrawal", // reply from the server regarding a withdrawal request
190  "marketOffer", // this transaction is a market offer
191  "atMarketOffer", // reply from the server regarding a market offer
192  "paymentPlan", // this transaction is a payment plan
193  "atPaymentPlan", // reply from the server regarding a payment plan
194  "smartContract", // this transaction is a smart contract
195  "atSmartContract", // reply from the server regarding a smart contract
196  "cancelCronItem", // this transaction is a cancellation of a cron item
197  // (payment plan etc)
198  "atCancelCronItem", // reply from the server regarding said cancellation.
199  "exchangeBasket", // this transaction is an exchange in/out of a basket
200  // currency.
201  "atExchangeBasket", // reply from the server regarding said exchange.
202  "payDividend", // this transaction is a dividend payment (to the
203  // shareholders.)
204  "atPayDividend", // reply from the server regarding said dividend payment.
205  "error_state"};
206 
207 } // namespace
208 
209 namespace opentxs
210 {
211 
212 const char* GetTransactionTypeString(int transactionNumber)
213 {
214  return TypeStrings[transactionNumber];
215 }
216 
217 // Returns 1 if success, -1 if error.
219  int64_t& lNumberOfOrigin,
220  int64_t& lTransactionNum, int64_t& lInRefTo,
221  int64_t& lInRefDisplay, time64_t& the_DATE_SIGNED,
222  int& theType, OTString& strHash,
223  int64_t& lAdjustment, int64_t& lDisplayValue,
224  int64_t& lClosingNum, int64_t& lRequestNum,
225  bool& bReplyTransSuccess, OTNumList* pNumList)
226 {
227 
228  const OTString strOrigin = xml->getAttributeValue("numberOfOrigin");
229  const OTString strTransNum = xml->getAttributeValue("transactionNum");
230  const OTString strInRefTo = xml->getAttributeValue("inReferenceTo");
231  const OTString strInRefDisplay = xml->getAttributeValue("inRefDisplay");
232  const OTString strDateSigned = xml->getAttributeValue("dateSigned");
233 
234  if (!strTransNum.Exists() || !strInRefTo.Exists() ||
235  !strInRefDisplay.Exists() || !strDateSigned.Exists()) {
236  otOut << "OTTransaction::LoadAbbreviatedRecord: Failure: missing "
237  "strTransNum (" << strTransNum << ") or strInRefTo ("
238  << strInRefTo << ") or strInRefDisplay (" << strInRefDisplay
239  << ") or strDateSigned(" << strDateSigned
240  << ") while loading abbreviated receipt. \n";
241  return (-1);
242  }
243  lTransactionNum = atol(strTransNum.Get());
244  lInRefTo = atol(strInRefTo.Get());
245  lInRefDisplay = atol(strInRefDisplay.Get());
246 
247  if (strOrigin.Exists()) lNumberOfOrigin = atol(strOrigin.Get());
248 
249  // DATE SIGNED
250  the_DATE_SIGNED = OTTimeGetTimeFromSeconds(
251  strDateSigned.Get()); // (We already verified it Exists() just above.)
252 
253  // Transaction TYPE for the abbreviated record...
254  theType = OTTransaction::error_state; // default
255  const OTString strAbbrevType =
256  xml->getAttributeValue("type"); // the type of inbox receipt, or outbox
257  // receipt, or nymbox receipt.
258  // (Transaction type.)
259  if (strAbbrevType.Exists()) {
260  theType = OTTransaction::GetTypeFromString(strAbbrevType);
261 
262  if (OTTransaction::error_state == theType) {
263  otErr << "OTTransaction::LoadAbbreviatedRecord: Failure: "
264  "OTTransaction::error_state was the found type (based on "
265  "string " << strAbbrevType
266  << "), when loading abbreviated receipt for trans num: "
267  << lTransactionNum << " (In Reference To: " << lInRefTo
268  << ") \n";
269  return (-1);
270  }
271  }
272  else {
273  otOut << "OTTransaction::LoadAbbreviatedRecord: Failure: unknown "
274  "transaction type (" << strAbbrevType
275  << ") when "
276  "loading abbreviated receipt for trans num: "
277  << lTransactionNum << " (In Reference To: " << lInRefTo << ") \n";
278  return (-1);
279  }
280 
281  // RECEIPT HASH
282  //
283  strHash = xml->getAttributeValue("receiptHash");
284  if (!strHash.Exists()) {
285  otOut << "OTTransaction::LoadAbbreviatedRecord: Failure: Expected "
286  "receiptHash while loading "
287  "abbreviated receipt for trans num: " << lTransactionNum
288  << " (In Reference To: " << lInRefTo << ")\n";
289  return (-1);
290  }
291 
292  lAdjustment = 0;
293  lDisplayValue = 0;
294  lClosingNum = 0;
295 
296  const OTString strAbbrevAdjustment = xml->getAttributeValue("adjustment");
297  if (strAbbrevAdjustment.Exists())
298  lAdjustment = atol(strAbbrevAdjustment.Get());
299  // -------------------------------------
300  const OTString strAbbrevDisplayValue =
301  xml->getAttributeValue("displayValue");
302  if (strAbbrevDisplayValue.Exists())
303  lDisplayValue = atol(strAbbrevDisplayValue.Get());
304 
305  if (OTTransaction::replyNotice == theType) {
306  const OTString strRequestNum = xml->getAttributeValue("requestNumber");
307 
308  if (!strRequestNum.Exists()) {
309  otOut << "OTTransaction::LoadAbbreviatedRecord: Failed loading "
310  "abbreviated receipt: "
311  "expected requestNumber on replyNotice trans num: "
312  << lTransactionNum << " (In Reference To: " << lInRefTo
313  << ")\n";
314  return (-1);
315  }
316  lRequestNum = atol(strRequestNum.Get());
317 
318  const OTString strTransSuccess = xml->getAttributeValue("transSuccess");
319 
320  bReplyTransSuccess = strTransSuccess.Compare("true");
321  } // if replyNotice (expecting request Number)
322 
323  // If the transaction is a certain type, then it will also have a CLOSING
324  // number.
325  // (Grab that too.)
326  //
327  if ((OTTransaction::finalReceipt == theType) ||
328  (OTTransaction::basketReceipt == theType)) {
329  const OTString strAbbrevClosingNum =
330  xml->getAttributeValue("closingNum");
331 
332  if (!strAbbrevClosingNum.Exists()) {
333  otOut << "OTTransaction::LoadAbbreviatedRecord: Failed loading "
334  "abbreviated receipt: "
335  "expected closingNum on trans num: " << lTransactionNum
336  << " (In Reference To: " << lInRefTo << ")\n";
337  return (-1);
338  }
339  lClosingNum = atol(strAbbrevClosingNum.Get());
340  } // if finalReceipt or basketReceipt (expecting closing num)
341 
342  // These types carry their own internal list of numbers.
343  //
344  if ((nullptr != pNumList) && ((OTTransaction::blank == theType) ||
345  (OTTransaction::successNotice == theType))) {
346  const OTString strNumbers =
347  xml->getAttributeValue("totalListOfNumbers");
348  pNumList->Release();
349 
350  if (strNumbers.Exists()) pNumList->Add(strNumbers);
351  } // if blank or successNotice (expecting totalListOfNumbers.. no more
352  // multiple blanks in the same ledger! They all go in a single
353  // transaction.)
354 
355  return 1;
356 }
357 
359  const OTIdentifier& SERVER_ID,
360  const OTIdentifier& USER_ID, // Unused here for now, but still convention.
361  const OTIdentifier& ACCOUNT_ID, // If for Nymbox (vs inbox/outbox) then pass
362  // USER_ID in this field also.
363  const int32_t nBoxType, // 0/nymbox, 1/inbox, 2/outbox
364  const int64_t& lTransactionNum)
365 {
366  const int64_t lLedgerType = static_cast<int64_t>(nBoxType);
367 
368  const OTString strServerID(SERVER_ID),
369  strUserOrAcctID(0 == lLedgerType ? USER_ID : ACCOUNT_ID); // (For Nymbox
370  // aka type 0,
371  // the UserID
372  // will be
373  // here.)
374  // --------------------------------------------------------------------
375  OTString strFolder1name, strFolder2name, strFolder3name, strFilename;
376 
377  if (!SetupBoxReceiptFilename(lLedgerType, // nBoxType is lLedgerType
378  strUserOrAcctID, strServerID, lTransactionNum,
379  "OTTransaction::VerifyBoxReceiptExists",
380  strFolder1name, strFolder2name, strFolder3name,
381  strFilename))
382  return false; // This already logs -- no need to log twice, here.
383  // --------------------------------------------------------------------
384  // See if the box receipt exists before trying to save over it...
385  //
386  const bool bExists =
387  OTDB::Exists(strFolder1name.Get(), strFolder2name.Get(),
388  strFolder3name.Get(), strFilename.Get());
389 
390  otWarn << "OTTransaction::" << (bExists ? "(Already have this one)"
391  : "(Need to download this one)")
392  << ": " << __FUNCTION__ << ": " << strFolder1name
393  << OTLog::PathSeparator() << strFolder2name << OTLog::PathSeparator()
394  << strFolder3name << OTLog::PathSeparator() << strFilename << "\n";
395 
396  return bExists;
397 }
398 
400 {
401  const int64_t lLedgerType = static_cast<int64_t>(theLedger.GetType());
402  return LoadBoxReceipt(theAbbrev, lLedgerType);
403 }
404 
405 OTTransaction* LoadBoxReceipt(OTTransaction& theAbbrev, int64_t lLedgerType)
406 {
407  // See if the appropriate file exists, and load it up from
408  // local storage, into a string.
409  // Then, try to load the transaction from that string and see if successful.
410  // If it verifies, then return it. Otherwise return nullptr.
411 
412  // Can only load abbreviated transactions (so they'll become their full
413  // form.)
414  //
415  if (!theAbbrev.IsAbbreviated()) {
416  otOut << __FUNCTION__ << ": Unable to load box receipt "
417  << theAbbrev.GetTransactionNum()
418  << ": "
419  "(Because argument 'theAbbrev' wasn't abbreviated.)\n";
420  return nullptr;
421  }
422 
423  // Next, see if the appropriate file exists, and load it up from
424  // local storage, into a string.
425 
426  OTString strFolder1name, strFolder2name, strFolder3name, strFilename;
427 
429  lLedgerType, theAbbrev,
430  __FUNCTION__, // "OTTransaction::LoadBoxReceipt",
431  strFolder1name, strFolder2name, strFolder3name, strFilename))
432  return nullptr; // This already logs -- no need to log twice, here.
433 
434  // See if the box receipt exists before trying to load it...
435  //
436  if (!OTDB::Exists(strFolder1name.Get(), strFolder2name.Get(),
437  strFolder3name.Get(), strFilename.Get())) {
438  otWarn << __FUNCTION__
439  << ": Box receipt does not exist: " << strFolder1name
440  << OTLog::PathSeparator() << strFolder2name
441  << OTLog::PathSeparator() << strFolder3name
442  << OTLog::PathSeparator() << strFilename << "\n";
443  return nullptr;
444  }
445 
446  // Try to load the box receipt from local storage.
447  //
448  std::string strFileContents(OTDB::QueryPlainString(
449  strFolder1name.Get(), // <=== LOADING FROM DATA STORE.
450  strFolder2name.Get(), strFolder3name.Get(), strFilename.Get()));
451  if (strFileContents.length() < 2) {
452  otErr << __FUNCTION__ << ": Error reading file: " << strFolder1name
453  << OTLog::PathSeparator() << strFolder2name
454  << OTLog::PathSeparator() << strFolder3name
455  << OTLog::PathSeparator() << strFilename << "\n";
456  return nullptr;
457  }
458 
459  OTString strRawFile(strFileContents.c_str());
460 
461  if (!strRawFile.Exists()) {
462  otErr << __FUNCTION__ << ": Error reading file (resulting output "
463  "string is empty): " << strFolder1name
464  << OTLog::PathSeparator() << strFolder2name
465  << OTLog::PathSeparator() << strFolder3name
466  << OTLog::PathSeparator() << strFilename << "\n";
467  return nullptr;
468  }
469 
470  // Finally, try to load the transaction from that string and see if
471  // successful.
472  //
473  OTTransactionType* pTransType =
475 
476  if (nullptr == pTransType) {
477  otErr << __FUNCTION__ << ": Error instantiating transaction "
478  "type based on strRawFile: " << strFolder1name
479  << OTLog::PathSeparator() << strFolder2name
480  << OTLog::PathSeparator() << strFolder3name
481  << OTLog::PathSeparator() << strFilename << "\n";
482  return nullptr;
483  }
484 
485  OTTransaction* pBoxReceipt = dynamic_cast<OTTransaction*>(pTransType);
486 
487  if (nullptr == pBoxReceipt) {
488  otErr << __FUNCTION__
489  << ": Error dynamic_cast from transaction "
490  "type to transaction, based on strRawFile: " << strFolder1name
491  << OTLog::PathSeparator() << strFolder2name
492  << OTLog::PathSeparator() << strFolder3name
493  << OTLog::PathSeparator() << strFilename << "\n";
494  delete pTransType;
495  pTransType = nullptr; // cleanup!
496  return nullptr;
497  }
498 
499  // BELOW THIS POINT, pBoxReceipt exists, and is an OTTransaction pointer,
500  // and is loaded,
501  // and basically is ready to be compared to theAbbrev, which is its
502  // abbreviated version.
503  // It MUST either be returned or deleted.
504 
505  bool bSuccess = theAbbrev.VerifyBoxReceipt(*pBoxReceipt);
506 
507  if (!bSuccess) {
508  otErr << __FUNCTION__ << ": Failed verifying Box Receipt:\n"
509  << strFolder1name << OTLog::PathSeparator() << strFolder2name
510  << OTLog::PathSeparator() << strFolder3name
511  << OTLog::PathSeparator() << strFilename << "\n";
512 
513  delete pBoxReceipt;
514  pBoxReceipt = nullptr;
515  return nullptr;
516  }
517  else
518  otInfo << __FUNCTION__ << ": Successfully loaded Box Receipt in:\n"
519  << strFolder1name << OTLog::PathSeparator() << strFolder2name
520  << OTLog::PathSeparator() << strFolder3name
521  << OTLog::PathSeparator() << strFilename << "\n";
522 
523  // Todo: security analysis. By this point we've verified the hash of the
524  // transaction against the stored
525  // hash inside the abbreviated version. (VerifyBoxReceipt) We've also
526  // verified a few other values like transaction
527  // number, and the "in ref to" display number. We're then assuming based on
528  // those, that the adjustment and display
529  // amount are correct. (The hash is actually a zero knowledge proof of this
530  // already.) This is good for speedier
531  // optimization but may be worth revisiting in case any security holes.
532  // UPDATE: We'll save this for optimization needs in the future.
533  // pBoxReceipt->SetAbbrevAdjustment( theAbbrev.GetAbbrevAdjustment()
534  // );
535  // pBoxReceipt->SetAbbrevDisplayAmount(
536  // theAbbrev.GetAbbrevDisplayAmount() );
537 
538  return pBoxReceipt;
539 }
540 
541 bool SetupBoxReceiptFilename(int64_t lLedgerType,
542  const OTString& strUserOrAcctID,
543  const OTString& strServerID,
544  const int64_t& lTransactionNum,
545  const char* szCaller, OTString& strFolder1name,
546  OTString& strFolder2name, OTString& strFolder3name,
547  OTString& strFilename)
548 {
549  OT_ASSERT(nullptr != szCaller);
550 
551  const char* pszFolder = nullptr; // "nymbox" (or "inbox" or "outbox")
552  switch (lLedgerType) {
553  case 0:
554  pszFolder = OTFolders::Nymbox().Get();
555  break;
556  case 1:
557  pszFolder = OTFolders::Inbox().Get();
558  break;
559  case 2:
560  pszFolder = OTFolders::Outbox().Get();
561  break;
562  // case 3: (message ledger.)
563  case 4:
564  pszFolder = OTFolders::PaymentInbox().Get();
565  break;
566  case 5:
567  pszFolder = OTFolders::RecordBox().Get();
568  break;
569  case 6:
570  pszFolder = OTFolders::ExpiredBox().Get();
571  break;
572  default:
573  otErr << "OTTransaction::" << __FUNCTION__ << " " << szCaller
574  << ": Error: unknown box type: " << lLedgerType
575  << ". (This should never happen.)\n";
576  return false;
577  }
578 
579  strFolder1name.Set(pszFolder); // "nymbox" (or "inbox" or "outbox")
580  strFolder2name.Set(strServerID); // "SERVER_ID"
581  strFolder3name.Format("%s.r", strUserOrAcctID.Get()); // "USER_ID.r"
582 
583  strFilename.Format("%lld.rct", lTransactionNum); // "TRANSACTION_ID.rct"
584  // todo hardcoding of file extension. Need to standardize extensions.
585 
586  // Finished product: "nymbox/SERVER_ID/USER_ID.r/TRANSACTION_ID.rct"
587 
588  return true;
589 }
590 
591 bool SetupBoxReceiptFilename(int64_t lLedgerType, OTTransaction& theTransaction,
592  const char* szCaller, OTString& strFolder1name,
593  OTString& strFolder2name, OTString& strFolder3name,
594  OTString& strFilename)
595 {
596  OTString strUserOrAcctID;
597  theTransaction.GetIdentifier(strUserOrAcctID);
598 
599  const OTString strServerID(theTransaction.GetRealServerID());
600 
601  return SetupBoxReceiptFilename(lLedgerType, strUserOrAcctID, strServerID,
602  theTransaction.GetTransactionNum(), szCaller,
603  strFolder1name, strFolder2name,
604  strFolder3name, strFilename);
605 }
606 
607 bool SetupBoxReceiptFilename(OTLedger& theLedger, OTTransaction& theTransaction,
608  const char* szCaller, OTString& strFolder1name,
609  OTString& strFolder2name, OTString& strFolder3name,
610  OTString& strFilename)
611 {
612  int64_t lLedgerType = 0;
613 
614  switch (theLedger.GetType()) {
615  case OTLedger::nymbox:
616  lLedgerType = 0;
617  break;
618  case OTLedger::inbox:
619  lLedgerType = 1;
620  break;
621  case OTLedger::outbox:
622  lLedgerType = 2;
623  break;
624  // case OTLedger::message: lLedgerType = 3; break;
626  lLedgerType = 4;
627  break;
628  case OTLedger::recordBox:
629  lLedgerType = 5;
630  break;
632  lLedgerType = 6;
633  break;
634  default:
635  otErr << "OTTransaction::" << __FUNCTION__ << " " << szCaller
636  << ": Error: unknown box type. "
637  "(This should never happen.)\n";
638  return false;
639  }
640 
641  return SetupBoxReceiptFilename(lLedgerType, theTransaction, szCaller,
642  strFolder1name, strFolder2name,
643  strFolder3name, strFilename);
644 }
645 
646 } // namespace opentxs
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
static EXPORT const OTString & PaymentInbox()
Definition: OTFolders.cpp:339
EXPORT void Release()
Definition: OTNumList.cpp:465
static EXPORT OTTransactionType * TransactionFactory(OTString strInput)
static EXPORT const OTString & ExpiredBox()
Definition: OTFolders.cpp:363
static EXPORT const char * PathSeparator()
Definition: OTLog.cpp:408
OTLOG_IMPORT OTLogStream otOut
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
Definition: Common.hpp:215
int64_t time64_t
Definition: Common.hpp:209
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
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
OTTransaction * LoadBoxReceipt(OTTransaction &theAbbrev, OTLedger &theLedger)
Definition: Helpers.cpp:399
#define OT_ASSERT(x)
Definition: Assert.hpp:150
bool VerifyBoxReceipt(OTTransaction &theFullVersion)
static EXPORT const OTString & Outbox()
Definition: OTFolders.cpp:335
OTLOG_IMPORT OTLogStream otInfo
ledgerType GetType() const
Definition: OTLedger.hpp:212
static transactionType GetTypeFromString(const OTString &strType)
bool SetupBoxReceiptFilename(int64_t lLedgerType, OTTransaction &theTransaction, const char *szCaller, OTString &strFolder1name, OTString &strFolder2name, OTString &strFolder3name, OTString &strFilename)
Definition: Helpers.cpp:591
virtual EXPORT void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTContract.cpp:317
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT int64_t GetTransactionNum() const
bool IsAbbreviated() const
EXPORT const char * GetTransactionTypeString(int transactionNumber)
Definition: Helpers.cpp:212
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
const OTIdentifier & GetRealServerID() const