Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTCronItem.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTCronItem.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 // Base class for OTTrade and OTAgreement.
134 // OTCron contains lists of these for regular processing.
135 
136 #ifndef OPENTXS_CORE_CRON_OTCRONITEM_HPP
137 #define OPENTXS_CORE_CRON_OTCRONITEM_HPP
138 
139 #include "../OTTrackable.hpp"
140 
141 #include <deque>
142 
143 namespace opentxs
144 {
145 
146 class OTCron;
147 class OTIdentifier;
148 class OTPseudonym;
149 class OTString;
150 
151 class OTCronItem : public OTTrackable
152 {
153 public:
154  OTCronItem();
155 
156 private: // Private prevents erroneous use by other classes.
157  typedef OTTrackable ot_super;
158 
159 private:
160  OTCron* m_pCron;
161  OTPseudonym* serverNym_;
162  OTIdentifier* serverId_;
163  time64_t m_CREATION_DATE; // The date, in seconds, when the CronItem was
164  // authorized.
165  time64_t m_LAST_PROCESS_DATE; // The last time this item was processed.
166  int64_t m_PROCESS_INTERVAL; // How often to Process Cron on this item.
167 
168 protected:
169  std::deque<int64_t> m_dequeClosingNumbers; // Numbers used for CLOSING a
170  // transaction. (finalReceipt.)
171 
172 protected:
173  OTCronItem(const OTIdentifier& SERVER_ID, const OTIdentifier& ASSET_ID);
174  OTCronItem(const OTIdentifier& SERVER_ID, const OTIdentifier& ASSET_ID,
175  const OTIdentifier& ACCT_ID, const OTIdentifier& USER_ID);
176 
178 
179  bool m_bCanceled; // This defaults to false. But if someone cancels it
180  // (BEFORE it is ever activated, just to nip it in the bud
181  // and harvest the numbers, and send the notices, etc) --
182  // then we set this to true, and we also set the canceler
183  // Nym ID. (So we can see these values later and know
184  // whether it was canceled before activation, and if so,
185  // who did it.)
186 
187  bool m_bRemovalFlag; // Set this to true and the cronitem will be removed
188  // from Cron on next process.
189  // (And its offer will be removed from the Market as well, if appropriate.)
190  virtual void onActivate()
191  {
192  } // called by HookActivationOnCron().
193 
194  virtual void onFinalReceipt(
195  OTCronItem& theOrigCronItem, const int64_t& lNewTransactionNumber,
196  OTPseudonym& theOriginator,
197  OTPseudonym* pRemover); // called by HookRemovalFromCron().
198 
199  virtual void onRemovalFromCron()
200  {
201  } // called by HookRemovalFromCron().
202  void ClearClosingNumbers();
203 
204 public:
205  // To force the Nym to close out the closing number on the receipt.
207  const OTIdentifier& USER_ID, const OTIdentifier& ACCOUNT_ID,
208  const int64_t& lNewTransactionNumber, const int64_t& lClosingNumber,
209  const OTString& strOrigCronItem, OTString* pstrNote = nullptr,
210  OTString* pstrAttachment = nullptr, OTAccount* pActualAcct = nullptr);
211 
212  // Notify the Nym that the OPENING number is now closed, so he can remove it
213  // from his issued list.
214  bool DropFinalReceiptToNymbox(const OTIdentifier& USER_ID,
215  const int64_t& lNewTransactionNumber,
216  const OTString& strOrigCronItem,
217  OTString* pstrNote = nullptr,
218  OTString* pstrAttachment = nullptr,
219  OTPseudonym* pActualNym = nullptr);
220  virtual bool CanRemoveItemFromCron(OTPseudonym& theNym);
221  virtual void HarvestOpeningNumber(OTPseudonym& theNym);
222  virtual void HarvestClosingNumbers(OTPseudonym& theNym);
223  // pActivator and pRemover are both "SOMETIMES nullptr"
224  // I don't default the parameter, because I want to force the programmer to
225  // choose.
226 
227  // Called in OTCron::AddCronItem.
228  void HookActivationOnCron(OTPseudonym* pActivator,
229  bool bForTheFirstTime = false); // This calls
230  // onActivate,
231  // which is
232  // virtual.
233 
234  // Called in OTCron::RemoveCronItem as well as OTCron::ProcessCron.
235  // This calls onFinalReceipt, then onRemovalFromCron. Both are virtual.
236  void HookRemovalFromCron(OTPseudonym* pRemover, int64_t newTransactionNo);
237 
238  inline bool IsFlaggedForRemoval() const
239  {
240  return m_bRemovalFlag;
241  }
242  inline void FlagForRemoval()
243  {
244  m_bRemovalFlag = true;
245  }
246  inline void SetCronPointer(OTCron& theCron)
247  {
248  m_pCron = &theCron;
249  }
250 
251  EXPORT static OTCronItem* NewCronItem(const OTString& strCronItem);
252  EXPORT static OTCronItem* LoadCronReceipt(
253  const int64_t& lTransactionNum); // Server-side only.
254  EXPORT static OTCronItem* LoadActiveCronReceipt(
255  const int64_t& lTransactionNum,
256  const OTIdentifier& serverID); // Client-side only.
257  EXPORT static bool EraseActiveCronReceipt(
258  const int64_t& lTransactionNum, const OTIdentifier& nymID,
259  const OTIdentifier& serverID); // Client-side only.
260  EXPORT static bool GetActiveCronTransNums(OTNumList& output, // Client-side
261  // only.
262  const OTIdentifier& nymID,
263  const OTIdentifier& serverID);
264  inline void SetCreationDate(const time64_t& CREATION_DATE)
265  {
266  m_CREATION_DATE = CREATION_DATE;
267  }
268  inline const time64_t& GetCreationDate() const
269  {
270  return m_CREATION_DATE;
271  }
272 
273  EXPORT bool SetDateRange(time64_t VALID_FROM = OT_TIME_ZERO,
274  time64_t VALID_TO = OT_TIME_ZERO);
275  inline void SetLastProcessDate(const time64_t& THE_DATE)
276  {
277  m_LAST_PROCESS_DATE = THE_DATE;
278  }
279  inline const time64_t& GetLastProcessDate() const
280  {
281  return m_LAST_PROCESS_DATE;
282  }
283 
284  inline void SetProcessInterval(const int64_t& THE_DATE)
285  {
286  m_PROCESS_INTERVAL = THE_DATE;
287  }
288  inline const int64_t& GetProcessInterval() const
289  {
290  return m_PROCESS_INTERVAL;
291  }
292 
293  inline OTCron* GetCron() const
294  {
295  return m_pCron;
296  }
297  void setServerNym(OTPseudonym* serverNym)
298  {
299  serverNym_ = serverNym;
300  }
301  void setServerId(OTIdentifier* serverId)
302  {
303  serverId_ = serverId;
304  }
305  // When first adding anything to Cron, a copy needs to be saved in a folder
306  // somewhere.
307  EXPORT bool SaveCronReceipt(); // server side only
308  EXPORT bool SaveActiveCronReceipt(const OTIdentifier& theNymID); // client
309  // side
310  // only
311 
312  // Return True if should stay on OTCron's list for more processing.
313  // Return False if expired or otherwise should be removed.
314  virtual bool ProcessCron(); // OTCron calls this regularly, which is my
315  // chance to expire, etc.
316  // From OTTrackable (parent class of this)
317  virtual ~OTCronItem();
318 
319  void InitCronItem();
320 
321  virtual void Release();
322  void Release_CronItem();
323  EXPORT bool GetCancelerID(OTIdentifier& theOutput) const;
324  EXPORT bool IsCanceled() const
325  {
326  return m_bCanceled;
327  }
328  EXPORT bool CancelBeforeActivation(
329  OTPseudonym& theCancelerNym); // When canceling a cron item before it
330  // has been activated, use this.
331  // These are for std::deque<int64_t> m_dequeClosingNumbers;
332  // They are numbers used for CLOSING a transaction. (finalReceipt.)
333 
334  EXPORT int64_t GetClosingTransactionNoAt(uint32_t nIndex) const;
335  EXPORT int32_t GetCountClosingNumbers() const;
336 
337  EXPORT void AddClosingTransactionNo(const int64_t& lClosingTransactionNo);
338 
339  // HIGHER LEVEL ABSTRACTIONS:
340  EXPORT int64_t GetOpeningNum() const;
341  EXPORT int64_t GetClosingNum() const;
342  virtual bool IsValidOpeningNumber(const int64_t& lOpeningNum) const;
343 
344  virtual int64_t GetOpeningNumber(const OTIdentifier& theNymID) const;
345  virtual int64_t GetClosingNumber(const OTIdentifier& theAcctID) const;
346  virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader*& xml);
347  // virtual void UpdateContents(); // Before transmission or
348  // serialization, this is where the ledger saves its contents
349  // virtual bool SaveContractWallet(std::ofstream& ofs) const;
350 };
351 
352 } // namespace opentxs
353 
354 #endif // OPENTXS_CORE_CRON_OTCRONITEM_HPP
virtual int64_t GetOpeningNumber(const OTIdentifier &theNymID) const
EXPORT bool IsCanceled() const
Definition: OTCronItem.hpp:324
EXPORT bool SaveCronReceipt()
Definition: OTCronItem.cpp:577
virtual void HarvestClosingNumbers(OTPseudonym &theNym)
virtual bool IsValidOpeningNumber(const int64_t &lOpeningNum) const
virtual void HarvestOpeningNumber(OTPseudonym &theNym)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT bool SaveActiveCronReceipt(const OTIdentifier &theNymID)
Definition: OTCronItem.cpp:453
void HookRemovalFromCron(OTPseudonym *pRemover, int64_t newTransactionNo)
Definition: OTCronItem.cpp:815
static EXPORT OTCronItem * LoadCronReceipt(const int64_t &lTransactionNum)
Definition: OTCronItem.cpp:227
bool IsFlaggedForRemoval() const
Definition: OTCronItem.hpp:238
virtual bool CanRemoveItemFromCron(OTPseudonym &theNym)
Definition: OTCronItem.cpp:700
virtual void onFinalReceipt(OTCronItem &theOrigCronItem, const int64_t &lNewTransactionNumber, OTPseudonym &theOriginator, OTPseudonym *pRemover)
Definition: OTCronItem.cpp:993
int64_t time64_t
Definition: Common.hpp:209
void SetCreationDate(const time64_t &CREATION_DATE)
Definition: OTCronItem.hpp:264
EXPORT int64_t GetClosingTransactionNoAt(uint32_t nIndex) const
Definition: OTCronItem.cpp:681
void SetCronPointer(OTCron &theCron)
Definition: OTCronItem.hpp:246
bool DropFinalReceiptToInbox(const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, const int64_t &lNewTransactionNumber, const int64_t &lClosingNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTAccount *pActualAcct=nullptr)
EXPORT int32_t GetCountClosingNumbers() const
Definition: OTCronItem.cpp:676
virtual bool ProcessCron()
Definition: OTCronItem.cpp:769
EXPORT bool GetCancelerID(OTIdentifier &theOutput) const
EXPORT bool SetDateRange(time64_t VALID_FROM=OT_TIME_ZERO, time64_t VALID_TO=OT_TIME_ZERO)
Definition: OTCronItem.cpp:619
static EXPORT bool EraseActiveCronReceipt(const int64_t &lTransactionNum, const OTIdentifier &nymID, const OTIdentifier &serverID)
Definition: OTCronItem.cpp:344
static EXPORT bool GetActiveCronTransNums(OTNumList &output, const OTIdentifier &nymID, const OTIdentifier &serverID)
Definition: OTCronItem.cpp:303
EXPORT bool CancelBeforeActivation(OTPseudonym &theCancelerNym)
const int64_t & GetProcessInterval() const
Definition: OTCronItem.hpp:288
EXPORT int64_t GetClosingNum() const
static EXPORT OTCronItem * LoadActiveCronReceipt(const int64_t &lTransactionNum, const OTIdentifier &serverID)
Definition: OTCronItem.cpp:262
EXPORT int64_t GetOpeningNum() const
void setServerNym(OTPseudonym *serverNym)
Definition: OTCronItem.hpp:297
void setServerId(OTIdentifier *serverId)
Definition: OTCronItem.hpp:301
OTIdentifier * m_pCancelerNymID
Definition: OTCronItem.hpp:177
const time64_t & GetLastProcessDate() const
Definition: OTCronItem.hpp:279
bool DropFinalReceiptToNymbox(const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
EXPORT void AddClosingTransactionNo(const int64_t &lClosingTransactionNo)
Definition: OTCronItem.cpp:693
std::deque< int64_t > m_dequeClosingNumbers
Definition: OTCronItem.hpp:169
#define OT_TIME_ZERO
Definition: Common.hpp:180
OTCron * GetCron() const
Definition: OTCronItem.hpp:293
virtual int64_t GetClosingNumber(const OTIdentifier &theAcctID) const
void HookActivationOnCron(OTPseudonym *pActivator, bool bForTheFirstTime=false)
Definition: OTCronItem.cpp:797
virtual void Release()
static EXPORT OTCronItem * NewCronItem(const OTString &strCronItem)
Definition: OTCronItem.cpp:165
void SetProcessInterval(const int64_t &THE_DATE)
Definition: OTCronItem.hpp:284
const time64_t & GetCreationDate() const
Definition: OTCronItem.hpp:268
virtual void onRemovalFromCron()
Definition: OTCronItem.hpp:199
virtual void onActivate()
Definition: OTCronItem.hpp:190
void SetLastProcessDate(const time64_t &THE_DATE)
Definition: OTCronItem.hpp:275