Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTRecordList.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTRecordList.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_CLIENT_OTRECORDLIST_HPP
134 #define OPENTXS_CLIENT_OTRECORDLIST_HPP
135 
137 
138 #include <list>
139 #include <map>
140 #include <vector>
141 
142 // For address book lookups. Your client app inherits this and provides
143 // addr storage/lookup through this simple interface. OTRecordList then
144 // calls it.
145 //
146 
147 namespace opentxs
148 {
149 
151 {
152 public:
153  EXPORT OTNameLookup()
154  {
155  }
156  EXPORT virtual ~OTNameLookup();
157 
158  EXPORT virtual std::string GetNymName(
159  const std::string& str_id, // NymID
160  const std::string* p_server_id = nullptr) const;
161 
162  EXPORT virtual std::string GetAcctName(
163  const std::string& str_id, // AcctID
164  const std::string* p_nym_id = nullptr,
165  const std::string* p_server_id = nullptr,
166  const std::string* p_asset_id = nullptr) const;
167 
168  EXPORT virtual std::string GetAddressName(const std::string& str_address)
169  const; // Used for Bitmessage and other special addresses.
170 };
171 
172 /*
173  // OVERLOAD THE ABOVE CLASS; make a subclass that does an address book lookup
174  // however is appropriate for your client.
175  //
176  class OTNameLookupIPhone : public OTNameLookup
177  {
178  public:
179  virtual std::string GetNymName(const std::string& str_id) const;
180  virtual std::string GetAcctName(const std::string& str_id) const;
181  virtual std::string GetAddressName(const std::string& str_id) const; //
182  Used for Bitmessage and other special addresses.
183  };
184  */
185 
186 // Client app makes an instance of its own subclass of OTNameLookup.
187 // Client app also makes an instance of OTLookupCaller (below.)
188 // Client app then gives the caller a pointer to the namelookup.
189 // Client app then passes the caller to OT via OT_API_Set_AddrBookCallback.
190 // OTRecord and OTRecordList then call the caller.
191 //
193 {
194 protected:
196 
197 public:
198  EXPORT OTLookupCaller()
199  : _callback(nullptr)
200  {
201  }
202  EXPORT ~OTLookupCaller();
203 
205  {
206  return _callback;
207  }
208  EXPORT void delCallback();
209  EXPORT void setCallback(OTNameLookup* cb);
210  EXPORT bool isCallbackSet() const;
211 
212  EXPORT std::string GetNymName(
213  const std::string& str_id, // NymID
214  const std::string* p_server_id = nullptr) const;
215 
216  EXPORT std::string GetAcctName(
217  const std::string& str_id, // AcctID
218  const std::string* p_nym_id = nullptr,
219  const std::string* p_server_id = nullptr,
220  const std::string* p_asset_id = nullptr) const;
221 
222  EXPORT std::string GetAddressName(const std::string& str_address) const;
223 };
224 
225 EXPORT bool OT_API_Set_AddrBookCallback(
226  OTLookupCaller& theCaller); // OTLookupCaller must have OTNameLookup
227  // attached already.
228 
229 typedef std::weak_ptr<OTRecord> weak_ptr_OTRecord;
230 typedef std::shared_ptr<OTRecord> shared_ptr_OTRecord;
231 
232 typedef std::vector<shared_ptr_OTRecord> vec_OTRecordList;
233 typedef std::list<std::string> list_of_strings;
234 typedef std::map<std::string, std::string> map_of_strings;
235 
237 {
238  const OTNameLookup* m_pLookup;
239  // Defaults to false. If you set it true, it will run a lot faster. (And
240  // give you less data.)
241  bool m_bRunFast;
242  bool m_bAutoAcceptCheques; // Cheques and vouchers, NOT invoices.
243  bool m_bAutoAcceptReceipts;
244  bool m_bAutoAcceptTransfers;
245  bool m_bAutoAcceptCash;
246  static std::string s_strTextTo; // "To: "
247  static std::string s_strTextFrom; // "From: "
248  list_of_strings m_servers;
249  map_of_strings m_assets; // <asset_type_id, asset_name>
250  list_of_strings m_accounts;
251  list_of_strings m_nyms;
252  vec_OTRecordList m_contents;
253  static const std::string s_blank;
254  static const std::string s_message_type;
255 
256 public: // ADDRESS BOOK CALLBACK
257  static bool setAddrBookCaller(OTLookupCaller& theCaller);
259 
260 protected: // ADDRESS BOOK CALLER
262 
263 public:
264  EXPORT OTRecordList(); // This one expects that s_pCaller is not nullptr.
265  EXPORT OTRecordList(const OTNameLookup& theLookup);
266  EXPORT ~OTRecordList();
267  EXPORT static const char* textTo()
268  {
269  return s_strTextTo.c_str();
270  }
271  EXPORT static const char* textFrom()
272  {
273  return s_strTextFrom.c_str();
274  }
275 
276  EXPORT static void setTextTo(std::string text)
277  {
278  s_strTextTo = text;
279  }
280  EXPORT static void setTextFrom(std::string text)
281  {
282  s_strTextFrom = text;
283  }
284  EXPORT void SetFastMode()
285  {
286  m_bRunFast = true;
287  }
288  // SETUP:
289 
290  EXPORT void SetServerID(std::string str_id); // Set the default server
291  // here.
292  EXPORT void AddServerID(std::string str_id); // Unless you have many
293  // servers, then use
294  // this.
295  EXPORT void ClearServers(); // Also clears m_contents
296 
297  EXPORT void SetAssetID(std::string str_id); // Etc.
298  EXPORT void AddAssetID(std::string str_id);
299  EXPORT void ClearAssets(); // Also clears m_contents
300 
301  EXPORT void SetNymID(std::string str_id);
302  EXPORT void AddNymID(std::string str_id);
303  EXPORT void ClearNyms(); // Also clears m_contents
304 
305  EXPORT void SetAccountID(std::string str_id);
306  EXPORT void AddAccountID(std::string str_id);
307  EXPORT void ClearAccounts(); // Also clears m_contents
308 
309  EXPORT const list_of_strings& GetNyms() const;
310  EXPORT void AcceptChequesAutomatically(bool bVal = true);
311  EXPORT void AcceptReceiptsAutomatically(bool bVal = true);
312  EXPORT void AcceptTransfersAutomatically(bool bVal = true);
313  EXPORT void AcceptCashAutomatically(bool bVal = true);
314 
315  EXPORT bool DoesAcceptChequesAutomatically() const;
316  EXPORT bool DoesAcceptReceiptsAutomatically() const;
317  EXPORT bool DoesAcceptTransfersAutomatically() const;
318  EXPORT bool DoesAcceptCashAutomatically() const;
319 
320  EXPORT bool PerformAutoAccept(); // Before populating, process out any items
321  // we're supposed to accept automatically.
322  // POPULATE:
323 
324  EXPORT bool Populate(); // Populates m_contents from OT API. Calls
325  // ClearContents().
326  EXPORT void ClearContents(); // Clears m_contents (NOT nyms, accounts,
327  // servers, or asset types.)
328  EXPORT void SortRecords(); // Populate already sorts. But if you have to add
329  // some external records after Populate, then you
330  // can sort again. P.S. sorting is performed
331  // based on the "from" date.
332 
333  // Let's say you also want to add some Bitmessages. (Or any other external
334  // source.) This is where you do that. Make sure to call Populate, then use
335  // AddSpecialMsg a few times, then call SortRecords.
336  EXPORT void AddSpecialMsg(
337  const std::string& str_msg_id, // The ID of this message, from whatever
338  // system it came from.
339  bool bIsOutgoing, int32_t nMethodID,
340  const std::string& str_contents, // Make sure to concatentate subject
341  // with contents, before passing here.
342  const std::string& str_address, const std::string& str_other_address,
343  const std::string& str_type, const std::string& str_type_display,
344  std::string str_my_nym_id = "", time64_t tDate = OT_TIME_ZERO);
345  // RETRIEVE:
346  //
347  EXPORT int32_t size() const;
348  EXPORT std::shared_ptr<OTRecord> GetRecord(int32_t nIndex);
349  EXPORT bool RemoveRecord(int32_t nIndex);
350 };
351 
352 } // namespace opentxs
353 
354 #endif // OPENTXS_CLIENT_OTRECORDLIST_HPP
EXPORT bool DoesAcceptReceiptsAutomatically() const
virtual EXPORT ~OTNameLookup()
EXPORT void SetServerID(std::string str_id)
static OTLookupCaller * s_pCaller
static bool setAddrBookCaller(OTLookupCaller &theCaller)
EXPORT void AddSpecialMsg(const std::string &str_msg_id, bool bIsOutgoing, int32_t nMethodID, const std::string &str_contents, const std::string &str_address, const std::string &str_other_address, const std::string &str_type, const std::string &str_type_display, std::string str_my_nym_id="", time64_t tDate=OT_TIME_ZERO)
EXPORT bool RemoveRecord(int32_t nIndex)
std::weak_ptr< OTRecord > weak_ptr_OTRecord
std::vector< shared_ptr_OTRecord > vec_OTRecordList
std::list< std::string > list_of_strings
EXPORT void AddAssetID(std::string str_id)
EXPORT std::string GetAddressName(const std::string &str_address) const
static EXPORT void setTextTo(std::string text)
EXPORT void SetNymID(std::string str_id)
int64_t time64_t
Definition: Common.hpp:209
virtual EXPORT std::string GetAcctName(const std::string &str_id, const std::string *p_nym_id=nullptr, const std::string *p_server_id=nullptr, const std::string *p_asset_id=nullptr) const
EXPORT bool DoesAcceptCashAutomatically() const
EXPORT void ClearAssets()
EXPORT bool DoesAcceptChequesAutomatically() const
EXPORT void ClearContents()
EXPORT void SetAssetID(std::string str_id)
virtual EXPORT std::string GetAddressName(const std::string &str_address) const
EXPORT void AcceptReceiptsAutomatically(bool bVal=true)
EXPORT const list_of_strings & GetNyms() const
EXPORT void setCallback(OTNameLookup *cb)
EXPORT void SetAccountID(std::string str_id)
EXPORT void ClearServers()
virtual EXPORT std::string GetNymName(const std::string &str_id, const std::string *p_server_id=nullptr) const
EXPORT void AcceptTransfersAutomatically(bool bVal=true)
EXPORT void AddServerID(std::string str_id)
EXPORT void ClearNyms()
EXPORT std::shared_ptr< OTRecord > GetRecord(int32_t nIndex)
EXPORT void ClearAccounts()
EXPORT OTNameLookup * getCallback()
EXPORT std::string GetNymName(const std::string &str_id, const std::string *p_server_id=nullptr) const
OTNameLookup * _callback
EXPORT void AcceptChequesAutomatically(bool bVal=true)
static EXPORT const char * textFrom()
static EXPORT void setTextFrom(std::string text)
EXPORT void AddAccountID(std::string str_id)
EXPORT std::string GetAcctName(const std::string &str_id, const std::string *p_nym_id=nullptr, const std::string *p_server_id=nullptr, const std::string *p_asset_id=nullptr) const
std::map< std::string, std::string > map_of_strings
std::shared_ptr< OTRecord > shared_ptr_OTRecord
EXPORT void AcceptCashAutomatically(bool bVal=true)
EXPORT int32_t size() const
EXPORT bool DoesAcceptTransfersAutomatically() const
#define OT_TIME_ZERO
Definition: Common.hpp:180
static OTLookupCaller * getAddrBookCaller()
static EXPORT const char * textTo()
EXPORT bool PerformAutoAccept()
EXPORT bool isCallbackSet() const
EXPORT void SetFastMode()
EXPORT bool OT_API_Set_AddrBookCallback(OTLookupCaller &theCaller)
EXPORT void AddNymID(std::string str_id)
EXPORT void SortRecords()