Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTTransaction.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTTransaction.hpp
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 #ifndef OPENTXS_CORE_TRANSACTION_HPP
134 #define OPENTXS_CORE_TRANSACTION_HPP
135 
136 #include "OTItem.hpp"
137 #include "transaction/Helpers.hpp"
138 
139 namespace opentxs
140 {
141 
142 /*
143 WHEN THE server receives a transaction request, it receives a MESSAGE containing
144 an ascii-armored LEDGER.
145 
146  The TYPE of the message might be "process inbox" or "process these transfers".
147  but either way there is a ledger bundled that contains a list of transactions
148 (often a list of one.)
149 
150  a ledger is stored as my inbox
151 
152  a ledger is sent in a message to send me my inbox
153 
154  a ledger is what I send the server when I ask it to process a couple of
155 transactions.
156  Each one of them has a transaction number.
157  Therefore the ledger must have a MAP of transactions, indexed by TRANSACTION
158 NUMBER.
159 
160  Therefore message cannot handle transaction number.
161 
162  Perhaps ledger is derived from message. CMD3 is a ledger in an envelope.
163  Then it can do everything that a message can do,
164 
165 
166 
167 
168  A message contains a payload of a ledger
169 
170  the ledger contains a list of transactions
171 
172 Ledger is derived from contract because you must be able to save / sign it and
173 load from string,
174  and because it must have items in it.
175 
176 
177  transactions are derived from messages. a transaction is a form of message.
178  (technically you could do a CMD3 and just send a transaction but the above is
179 cleaner.)
180 
181  Messages already have server ID, command, Account ID,
182 
183  No a transaction is just a sibling to a message. It's it's own thing derived
184 from contract.
185  but they have similarities
186 
187  so a ledger has a list of transactions. BOTH are derived from contract.
188 
189  A transaction has a list of Items. a transaction can also be "in reference to"
190 an item.
191 
192  does an item need to be a contract?
193 
194  each item has to be individually signed (because when I accept Sue's spend,
195 that signed accepted item goes back to Sue.)
196 
197  So the item has to be a contract. Each is signed and then put on the
198 transaction's list of items.
199 
200  Each transaction is also signed and includes a transaction number and is on the
201 ledger's list of transactions.
202 
203  The ledger itself is signed because it may be saved into a file.
204 
205  The whole enchilada is wrapped up in ascii-armor and attached to a message and
206 sent over the pipe.
207 */
208 
209 /*
210 
211  Partially loading transactions! (New development, born out of necessity.)
212 
213  A few volunteers have played with OT test servers, and we (unsurprisingly)
214 started noticing messaging
215  delays where a user had accumulated a thousand receipts in his inbox, and when
216 he tried to download it
217  he would miss the message, and thus get out of sync. He can't download his
218 inbox anymore.
219 
220  So now, the inbox is not going to contain a copy of the actual receipts
221 themselves, as normally with
222  transactions inside a ledger. Instead, the receipts will be saved into a
223 separate location, and they
224  will be given a "save to ledger" function that will save the full thing (for
225 message ledgers) or a partial
226  version (for inbox/outbox/nymbox ledgers) with no attachments (MUCH smaller
227 size) and which contains a hash
228  of the actual full receipt.
229 
230  OT should just be able to ASSUME that the client software has downloaded the
231 relevant receipts (a message
232  will be added to the protocol for downloading these receipts.) The transaction
233 object on an inbox will have
234  a flag set to false until the actual receipt has been loaded (not just the
235 inbox placeholder) and certain
236  actions will simply fail if that flag has not been set to true from the ACTUAL
237 full receipt being loaded.
238  Or the function will automatically try to load said receipt, and then fail if
239 that action fails. If the receipt
240  hash appears in the inbox, therefore the API should be able to assume that the
241 receipt itself is available for
242  inspection.
243 
244  Todo:
245  -- "Save To Abbreviated form" function.
246 
247  And what does it save?
248  transactionType m_Type; // blank, pending, processInbox,
249 transfer, deposit, withdrawal, trade, etc.
250  time64_t m_DATE_SIGNED; // The date, in seconds, when
251 the instrument was last signed.
252  int64_t m_lTransactionNum; // The server issues this and
253 it must be sent with transaction request.
254  int64_t m_lInReferenceToTransaction;
255  int64_t m_lClosingTransactionNo; // used by finalReceipt
256  also: AMOUNT. // GetReceiptAmount()
257  int64_t m_lAbbrevAmount; // Stored here after loading, but not
258 saved from here in the first place (see GetReceiptAmount())
259  int64_t m_lDisplayAmount; // Just like m_lAbbrevAmount, except
260 it stores the display amount. For example, a transferReceipt for a 5000 clam
261 transfer has an effective value of 0 (since the transfer is already done) but it
262 has a display amount of 5000.
263  OTIdentifier m_Hash; // Created while saving abbreviated
264 record, loaded back with it, then verified against actual hash when loading
265 actual box receipt.
266 
267  DOES NOT SAVE:
268  listOfItems m_listItems; // the various items in this transaction.
269  OTASCIIArmor m_ascCancellationRequest; // used by finalReceipt
270 // OTIdentifier m_ID; // Account ID. This is in OTContract
271 (parent class). Here we use it for the REAL ACCOUNT ID (set before loading.)
272  OTIdentifier m_AcctID; // Compare m_AcctID to m_ID after loading it
273 from string or file. They should match, and signature should verify.
274  OTIdentifier m_ServerID; // Server ID as used to instantiate the
275 transaction, based on expected ServerID.
276  OTIdentifier m_AcctServerID; // Actual ServerID within the signed
277 portion. (Compare to m_ServerID upon loading.)
278  OTIdentifier m_AcctUserID; // NymID of the user who created this
279 item. (In the future, this item
280  OTASCIIArmor m_ascInReferenceTo; // This item may be in reference to a
281 different item
282 
283  Normally we only save the "purported" values. But in "save to ledger" function
284 I only want to save the values
285  that I'm EXPECTING to be in those receipts, not the values that are ACTUALLY in
286 those receipts. (Of course they
287  ARE the values that were in the receipts when first saved, but I don't know
288 what will be in the receipts when I LOAD
289  them again, until I load them and verify that they are still the right ones.
290 Perhaps a substitution occured in the meantime.
291 
292  In any case, when I am making the abbreviated record, I already know that
293 information from the ledger itself
294  (user ID, account ID, server ID, etc) so I don't bother storing it for each
295 transaction at all since it's already
296  stored for the ledger as a whole. I can set the expected numbers based on that,
297 and then verify it against the purported
298  numbers when the ACTUAL receipt is loaded up.
299 
300  Hmm ProduceOutboxReportItem() and ProduceInboxReportItem() ALREADY do the work
301 of grabbing the Type, transaction#,
302  the reference #, the closing #, and the amount. Therefore I'll use that to do
303 the work, and then iterate the balance
304  item's sub-items when saving in abbreviated form. But this means I have to
305 store the hash in the sub-items (at the time
306  of their creation) which means I probably want to just keep it there for the
307 normal balance agreements as well. But
308  for normal balance agreements, the sub-items are stored on an actual item, so
309 I'll check out that code... maybe just save
310  that item itself directly in the ledger... except the balance portions aren't
311 appropriate, only the sub-item portions.
312  CHANGE OF HEART: I won't be using the sub-items for this, the difference is
313 great enough that I'd be forcing a square
314  peg into a round hole. Just adding a few functions for saving/loading in
315 abbreviated form.
316 
317 
318  NEED TO CODE:
319  -- Server message for downloading "box receipts."
320 
321  -- Method on OTTransaction for saving in abbreviated format to a string. Called
322 by...
323 
324  -- Fix OTLedger Load/Save so it only loads/saves transactions in abbreviated
325 format, which should only be
326  useful for getting enough information in order to download the receipts.
327 From there, the existing "verify"
328  function should try to load them all before actually verifying. (From there,
329 you have loaded and verified the transaction,
330  which we normally do anyway before using it, so now that's all done, so we
331 can go ahead and use it as normal.)
332 
333  -- How does user get his box receipts? downloads from server and loads during
334 verify process.
335 
336  -- How does Ledger save? It calls OTTransaction::SaveToAbbreviatedForm() or
337 some such, in a loop, and saves all their
338  vitals.
339 
340  -- How about the transactions themselves (the full "box receipts" and not just
341 abbreviated versions) ?
342  1. User never saves them other than when downloading from server, and he
343 must compare them against the hash in the box.
344  2. User loads them as part of verify process when verifying
345 inbox/outbox/nymbox.
346  3. Server must First Save them at the same time that they are added to the
347 box itself.
348  4. From there server can load anytime also, similar to user (verify
349 process.) Server should never fail since it CREATED the receipt.
350 
351  -- Server is safe to erase the box receipt at the same time that it's been
352 removed from its box. In practice this
353  should be handled by saving the box receipt with a MARKED FOR DELETION flag
354 added.
355 
356  -- WHERE to save? (client and server side)
357 
358  Keeping in mind there are also "cron receipts" (OTCronItem is for recurring
359 transactions like market offers/trades,
360  and smart contracts) as well as "transaction receipts" (*every* server reply to
361 every transaction request is automatically
362  saved, success or fail, as a transaction receipt.) They are stored like so:
363 
364  ~/.ot/client_data/receipts/tmHvLZxb13hW6OyH1oHKTmKd7fTMRsUfzqPE6KCwSjl
365  > ls
366  1mxwHcQvxSgqWqy2e28ZREeuVVfgs0kxE41FN10TnS3.success
367 2K3LoD1UxsJLO0FAfng0fgqnxnXScO8rM2eO5tdDTOE.success
368 T1Q3wZWgeTUoaUvn9m1lzIK5tn5wITlzxzrGNI8qtaV.success
369 vuXpQt8h6CRGcz6G5zMOXqQeIRpsOq05VLuJ5IAFS5R.success
370  2FHFr5NdT1r1XtUWVjll1uGcTKGKx4Pt1iWJ9eV0kkZ.success
371 A6CcGwNiTtEPQnv7HLUcmf0QFaCGy862pb1SJ3zVqIU.success
372 gys4puOdx15pknQYcVtF4DmOo2tOYouoiqcQAHKApSF.success
373 w06QIURsSDV7sdWWvyPSxRaiv4T2MUQbJyWmIKxSmuL.success
374 
375  basically:
376  OT_DATA/receipts/SERVER_ID/ACCT_ID.success
377  OT_DATA/receipts/SERVER_ID/ACCT_ID.fail
378 
379  or:
380  OT_DATA/receipts/SERVER_ID/NYM_ID.success
381  OT_DATA/receipts/SERVER_ID/NYM_ID.fail
382 
383  These receipts are related to balance agreement. These are the "last signed
384 receipt" that you keep in order to
385  verify later against future intermediary files, to make sure the server isn't
386 screwing you with bad intermediary
387  files. Sometimes there is a transaction statement, and sometimes there is a
388 balance agreement (depending on whether
389  both sides are merely agreeing on the list of signed-out transaction numbers,
390 or whether they are additionally
391  agreement on the balance and inbox items for a specific asset account as well.)
392 
393  (The transaction statements are the ones stored by NYM_ID, and the balance
394 agreements are the ones by ACCT_ID.)
395 
396  -----------
397 
398  In addition to "cron receipts" and "transaction receipts", I am now adding this
399 idea of "box receipts" which is really
400  just your inbox items stored in a separate file, because they simply won't all
401 fit comfortably in a getInbox message.
402  How to store them?
403 
404  Current inbox/outbox path: OT_DATA/[inbox|outbox]/SERVER_ID/ACCT_ID
405  Current nymbox path: OT_DATA/nymbox/SERVER_ID/NYM_ID
406 
407  Therefore I propose the box receipts to be stored:
408 
409  Inbox/outbox path: OT_DATA/inbox/SERVER_ID/ACCT_ID.r/TRANSACTION_ID.rct
410  nymbox path: OT_DATA/nymbox/SERVER_ID/NYM_ID.r/TRANSACTION_ID.rct
411 
412  When querying the server for a box receipt, you will have to provide TYPE
413 (inbox, outbox, etc)
414  as well as ID (acct ID or Nym ID, depending on which box type) as well as
415 transaction number,
416  and the hash.
417 
418  ------------
419 
420  Note: When loading from string, IF IN ABBREVIATED FORM, then we must take care
421 to verify the
422  loaded values against their expected counterparts, before OVERWRITING the
423 "expected" values
424  with the actual ones from the box receipts. Rather than store each value
425 separately, (as we did
426  with serverID, acctID, etc in OTTransactionType) we will instead simply take
427 care to verify them
428  during loading, if the "abbreviated" flag is set.
429 
430  ------------
431 
432  THE BEST TIME to actually SAVE the box receipt, on the Server Side, is at the
433 same time that it is first being
434  added to the relevant box itself. (Look into centralizing that mechanism...)
435 
436  */
437 
438 class OTLedger;
439 
441 {
443  OTString strInput);
444 
445 public:
446  // a transaction can be blank (issued from server)
447  // or pending (in the inbox/outbox)
448  // or it can be a "process inbox" transaction
449  // might also be in the nymbox.
451  // ***** INBOX / OUTBOX / NYMBOX
452 
453  // NYMBOX
454  blank, // freshly issued transaction number, not used yet
455  // (the server drops these into the nymbox.)
456  message, // A message from one user to another, also in the nymbox.
457  notice, // A notice from the server. Used in Nymbox.
458  replyNotice, // A copy of a server reply to a previous request you sent.
459  // (To make SURE you get the reply.)
460  successNotice, // A transaction # has successfully been signed out.
461 
462  // INBOX / OUTBOX (pending transfer)
463  pending, // Server puts this in your outbox (when sending) and
464  // recipient's inbox.
465 
466  // INBOX / receipts
467  transferReceipt, // the server drops this into your inbox, when someone
468  // accepts your transfer.
469  chequeReceipt, // the server drops this into your inbox, when someone
470  // deposits your cheque.
471  voucherReceipt, // the server drops this into your inbox, when someone
472  // deposits your voucher.
473  marketReceipt, // server periodically drops this into your inbox if an
474  // offer is live.
475  paymentReceipt, // the server drops this into people's inboxes, every
476  // time a payment processes. (from a payment plan or a
477  // smart contract)
478  finalReceipt, // the server drops this into your in/nym box(es), when a
479  // CronItem expires or is canceled.
480  basketReceipt, // the server drops this into your inboxes, when a basket
481  // exchange is processed.
482 
483  // PAYMENT INBOX / PAYMENT OUTBOX / RECORD BOX
484  instrumentNotice, // Receive these in paymentInbox (by way of Nymbox),
485  // and send in Outpayments (like Outmail).) (When
486  // done, they go to recordBox or expiredBox to await
487  // deletion.)
488  instrumentRejection, // When someone rejects your invoice from his
489  // paymentInbox, you get one of these in YOUR
490  // paymentInbox.
491 
492  // **** MESSAGES ****
493  processNymbox, // process nymbox transaction // comes from client
494  atProcessNymbox, // process nymbox reply // comes from
495  // server
496  processInbox, // process inbox transaction // comes from client
497  atProcessInbox, // process inbox reply // comes from server
498  transfer, // or "spend". This transaction is a request to transfer from
499  // one account to another
500  atTransfer, // reply from the server regarding a transfer request
501  deposit, // this transaction is a deposit (cash or cheque)
502  atDeposit, // reply from the server regarding a deposit request
503  withdrawal, // this transaction is a withdrawal (cash or voucher)
504  atWithdrawal, // reply from the server regarding a withdrawal request
505  marketOffer, // this transaction is a market offer
506  atMarketOffer, // reply from the server regarding a market offer
507  paymentPlan, // this transaction is a payment plan
508  atPaymentPlan, // reply from the server regarding a payment plan
509  smartContract, // this transaction is a smart contract
510  atSmartContract, // reply from the server regarding a smart contract
511  cancelCronItem, // this transaction is intended to cancel a market offer
512  // or payment plan.
513  atCancelCronItem, // reply from the server regarding said cancellation.
514  exchangeBasket, // this transaction is an exchange in/out of a basket
515  // currency.
516  atExchangeBasket, // reply from the server regarding said exchange.
517  payDividend, // this transaction is dividend payment (to all
518  // shareholders...)
519  atPayDividend, // reply from the server regarding said dividend payment.
521  }; // If you add any types to this list, update the list of strings at the
522  // top of the .CPP file.
523 
524 public:
525  OTTransaction(const OTLedger& theOwner);
526 
527  EXPORT OTTransaction(const OTIdentifier& theUserID,
528  const OTIdentifier& theAccountID,
529  const OTIdentifier& theServerID);
530 
531  OTTransaction(const OTIdentifier& theUserID,
532  const OTIdentifier& theAccountID,
533  const OTIdentifier& theServerID, int64_t lTransactionNum);
534 
535  // THIS constructor only used when loading an abbreviated box receipt
536  // (inbox, nymbox, or outbox receipt).
537  // The full receipt is loaded only after the abbreviated ones are loaded,
538  // and verified against them.
539  OTTransaction(const OTIdentifier& theUserID,
540  const OTIdentifier& theAccountID,
541  const OTIdentifier& theServerID,
542  const int64_t& lNumberOfOrigin,
543  const int64_t& lTransactionNum, const int64_t& lInRefTo,
544  const int64_t& lInRefDisplay, time64_t the_DATE_SIGNED,
545  transactionType theType, const OTString& strHash,
546  const int64_t& lAdjustment, const int64_t& lDisplayValue,
547  const int64_t& lClosingNum, const int64_t& lRequestNum,
548  bool bReplyTransSuccess, OTNumList* pNumList = nullptr);
549 
550  EXPORT virtual ~OTTransaction();
551 
552  virtual void Release();
553  EXPORT virtual int64_t GetNumberOfOrigin();
554  EXPORT virtual void CalculateNumberOfOrigin();
555 
556  // This calls VerifyContractID() as well as VerifySignature()
557  // Use this instead of OTContract::VerifyContract, which expects/uses a
558  // pubkey from inside the contract.
559  virtual bool VerifyAccount(const OTPseudonym& theNym);
560 
561  virtual bool SaveContractWallet(std::ofstream& ofs) const;
562 
563  void InitTransaction();
564 
565  EXPORT bool IsCancelled()
566  {
567  return m_bCancelled;
568  }
569 
570  EXPORT void SetAsCancelled()
571  {
572  m_bCancelled = true;
573  }
574 
575  void SetParent(const OTLedger& theParent)
576  {
577  m_pParent = &theParent;
578  }
579 
580  EXPORT bool AddNumbersToTransaction(const OTNumList& theAddition);
581 
582  bool IsAbbreviated() const
583  {
584  return m_bIsAbbreviated;
585  }
586 
587  int64_t GetAbbrevAdjustment() const
588  {
589  return m_lAbbrevAmount;
590  }
591 
592  void SetAbbrevAdjustment(int64_t lAmount)
593  {
594  m_lAbbrevAmount = lAmount;
595  }
596 
597  int64_t GetAbbrevDisplayAmount() const
598  {
599  return m_lDisplayAmount;
600  }
601 
602  void SetAbbrevDisplayAmount(int64_t lAmount)
603  {
604  m_lDisplayAmount = lAmount;
605  }
606 
607  int64_t GetAbbrevInRefDisplay() const
608  {
609  return m_lInRefDisplay;
610  }
611 
612  void SetAbbrevInRefDisplay(int64_t lAmount)
613  {
614  m_lInRefDisplay = lAmount;
615  }
616 
617  // These are used exclusively by replyNotice (so you can tell
618  // which reply message it's a notice of.)
619  const int64_t& GetRequestNum() const
620  {
621  return m_lRequestNumber;
622  }
623 
624  void SetRequestNum(const int64_t& lNum)
625  {
626  m_lRequestNumber = lNum;
627  }
628 
630  {
631  return m_bReplyTransSuccess;
632  }
633 
634  void SetReplyTransSuccess(bool bVal)
635  {
636  m_bReplyTransSuccess = bVal;
637  }
638 
639  // These are used for finalReceipt and basketReceipt
640  EXPORT int64_t GetClosingNum() const;
641  EXPORT void SetClosingNum(int64_t lClosingNum);
642  EXPORT int64_t GetReferenceNumForDisplay();
643 
651  EXPORT bool GetSenderUserIDForDisplay(OTIdentifier& theReturnID);
652  EXPORT bool GetRecipientUserIDForDisplay(OTIdentifier& theReturnID);
653 
654  EXPORT bool GetSenderAcctIDForDisplay(OTIdentifier& theReturnID);
655  EXPORT bool GetRecipientAcctIDForDisplay(OTIdentifier& theReturnID);
656  EXPORT bool GetMemo(OTString& strMemo);
657 
658  inline time64_t GetDateSigned() const
659  {
660  return m_DATE_SIGNED;
661  }
662 
663  EXPORT bool GetSuccess(); // Tries to determine, based on items within,
664  // whether it was a success or fail.
665 
666  EXPORT int64_t GetReceiptAmount(); // Tries to determine IF there is an
667  // amount (depending on type) and return
668  // it.
669 
670  EXPORT static OTTransaction* GenerateTransaction(
671  const OTIdentifier& theUserID, const OTIdentifier& theAccountID,
672  const OTIdentifier& theServerID, transactionType theType,
673  int64_t lTransactionNum = 0);
674 
675  EXPORT static OTTransaction* GenerateTransaction(
676  const OTLedger& theOwner, transactionType theType,
677  int64_t lTransactionNum = 0);
678  inline transactionType GetType() const
679  {
680  return m_Type;
681  }
682 
683  inline void SetType(transactionType theType)
684  {
685  m_Type = theType;
686  }
687 
688  // This function assumes that theLedger is the owner of this transaction.
689  // We pass the ledger in so we can determine the proper directory we're
690  // reading from.
691  EXPORT bool SaveBoxReceipt(int64_t lLedgerType);
692 
693  EXPORT bool SaveBoxReceipt(OTLedger& theLedger);
694 
695  EXPORT bool DeleteBoxReceipt(OTLedger& theLedger);
696 
697  // Call on abbreviated version, and pass in the purported full version.
698  bool VerifyBoxReceipt(OTTransaction& theFullVersion);
699 
700  EXPORT bool VerifyBalanceReceipt(OTPseudonym& SERVER_NYM,
701  OTPseudonym& THE_NYM);
702 
703  // First VerifyContractID() is performed already on all the items when
704  // they are first loaded up. ServerID and AccountID have been verified.
705  // Now we check ownership, and signatures, and transaction #s, etc.
706  // (We go deeper.)
707  EXPORT bool VerifyItems(OTPseudonym& theNym);
708 
709  inline int32_t GetItemCount() const
710  {
711  return static_cast<int32_t>(m_listItems.size());
712  }
713 
714  int32_t GetItemCountInRefTo(int64_t lReference); // Count the number
715  // of items that are
716  // IN REFERENCE TO
717  // some transaction#.
718 
719  // While processing a transaction, you may wish to query it for items of a
720  // certain type.
721  EXPORT OTItem* GetItem(OTItem::itemType theType);
722 
723  EXPORT OTItem* GetItemInRefTo(int64_t lReference);
724 
725  EXPORT void AddItem(OTItem& theItem); // You have to allocate the item on
726  // the heap and then pass it in as a
727  // reference.
728  // OTTransaction will take care of it from there and will delete it in
729  // destructor.
730  // used for looping through the items in a few places.
732  {
733  return m_listItems;
734  }
735 
736  // Because all of the actual receipts cannot fit into the single inbox
737  // file, you must put their hash, and then store the receipt itself
738  // separately...
739  void SaveAbbreviatedNymboxRecord(OTString& strOutput);
740  void SaveAbbreviatedOutboxRecord(OTString& strOutput);
741  void SaveAbbreviatedInboxRecord(OTString& strOutput);
742  void SaveAbbrevPaymentInboxRecord(OTString& strOutput);
743  void SaveAbbrevRecordBoxRecord(OTString& strOutput);
744  void SaveAbbrevExpiredBoxRecord(OTString& strOutput);
745  void ProduceInboxReportItem(OTItem& theBalanceItem);
746  void ProduceOutboxReportItem(OTItem& theBalanceItem);
747 
748  static transactionType GetTypeFromString(const OTString& strType);
749 
750  const char* GetTypeString() const
751  {
752  return GetTransactionTypeString(static_cast<int>(m_Type));
753  }
754 
755  // These functions are fairly smart about which transaction types are
756  // harvestable,
757  // in which situations (based on the bools.) As long as you use the bools
758  // correctly,
759  // you aren't likely to accidentally harvest an opening number unless you
760  // are SUPPOSED
761  // to harvest it, based on its type and the circumstances. Just make sure
762  // you are accurate
763  // when you tell it the circumstances (bools!)
765  OTPseudonym& theNym,
766  bool bHarvestingForRetry, // exchangeBasket, on retry, needs to
767  // clawback the opening # because it
768  // will be using another opening # the
769  // next time OT_API_exchangeBasket() is
770  // called.
771  bool bReplyWasSuccess, // false until positively asserted.
772  bool bReplyWasFailure, // false until positively asserted.
773  bool bTransactionWasSuccess, // false until positively asserted.
774  bool bTransactionWasFailure); // false until positively asserted.
775 
776  // NOTE: IN CASE it's not obvious, the NYM is harvesting numbers from the
777  // TRANSACTION, and not the other way around!
778 
779  // Normally do this if your transaction ran--and failed--so you can get most
780  // of your transaction numbers back. (The opening number is already gone,
781  // but any others are still salvageable.)
783  OTPseudonym& theNym,
784  bool bHarvestingForRetry, // exchangeBasket, on retry, needs to
785  // clawback the opening # because it
786  // will be using another opening # the
787  // next time OT_API_exchangeBasket() is
788  // called.
789  bool bReplyWasSuccess, // false until positively asserted.
790  bool bReplyWasFailure, // false until positively asserted.
791  bool bTransactionWasSuccess, // false until positively asserted.
792  bool bTransactionWasFailure); // false until positively asserted.
793 
794 protected:
795  // return -1 if error, 0 if nothing, and 1 if the node was processed.
796  virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader*& xml);
797 
798  virtual void UpdateContents(); // Before transmission or serialization, this
799  // is where the transaction saves its
800  // contents
801 
802  OTTransaction(); // only the factory gets to use this one.
803 
804 protected:
805  // Usually a transaction object is inside a ledger object.
806  // If this is not nullptr, then you can reference that object.
808 
809  // Transactions can be loaded in abbreviated form from a ledger, but they
810  // are not considered "actually loaded"
811  // until their associated "box receipt" is also loaded up from storage, and
812  // verified against its hash.
813  // From the time they are loaded in abbreviated form, this flag is set true,
814  // until the box receipt is loaded.
815  // This value defaults to false, so if the transaction was never loaded in
816  // abbreviated form, then this is never
817  // set to true in the first place.
819 
820  // The "Amount" of the transaction is not normally stored in the transaction
821  // itself, but in one of its
822  // transaction items. However, when saving/loading the transaction in
823  // abbreviated form, the amount is
824  // placed here, which makes it available for necessary calculations without
825  // being forced to load up
826  // all of the box receipts to do so.
827 
829 
830  // Just like m_lAbbrevAmount, except it stores the display amount. For
831  // example, a transferReceipt for
832  // a 5000 clam transfer has an effective value of 0 (since the transfer is
833  // already done) but it has a
834  // display amount of 5000.
835  // As with m_lAbbrevAmount, the Display amount value is calculated just
836  // before saving in abbreviated
837  // form, and this variable is only set upon LOADING that value in
838  // abbreviated form. The actual value
839  // only becomes available when loading the ACTUAL box receipt, at which time
840  // it should be compared to
841  // this one. (If loading the transaction fails, as a result of a failed
842  // verification there, then these
843  // numbers become pretty reliable and can be used in optimization, since the
844  // current process of loading
845  // transaction items from a string every time we need to check the amount,
846  // can be time-consuming, CPU-wise.)
848 
849  // The value of GetReferenceNumForDisplay() is saved when saving an
850  // abbreviated record of this transaction,
851  // and then loaded into THIS member variable when loading the abbreviated
852  // record.
854 
855  // This hash is not stored inside the box receipt itself (a transaction that
856  // appears in an inbox, outbox, or nymbox)
857  // but rather, is set from above, and then verified against the actual box
858  // receipt once it is loaded.
859  // This verification occurs only when loading the box receipt, and this Hash
860  // value is not saved again to any
861  // location. When the abbreviated form of the box receipt is saved inside
862  // the inbox itself, it is easy to
863  // just create the hash at that time. Then upon loading the ledger (the box)
864  // the hash is set based on the abbreviated entry.
865  // The hash can then be verified against the actual box receipt by hashing
866  // that and comparing them, after which I no
867  // longer care about this variable at all, and do not save it again, since
868  // it can be re-calculated the next time we
869  // save again in abbreviated form.
870  OTIdentifier m_Hash; // todo: make this const and force it to be set during
871  // construction.
872 
873  time64_t m_DATE_SIGNED; // The date, in seconds, when the instrument was
874  // last signed.
875  transactionType m_Type; // blank, pending, processInbox, transfer, deposit,
876  // withdrawal, trade, etc.
877  listOfItems m_listItems; // the various items in this transaction.
878 
879  int64_t m_lClosingTransactionNo; // used by finalReceipt
880  OTASCIIArmor m_ascCancellationRequest; // used by finalReceipt
881 
882  // ONLY the "replyNotice" transaction uses this field.
883  // When replyNotices are dropped into your Nymbox (server notices
884  // of replies to messages you sent in the past) I wanted to put that
885  // they were "in reference to" a specific request number. But I don't
886  // want to muddy the "in reference to" code now which currently only
887  // references transaction numbers, not request numbers. Therefore I
888  // have added a special variable here for request numbers, so that
889  // replyNotices in the Nymbox can directly finger the messages they
890  // came from.
891  int64_t m_lRequestNumber; // Unused except by "replyNotice" in Nymbox.
892  bool m_bReplyTransSuccess; // Used only by replyNotice
893  // Unused except for @notarizeTransactions, specifically for @paymentPlan
894  // and @smartContract. (And maybe @depositCheque...) There are specific
895  // cases where the user sends through a transaction that is MEANT to be
896  // rejected by the server, for the purpose of cancelling that transaction.
897  // For example, if I sent a smart contract on to the next party, and then
898  // later I decided to cancel it (before the next party had the chance to
899  // activate it.) I send through the (incomplete) contract AS THOUGH to
900  // activate it, specifically so the activation will fail (and thus cancel
901  // the smart contract.) This prevents anyone from activating it in the
902  // future (thus, it's now "cancelled.")
903  //
904  // In these cases, when I am "cancelling" something, a successful
905  // cancellation
906  // will result in a "rejected" reply from the server. A notice of this is
907  // sent to all the parties as well. The rejection notice causes all the
908  // parties to properly harvest their transaction numbers as they normally
909  // would when a smart contract fails activation. (Thus, a successful
910  // cancellation.)
911  //
912  // But how do we know the difference between a normal "rejection" versus
913  // a "rejection" that corresponds to a successful cancellation? That's
914  // what m_bCancelled is for. If the server has just successfully cancelled
915  // something, it will set m_bCancelled to TRUE (on the reply transaction.)
916  // This way the client side can tell the difference between an actual
917  // failed attempt marked as "rejected", versus a successful cancellation
918  // marked as "rejected." All the client has to do is check m_bCancelled
919  // to see if it's set to TRUE, and it will know.
921 };
922 
923 } // namespace opentxs
924 
925 #endif // OPENTXS_CORE_TRANSACTION_HPP
virtual void UpdateContents()
virtual EXPORT ~OTTransaction()
EXPORT bool GetSenderAcctIDForDisplay(OTIdentifier &theReturnID)
static EXPORT OTTransaction * GenerateTransaction(const OTIdentifier &theUserID, const OTIdentifier &theAccountID, const OTIdentifier &theServerID, transactionType theType, int64_t lTransactionNum=0)
void SaveAbbrevExpiredBoxRecord(OTString &strOutput)
void SetAbbrevDisplayAmount(int64_t lAmount)
EXPORT bool AddNumbersToTransaction(const OTNumList &theAddition)
void SaveAbbrevRecordBoxRecord(OTString &strOutput)
void SaveAbbreviatedInboxRecord(OTString &strOutput)
bool HarvestClosingNumbers(OTPseudonym &theNym, bool bHarvestingForRetry, bool bReplyWasSuccess, bool bReplyWasFailure, bool bTransactionWasSuccess, bool bTransactionWasFailure)
virtual EXPORT int64_t GetNumberOfOrigin()
const OTLedger * m_pParent
static EXPORT OTTransactionType * TransactionFactory(OTString strInput)
EXPORT bool DeleteBoxReceipt(OTLedger &theLedger)
EXPORT bool GetRecipientAcctIDForDisplay(OTIdentifier &theReturnID)
int64_t GetAbbrevAdjustment() const
virtual bool VerifyAccount(const OTPseudonym &theNym)
void SaveAbbreviatedNymboxRecord(OTString &strOutput)
EXPORT OTItem * GetItemInRefTo(int64_t lReference)
void SaveAbbrevPaymentInboxRecord(OTString &strOutput)
EXPORT bool GetSenderUserIDForDisplay(OTIdentifier &theReturnID)
int64_t time64_t
Definition: Common.hpp:209
const int64_t & GetRequestNum() const
const char * GetTypeString() const
int32_t GetItemCountInRefTo(int64_t lReference)
EXPORT bool GetMemo(OTString &strMemo)
EXPORT OTItem * GetItem(OTItem::itemType theType)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT void SetClosingNum(int64_t lClosingNum)
OTASCIIArmor m_ascCancellationRequest
EXPORT int64_t GetClosingNum() const
bool HarvestOpeningNumber(OTPseudonym &theNym, bool bHarvestingForRetry, bool bReplyWasSuccess, bool bReplyWasFailure, bool bTransactionWasSuccess, bool bTransactionWasFailure)
bool VerifyBoxReceipt(OTTransaction &theFullVersion)
EXPORT bool VerifyBalanceReceipt(OTPseudonym &SERVER_NYM, OTPseudonym &THE_NYM)
static transactionType GetTypeFromString(const OTString &strType)
void SetReplyTransSuccess(bool bVal)
std::list< OTItem * > listOfItems
Definition: OTItem.hpp:145
void SetAbbrevInRefDisplay(int64_t lAmount)
time64_t GetDateSigned() const
EXPORT bool SaveBoxReceipt(int64_t lLedgerType)
EXPORT int64_t GetReferenceNumForDisplay()
int64_t GetAbbrevDisplayAmount() const
void SaveAbbreviatedOutboxRecord(OTString &strOutput)
transactionType GetType() const
int32_t GetItemCount() const
void ProduceInboxReportItem(OTItem &theBalanceItem)
EXPORT int64_t GetReceiptAmount()
bool IsAbbreviated() const
void SetRequestNum(const int64_t &lNum)
EXPORT const char * GetTransactionTypeString(int transactionNumber)
Definition: Helpers.cpp:212
transactionType m_Type
void ProduceOutboxReportItem(OTItem &theBalanceItem)
void SetAbbrevAdjustment(int64_t lAmount)
listOfItems & GetItemList()
EXPORT void SetAsCancelled()
EXPORT bool VerifyItems(OTPseudonym &theNym)
EXPORT void AddItem(OTItem &theItem)
void SetType(transactionType theType)
virtual bool SaveContractWallet(std::ofstream &ofs) const
int64_t GetAbbrevInRefDisplay() const
void SetParent(const OTLedger &theParent)
EXPORT bool GetRecipientUserIDForDisplay(OTIdentifier &theReturnID)
virtual EXPORT void CalculateNumberOfOrigin()