Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTStorage.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTStorage.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_OTSTORAGE_HPP
134 #define OPENTXS_CORE_OTSTORAGE_HPP
135 
136 // we now include this file in swig
137 // we need to tell swig what parts to skip over.
138 
139 #ifndef SWIG
140 
141 #include "util/Assert.hpp"
142 
143 // credit:stlplus library.
144 #include "containers/simple_ptr.hpp"
145 
146 #include <deque>
147 #include <iostream>
148 #include <vector>
149 #include <map>
150 #include <string>
151 #include <cstdint>
152 
153 // Which storage mechanism are we building?
154 // (Option is for both...)
155 //
156 
157 //#ifndef _WIN32 // Until I get it working on Windows.
161 //#endif
162 
163 #define OTDB_PROTOCOL_BUFFERS 1
164 //#define OTDB_JSON_PACKING 1 // coming soon.
165 
166 //#define OTDB_DEFAULT_PACKER OTDB::PACK_MESSAGE_PACK
167 #define OTDB_DEFAULT_PACKER OTDB::PACK_PROTOCOL_BUFFERS
168 
169 #define OTDB_DEFAULT_STORAGE OTDB::STORE_FILESYSTEM
170 
171 // JAVA-STYLE INTERFACES.
172 //
173 // I'm doing some crazy stuff in this file.
174 // What you see below is a set of preprocessor definitions that
175 // allow me to use "Java-Style Interfaces" here in C++.
176 //
177 // It turns out that Storable needed a normal class hierarchy, AND Java-
178 // style interfaces, to do everything I wanted it to do.
179 //
180 // I will probably create a more general-purpose header file for OT
181 // and these sorts of #defines will probably end up there int64_t-term.
182 // Much of OT might be separable out into a more general-purpose utility
183 // lib, which I will get to whenever it is more important than anything else.
184 //
185 #define OTInterface class
186 
187 #define DeclareInterface(name) \
188  OTInterface name \
189  { \
190  public: \
191  virtual ~name() \
192  { \
193  }
194 
195 #define DeclareBasedInterface(name, base) \
196  class name : public base \
197  { \
198  public: \
199  virtual ~name() \
200  { \
201  }
202 
203 #define EndInterface \
204  } \
205  ;
206 
207 #define implements public
208 
209 #endif // (not) SWIG
210 
211 namespace opentxs
212 {
213 
214 namespace OTDB
215 {
216 
217 // ENUMS: PackType, StorageType, and StoredObjectType.
218 
219 // Currently supporting MsgPack and Protocol Buffers.
220 //
221 enum PackType // PACKING TYPE
222 { PACK_MESSAGE_PACK = 0, // Using MessagePack as packer.
223  PACK_PROTOCOL_BUFFERS, // Using Google Protocol Buffers as packer.
224  PACK_TYPE_ERROR // (Should never be.)
225 };
226 
227 // Currently supporting filesystem, with subclasses possible via API.
228 //
229 enum StorageType // STORAGE TYPE
230 { STORE_FILESYSTEM = 0, // Filesystem
231  // STORE_COUCH_DB, // Couch DB (not yet supported)
232  STORE_TYPE_SUBCLASS // (Subclass provided by API client via SWIG.)
233 };
234 
235 #ifndef SWIG
236 //
237 // STORED OBJECT TYPES...
238 //
239 extern const char* StoredObjectTypeStrings[];
240 #endif // (not) SWIG
241 
243  STORED_OBJ_STRING = 0, // Just a string.
244  STORED_OBJ_BLOB, // Used for storing binary data. Bytes of arbitrary length.
245  STORED_OBJ_STRING_MAP, // A StringMap is a list of Key/Value pairs, useful
246  // for storing nearly anything.
247  STORED_OBJ_WALLET_DATA, // The GUI wallet's stored data
248  STORED_OBJ_BITCOIN_ACCT, // The GUI wallet's stored data about a Bitcoin
249  // acct
250  STORED_OBJ_BITCOIN_SERVER, // The GUI wallet's stored data about a Bitcoin
251  // RPC port.
252  STORED_OBJ_RIPPLE_SERVER, // The GUI wallet's stored data about a Ripple
253  // server.
254  STORED_OBJ_LOOM_SERVER, // The GUI wallet's stored data about a Loom server.
255  STORED_OBJ_SERVER_INFO, // A Nym has a list of these.
256  STORED_OBJ_CONTACT_NYM, // This is a Nym record inside a contact of your
257  // address book.
258  STORED_OBJ_CONTACT_ACCT, // This is an account record inside a contact of
259  // your address book.
260  STORED_OBJ_CONTACT, // Your address book has a list of these.
261  STORED_OBJ_ADDRESS_BOOK, // Your address book.
262  STORED_OBJ_MARKET_DATA, // The description data for any given Market ID.
263  STORED_OBJ_MARKET_LIST, // A list of MarketDatas.
264  STORED_OBJ_BID_DATA, // Offer details (doesn't contain private details)
265  STORED_OBJ_ASK_DATA, // Offer details (doesn't contain private details)
266  STORED_OBJ_OFFER_LIST_MARKET, // A list of offer details, for a specific
267  // market.
268  STORED_OBJ_TRADE_DATA_MARKET, // Trade details (doesn't contain private
269  // data)
270  STORED_OBJ_TRADE_LIST_MARKET, // A list of trade details, for a specific
271  // market.
272  STORED_OBJ_OFFER_DATA_NYM, // Private offer details for a particular Nym and
273  // Offer.
274  STORED_OBJ_OFFER_LIST_NYM, // A list of private offer details for a
275  // particular Nym.
276  STORED_OBJ_TRADE_DATA_NYM, // Private trade details for a particular Nym and
277  // Trade.
278  STORED_OBJ_TRADE_LIST_NYM, // A list of private trade details for a
279  // particular Nym and Offer.
280  STORED_OBJ_ERROR // (Should never be.)
281 };
282 
283 #ifndef SWIG
284 
285 // ABSTRACT BASE CLASSES
286 //
287 class Storable; // A storable object
288 class OTPacker; // A packer (Could be MsgPack, or Google Protocol Buffers, or a
289  // json lib...)
290 class Storage; // A storage context (database, filesystem, cloud, etc.
291  // Swappable.)
292 class PackedBuffer; // A buffer for containing a PACKED STORABLE. (On its way
293  // to/from storage.)
294 
295 // OTDB NAMESPACE "CONSTRUCTOR"
296 //
298 {
299 public:
300  InitOTDBDetails(); // See implementation of this in CPP file for namespace
301  // construction.
302  ~InitOTDBDetails(); // Ditto.
303 };
304 
305 // As far as the USERS of the Storage API are concerned, the above classes are
306 // nearly everything.
307 // (In addition to the "Pure Data" classes such as ContactNym, BitcoinAcct,
308 // etc.)
309 // Behind the scenes, in OTStorage, there is the IStorable interface, with its
310 // progeny, the various
311 // subclasses based on specific packers, such as ContactNymMsgpack, or
312 // WalletDataProtobuf. But these
313 // are hidden, and are not seen outside of OTStorage in its actual USE.
314 
315 //
316 // OTDB Namespace internal typedefs
317 //
318 // In short:
319 // - InstantiateFunc (function pointer type.)
320 // - InstantiateFuncKey (based on Pack Type and Stored Object Type.)
321 // - mapOfFunctions (type: map of InstantiateFuncs, indexed by
322 // InstantiateFuncKeys.)
323 //
324 // Resulting in: pFunctionMap (Instance of mapOfFunctions, created in the OTDB
325 // constructor.)
326 //
327 typedef Storable*(InstantiateFunc)(); // Each storable has one of these as a
328  // static method.
329 typedef std::pair<PackType, StoredObjectType> InstantiateFuncKey; // Those
330  // methods are
331  // stored as
332  // function
333  // pointers
334  // here, and
335  // they are
336 // indexed by Pack Type and Stored Object Type. So if you know "LoomAcct" and
337 // "protocol buffers", those form the KEY for looking up the LoomAcctPB
338 // instantiator.
339 typedef std::map<InstantiateFuncKey, InstantiateFunc*>
340  mapOfFunctions; //...basically implementing my own vtable, eh?
341 
342 // OTDB Namespace PRIVATE MEMBERS
343 // this "details" naming is a common C++ idiom for "private" in a namespace.
344 //
345 namespace details
346 {
347 extern OTDB::Storage* s_pStorage;
348 
349 extern OTDB::mapOfFunctions* pFunctionMap; // This is a pointer so I can control
350  // what order it is created in, on
351  // startup.
352 }
353 
354 // All of the class hierarchy under Storable is based on OT data design. (Not
355 // packing and such implementation details.)
356 // So when we need to add custom behavior that's common to groups of the final
357 // subclasses,
358 // we use **Interfaces** to do it.
359 
360 // ===> That way, the Storable hierarchy can focus on DATA, (and form the
361 // external interface for OTStorage.)
362 // ===> while the IStorable hierarchy focuses on PACKING. (and is hidden
363 // INSIDE OTStorage.)
364 // ===> (Things are more elegant this way.)
365 
366 //
367 //
368 // Interface: IStorable
369 //
370 // Each specific Packer library (MsgPack, Protobuf, etc) must provide an
371 // interface
372 // derived from IStorable (They're all listed somewhere below.)
373 //
374 DeclareInterface(IStorable) virtual bool onPack(
375  PackedBuffer& theBuffer,
376  Storable& inObj) = 0; // buffer is output, inObj is input.
377 virtual bool onUnpack(PackedBuffer& theBuffer,
378  Storable& outObj) = 0; // buffer is input, outObj is
379  // output.
380 virtual void hookBeforePack()
381 {
382 } // This is called just before packing a storable. (Opportunity to copy
383  // values...)
384 virtual void hookAfterUnpack()
385 {
386 } // This is called just after unpacking a storable. (Opportunity to copy
387  // values...)
389 
390 #endif // (not) SWIG
391 
392 //
393 // use this without a semicolon:
394 //
395 
396 #ifdef SWIG // swig version
397 #define DEFINE_OT_DYNAMIC_CAST(CLASS_NAME_A) \
398  CLASS_NAME_A* clone() const \
399  { \
400  std::cerr \
401  << "********* THIS SHOULD NEVER HAPPEN!!!!! *****************" \
402  << std::endl; \
403  return nullptr; \
404  } \
405  static CLASS_NAME_A* ot_dynamic_cast(Storable* pObject) \
406  { \
407  return dynamic_cast<CLASS_NAME_A*>(pObject); \
408  }
409 // static const CLASS_NAME_A* ot_dynamic_cast(const Storable *pObject)
410 // { return dynamic_cast<const CLASS_NAME_A *>(pObject); }
411 #endif // SWIG
412 
413 #ifndef SWIG // normal version
414 #define DEFINE_OT_DYNAMIC_CAST(CLASS_NAME) \
415  virtual CLASS_NAME* clone() const \
416  { \
417  std::cout \
418  << "********* THIS SHOULD NEVER HAPPEN!!!!! *****************" \
419  << std::endl; \
420  OT_FAIL; \
421  } \
422  static CLASS_NAME* ot_dynamic_cast(Storable* pObject) \
423  { \
424  return dynamic_cast<CLASS_NAME*>(pObject); \
425  }
426 #endif // (not) SWIG
427 
428  // static const CLASS_NAME * ot_dynamic_cast( Storable // *pObject)
429  // { return dynamic_cast<const T *>(pObject); }
430 
431  //
432  // STORABLE
433  //
434  // Abstract base class for OT serializable object types.
435  //
436  class Storable
437 {
438  friend class Storage; // for instantiation of storable objects by their
439  // storage context.
440 
441 protected:
443  : m_Type("Storable")
444  {
445  }
446 
447  std::string m_Type;
448 
449 public:
450  virtual ~Storable()
451  {
452  }
453 
454  // %ignore spam(uint16_t); API users don't need this function, it's for
455  // internal purposes.
456  EXPORT static Storable* Create(StoredObjectType eType,
457  PackType thePackType);
458 
460 };
461 
462 #ifndef SWIG
463 
464 // PACKED BUFFER (for storing PACKED DATA)
465 //
466 // %ignore these classes (I think)
467 //
468 
470 {
471 protected:
473  {
474  } // Only subclasses of this should be instantiated.
475 public:
476  virtual ~PackedBuffer()
477  {
478  }
479 
480  virtual bool PackString(std::string& theString) = 0;
481  virtual bool UnpackString(std::string& theString) = 0;
482 
483  virtual bool ReadFromIStream(std::istream& inStream, int64_t lFilesize) = 0;
484  virtual bool WriteToOStream(std::ostream& outStream) = 0;
485 
486  virtual const uint8_t* GetData() = 0;
487  virtual size_t GetSize() = 0;
488 
489  virtual void SetData(const uint8_t* pData, size_t theSize) = 0;
490 };
491 
492 //
493 // SUBCLASSES (the actual declarations are at the bottom of this file.)
494 //
495 // typedef PackedBufferSubclass<PackerMsgpack, IStorableMsgpack,
496 // msgpack::sbuffer> BufferMsgpack;
497 // typedef PackedBufferSubclass<PackerPB, IStorablePB,
498 // std::string> BufferPB;
499 //
500 // Coming soon:
501 // typedef PackedBufferSubclass<PackerJSON, IStorableJSON,
502 // std::string> BufferJSON;
503 //
504 // They're all based on this template:
505 //
506 #define DECLARE_PACKED_BUFFER_SUBCLASS(theNewType, thePackerType, \
507  theInterfaceType, theInternalType) \
508  class theNewType : public PackedBuffer \
509  { \
510  friend class thePackerType; \
511  friend OTInterface theInterfaceType; \
512  theInternalType m_buffer; \
513  \
514  public: \
515  theNewType() \
516  : PackedBuffer() \
517  { \
518  } \
519  virtual ~theNewType() \
520  { \
521  } \
522  virtual bool PackString(std::string& theString); \
523  virtual bool UnpackString(std::string& theString); \
524  virtual bool ReadFromIStream(std::istream& inStream, \
525  int64_t lFilesize); \
526  virtual bool WriteToOStream(std::ostream& outStream); \
527  virtual const uint8_t* GetData(); \
528  virtual size_t GetSize(); \
529  virtual void SetData(const uint8_t* pData, size_t theSize); \
530  theInternalType& GetBuffer() \
531  { \
532  return m_buffer; \
533  } \
534  }
535 
536 // PACKER (now OTPacker since MsgPack also has a "Packer" in a #define).
537 //
538 // abstract base class for a packer
539 //
540 
541 // %ignore spam(uint16_t); (probably for all packers.)
542 class OTPacker
543 {
544 protected:
546  {
547  } // To instantiate: OTPacker * pPacker =
548  // OTPacker::Create(OTDB_DEFAULT_PACKER);
549 
550 public:
551  virtual ~OTPacker()
552  {
553  }
554 
555  static OTPacker* Create(PackType ePackType); // Factory.
556 
557  PackType GetType() const;
558 
560  EXPORT bool Unpack(PackedBuffer& inBuf, Storable& outObj);
561 
562  PackedBuffer* Pack(std::string& inObj);
563  bool Unpack(PackedBuffer& inBuf, std::string& outObj);
564 
565  virtual PackedBuffer* CreateBuffer() = 0;
566 };
567 
568 // For declaring subclasses of OTPacker.
569 
570 template <class theBufferType>
571 class PackerSubclass : public OTPacker
572 {
573 public:
575  : OTPacker()
576  {
577  }
578  virtual ~PackerSubclass()
579  {
580  }
581 
583  {
584  return new theBufferType;
585  }
586 
587  // You don't see onPack and onUnpack here because they are on IStorable.
588 };
589 
590 // To use:
591 // typedef PackerSubclass<theBufferType> theType;
592 //
593 
594 // SUBCLASSES:
595 //
596 // (Actual declarations are at the bottom of the file.)
597 //
598 // typedef PackerSubclass<BufferMsgpack> PackerMsgpack;
599 // typedef PackerSubclass<BufferPB> PackerPB;
600 //
601 // Coming soon:
602 // typedef PackerSubclass<BufferJSON> PackerJSON;
603 //
604 
605 #endif
606 //
607 // STORAGE -- abstract base class
608 //
609 //
610 class Storage
611 {
612 private:
613  OTPacker* m_pPacker;
614 
615 protected:
617  : m_pPacker(nullptr)
618  {
619  }
620 
621  Storage(const Storage&)
622  : m_pPacker(nullptr)
623  {
624  } // We don't want to copy the pointer. Let it create its own.
625 
626  // This is called once, in the factory.
627  void SetPacker(OTPacker& thePacker)
628  {
629  OT_ASSERT(nullptr == m_pPacker);
630  m_pPacker = &thePacker;
631  }
632 
633  // OVERRIDABLES
634  //
635  // If you wish to MAKE YOUR OWN subclass of Storage (to provide your own
636  // storage system)
637  // then just subclass OTDB::Storage, and override the below methods. For an
638  // example of how
639  // it's done, see StorageFS (filesystem), which is included below and in
640  // OTStorage.cpp.
641  //
642  // NOTE: This should be possible even in other languages! I'm using SWIG
643  // directors, meaning
644  // that you can make a Java subclass of OTDB::Storage, or a Python subclass,
645  // etc. This isn't
646  // possible with the other classes in OTStorage (yet), which must be
647  // subclassed in C++. But
648  // for this class, it is.
649  //
650  virtual bool onStorePackedBuffer(PackedBuffer& theBuffer,
651  std::string strFolder,
652  std::string oneStr = "",
653  std::string twoStr = "",
654  std::string threeStr = "") = 0;
655 
656  virtual bool onQueryPackedBuffer(PackedBuffer& theBuffer,
657  std::string strFolder,
658  std::string oneStr = "",
659  std::string twoStr = "",
660  std::string threeStr = "") = 0;
661 
662  virtual bool onStorePlainString(std::string& theBuffer,
663  std::string strFolder,
664  std::string oneStr = "",
665  std::string twoStr = "",
666  std::string threeStr = "") = 0;
667 
668  virtual bool onQueryPlainString(std::string& theBuffer,
669  std::string strFolder,
670  std::string oneStr = "",
671  std::string twoStr = "",
672  std::string threeStr = "") = 0;
673 
674  virtual bool onEraseValueByKey(std::string strFolder,
675  std::string oneStr = "",
676  std::string twoStr = "",
677  std::string threeStr = "") = 0;
678 
679 public:
680  // Use GetPacker() to access the Packer, throughout duration of this Storage
681  // object.
682  // If it doesn't exist yet, this function will create it on the first call.
683  // (The
684  // parameter allows you the choose what type will be created, other than
685  // default.)
686  //
687  // This way, whenever using an OT Storage, you KNOW the packer is always the
688  // right
689  // one, and that you don't have to fiddle with it at all. You can also
690  // therefore use
691  // it for creating instances of various Storables and PackedBuffers, and
692  // knowing
693  // that the right types will be instantiated automatically, with the buffer
694  // being
695  // the appropriate subclass for the packer.
696  //
697  EXPORT OTPacker* GetPacker(PackType ePackType = OTDB_DEFAULT_PACKER);
698 
699  // virtual bool Init(std::string oneStr="", std::string twoStr="",
700  // std::string threeStr="",
701  // std::string fourStr="", std::string fiveStr="",
702  // std::string sixStr="")=0;
703 
704  // See if the file is there.
705  virtual bool Exists(std::string strFolder, std::string oneStr = "",
706  std::string twoStr = "", std::string threeStr = "") = 0;
707 
708  virtual int64_t FormPathString(std::string& strOutput,
709  std::string strFolder,
710  std::string oneStr = "",
711  std::string twoStr = "",
712  std::string threeStr = "") = 0;
713 
714  virtual ~Storage()
715  {
716  if (nullptr != m_pPacker) delete m_pPacker;
717  m_pPacker = nullptr;
718  }
719 
720  // Store/Retrieve a string.
721 
722  EXPORT bool StoreString(std::string strContents, std::string strFolder,
723  std::string oneStr = "", std::string twoStr = "",
724  std::string threeStr = "");
725 
726  EXPORT std::string QueryString(std::string strFolder,
727  std::string oneStr = "",
728  std::string twoStr = "",
729  std::string threeStr = "");
730 
731  EXPORT bool StorePlainString(std::string strContents, std::string strFolder,
732  std::string oneStr = "",
733  std::string twoStr = "",
734  std::string threeStr = "");
735 
736  EXPORT std::string QueryPlainString(std::string strFolder,
737  std::string oneStr = "",
738  std::string twoStr = "",
739  std::string threeStr = "");
740 
741  // Store/Retrieve an object. (Storable.)
742 
743  EXPORT bool StoreObject(Storable& theContents, std::string strFolder,
744  std::string oneStr = "", std::string twoStr = "",
745  std::string threeStr = "");
746 
747  // Use %newobject OTDB::Storage::QueryObject();
748  EXPORT Storable* QueryObject(StoredObjectType theObjectType,
749  std::string strFolder, std::string oneStr = "",
750  std::string twoStr = "",
751  std::string threeStr = "");
752  // Store/Retrieve a Storable object inside an OTASCIIArmor object.
753 
754  EXPORT std::string EncodeObject(Storable& theContents);
755 
756  // Use %newobject OTDB::Storage::DecodeObject();
757  EXPORT Storable* DecodeObject(StoredObjectType theObjectType,
758  std::string strInput);
759 
760  // Erase any value based on its location.
761 
762  EXPORT bool EraseValueByKey(std::string strFolder, std::string oneStr = "",
763  std::string twoStr = "",
764  std::string threeStr = "");
765 
766  // Note:
767  // Make sure to use: %newobject Factory::createObj(); IN OTAPI.i file!
768  //
769  // That way, Java garbage cleanup will handle object after this.
770  // (Instead of leaking because it thinks C++ will clean it up.)
771  //
772  // Factory for Storable objects. %newobject Factory::createObj();
773  EXPORT Storable* CreateObject(StoredObjectType eType);
774 
775  // Factory for Storage itself. %ignore this in OTAPI.i (It's accessed
776  // through
777  // a namespace-level function, whereas this is for internal purposes.)
778  //
779  EXPORT static Storage* Create(StorageType eStorageType,
780  PackType ePackType); // FACTORY
781 
782  EXPORT StorageType GetType() const;
783 };
784 
785 //
786 // OTDB Namespace PUBLIC INTERFACE
787 //
788 //
789 
790 EXPORT bool InitDefaultStorage(StorageType eStoreType, PackType ePackType);
791 
792 // Default Storage instance:
793 EXPORT Storage* GetDefaultStorage();
794 
795 // %newobject Factory::createObj();
796 EXPORT Storage* CreateStorageContext(StorageType eStoreType,
797  PackType ePackType = OTDB_DEFAULT_PACKER);
798 
799 EXPORT Storable* CreateObject(StoredObjectType eType);
800 
801 // bool bSuccess = OTDB::StoreString(strInbox, "inbox", "lkjsdf908w345ljkvd");
802 // bool bSuccess = OTDB::StoreString(strMint, "mints", SERVER_ID, ASSET_ID);
803 // bool bSuccess = OTDB::StoreString(strPurse, "purse", SERVER_ID, USER_ID,
804 // ASSET_ID);
805 
806 // BELOW FUNCTIONS use the DEFAULT Storage context for the OTDB Namespace
807 
808 // Check if the values are good.
809 //
810 EXPORT bool CheckStringsExistInOrder(std::string& strFolder,
811  std::string& oneStr, std::string& twoStr,
812  std::string& threeStr,
813  const char* szFuncName = nullptr);
814 
815 // See if the file is there.
816 //
817 EXPORT bool Exists(std::string strFolder, std::string oneStr = "",
818  std::string twoStr = "", std::string threeStr = "");
819 
820 EXPORT int64_t FormPathString(std::string& strOutput, std::string strFolder,
821  std::string oneStr = "", std::string twoStr = "",
822  std::string threeStr = "");
823 // Store/Retrieve a string.
824 //
825 EXPORT bool StoreString(std::string strContents, std::string strFolder,
826  std::string oneStr = "", std::string twoStr = "",
827  std::string threeStr = "");
828 
829 EXPORT std::string QueryString(std::string strFolder, std::string oneStr = "",
830  std::string twoStr = "",
831  std::string threeStr = "");
832 
833 EXPORT bool StorePlainString(std::string strContents, std::string strFolder,
834  std::string oneStr = "", std::string twoStr = "",
835  std::string threeStr = "");
836 
837 EXPORT std::string QueryPlainString(std::string strFolder,
838  std::string oneStr = "",
839  std::string twoStr = "",
840  std::string threeStr = "");
841 
842 // Store/Retrieve an object. (Storable.)
843 //
844 EXPORT bool StoreObject(Storable& theContents, std::string strFolder,
845  std::string oneStr = "", std::string twoStr = "",
846  std::string threeStr = "");
847 
848 // Use %newobject OTDB::Storage::Query();
849 EXPORT Storable* QueryObject(StoredObjectType theObjectType,
850  std::string strFolder, std::string oneStr = "",
851  std::string twoStr = "",
852  std::string threeStr = "");
853 // Store/Retrieve a Storable object inside an OTASCIIArmor object.
854 
855 EXPORT std::string EncodeObject(Storable& theContents);
856 
857 // Use %newobject OTDB::Storage::DecodeObject();
858 EXPORT Storable* DecodeObject(StoredObjectType theObjectType,
859  std::string strInput);
860 
861 // Erase any value based on its location.
862 
863 EXPORT bool EraseValueByKey(std::string strFolder, std::string oneStr = "",
864  std::string twoStr = "", std::string threeStr = "");
865 
866 /*
867 typedef template<class T>
868 T * OT_DYNAMIC_CAST(Storable* pObject)
869 {
870  return dynamic_cast<T *>(pObject);
871 }
872 template<class T>
873 const T * OT_DYNAMIC_CONST_CAST(const Storable* pObject)
874 {
875  return dynamic_cast<const T *>(pObject);
876 }
877 */
878 
879 #ifdef SWIG // swig version
880 #define DECLARE_GET_ADD_REMOVE(name) \
881 protected: \
882  std::deque<stlplus::simple_ptr_clone<name>> list_##name##s; \
883  \
884 public: \
885  size_t Get##name##Count(); \
886  name* Get##name(size_t nIndex); \
887  bool Remove##name(size_t nIndex##name); \
888  bool Add##name(name& disownObject)
889 
890 #endif // SWIG
891 #ifndef SWIG
892 
893 #define DECLARE_GET_ADD_REMOVE(name) \
894 protected: \
895  std::deque<stlplus::simple_ptr_clone<name>> list_##name##s; \
896  \
897 public: \
898  EXPORT size_t Get##name##Count(); \
899  EXPORT name* Get##name(size_t nIndex); \
900  EXPORT bool Remove##name(size_t nIndex##name); \
901  EXPORT bool Add##name(name& disownObject)
902 #endif // (not) SWIG
903 
904 // Serialized types...
905 //
906 // Here the entire hierarchy focuses on the OT data itself.
907 // Later, subclasses are made providing the final implementation,
908 // based on the packer type. (Same for buffers.)
909 
910 class OTDBString : public Storable
911 {
912  // You never actually get an instance of this, only its subclasses.
913  // Therefore, I don't allow you to access the constructor except through the
914  // factory.
915 protected:
917  : Storable()
918  {
919  m_Type = "OTDBString";
920  }
921  OTDBString(const std::string& rhs)
922  : Storable()
923  , m_string(rhs)
924  {
925  m_Type = "OTDBString";
926  } // This is an abstract base class...so will this call ever actually
927  // happen?
928 
929 public:
930  virtual ~OTDBString()
931  {
932  }
933 
934  std::string m_string;
935 
937 };
938 
939 class Blob : public Storable
940 {
941  // You never actually get an instance of this, only its subclasses.
942  // Therefore, I don't allow you to access the constructor except through the
943  // factory.
944 protected:
946  : Storable()
947  {
948  m_Type = "Blob";
949  }
950 
951 public:
952  virtual ~Blob()
953  {
954  }
955 
956  std::vector<uint8_t> m_memBuffer; // Where the actual binary data is stored,
957  // before packing.
958 
960 };
961 
962 // The most useful generic data object... a map of strings, key/value pairs.
963 //
964 class StringMap : public Storable
965 {
966  // You never actually get an instance of this, only its subclasses.
967  // Therefore, I don't allow you to access the constructor except through the
968  // factory.
969 protected:
971  : Storable()
972  {
973  m_Type = "StringMap";
974  }
975 
976 public:
977  virtual ~StringMap()
978  {
979  }
980 
981  std::map<std::string, std::string> the_map; // all strings, key/value pairs.
982 
983  void SetValue(const std::string& strKey, const std::string& strValue)
984  {
985  std::map<std::string, std::string>::iterator ii = the_map.find(strKey);
986  if (ii != the_map.end()) the_map.erase(ii);
987  the_map[strKey] = strValue;
988  }
989 
990  std::string GetValue(const std::string& strKey)
991  {
992  std::string ret_val("");
993  std::map<std::string, std::string>::iterator ii = the_map.find(strKey);
994  if (ii != the_map.end()) ret_val = (*ii).second;
995  return ret_val;
996  }
997 
999 };
1000 
1001 class Displayable : public Storable
1002 {
1003  // You never actually get an instance of this, only its subclasses.
1004  // Therefore, I don't allow you to access the constructor except through the
1005  // factory.
1006 protected:
1008  : Storable()
1009  {
1010  m_Type = "Displayable";
1011  }
1012 
1013 public:
1014  virtual ~Displayable()
1015  {
1016  }
1017 
1018  std::string gui_label; // The label that appears in the GUI
1019 
1021 };
1022 
1023 class MarketData : public Displayable
1024 {
1025  // You never actually get an instance of this, only its subclasses.
1026  // Therefore, I don't allow you to access the constructor except through
1027  // factory.
1028 protected:
1030  : Displayable()
1031  , scale("0")
1032  , total_assets("0")
1033  , number_bids("0")
1034  , last_sale_price("0")
1035  , current_bid("0")
1036  , current_ask("0")
1037  , volume_trades("0")
1038  , volume_assets("0")
1039  , volume_currency("0")
1040  , recent_highest_bid("0")
1041  , recent_lowest_ask("0")
1042  , last_sale_date("0")
1043  {
1044  m_Type = "MarketData";
1045  }
1046 
1047 public:
1048  virtual ~MarketData()
1049  {
1050  }
1051 
1052  using Displayable::gui_label; // The label that appears in the GUI
1053 
1054  std::string server_id;
1055  std::string market_id;
1056 
1057  std::string asset_type_id;
1058  std::string currency_type_id;
1059 
1060  std::string scale; // the Market scale. (A trade in any particular asset is
1061  // measured in X units of SCALE.)
1062  // IOW, if the scale is 5000 on the gold market, that means "3 units" is
1063  // 15000 gold
1064 
1065  std::string total_assets; // total amount of assets available on market for
1066  // purchase.
1067 
1068  std::string number_bids; // number of bids that are currently on the market.
1069  std::string number_asks; // number of asks that are currently on the market.
1070 
1071  std::string last_sale_price; // The price at which the most recent trade
1072  // occurred on this market.
1073  std::string current_bid; // The highest bid currently on the market.
1074  std::string current_ask; // The lowest ask price currently available on the
1075  // market.
1076 
1077  std::string volume_trades; // 24-hour period, number of trades.
1078 
1079  std::string volume_assets; // 24-hour volume, amount of assets traded.
1080  std::string volume_currency; // 24-hour volume, amount of currency paid for
1081  // assets traded.
1082 
1083  std::string recent_highest_bid; // in a 24hour period, the highest bid to
1084  // hit the market.
1085  std::string recent_lowest_ask; // in a 24hour period, the lowest ask to hit
1086  // the market.
1087 
1088  std::string last_sale_date; // (NEW FIELD) The date on which the most recent
1089  // trade occurred on this market.
1090 
1092 };
1093 
1094 class MarketList : public Storable
1095 {
1096  // You never actually get an instance of this, only its subclasses.
1097  // Therefore, I don't allow you to access the constructor except through
1098  // factory.
1099 protected:
1101  : Storable()
1102  {
1103  m_Type = "MarketList";
1104  }
1105 
1106 public:
1107  virtual ~MarketList()
1108  {
1109  }
1110 
1112 
1114 };
1115 
1117 {
1118  // You never actually get an instance of this, only its subclasses.
1119  // Therefore, I don't allow you to access the constructor except through
1120  // factory.
1121 protected:
1123  : Displayable()
1124  , transaction_id("0")
1125  , price_per_scale("1")
1126  , available_assets("0")
1127  , minimum_increment("1")
1128  , date("0")
1129  {
1130  m_Type = "OfferDataMarket";
1131  }
1132 
1133 public:
1135  {
1136  }
1137 
1138  using Displayable::gui_label; // The label that appears in the GUI
1139 
1140  std::string transaction_id;
1141  std::string price_per_scale;
1142 
1143  // uint64_t total_assets;
1144  // uint64_t finished_so_far;
1145  std::string available_assets;
1146 
1147  // Each sale or purchase against (total_assets - finished_so_far) must be in
1148  // minimum increments.
1149  // Minimum Increment must be evenly divisible by scale.
1150  // (This effectively becomes a "FILL OR KILL" order if set to the same value
1151  // as total_assets. Also, MUST be 1
1152  // or greater. CANNOT be zero. Enforce this at class level. You cannot sell
1153  // something in minimum increments of 0.)
1154 
1155  std::string minimum_increment;
1156 
1157  std::string date; // (NEW FIELD) The date this offer was added to the
1158  // market.
1159 
1161 };
1162 
1163 class BidData : public OfferDataMarket
1164 {
1165  // You never actually get an instance of this, only its subclasses.
1166  // Therefore, I don't allow you to access the constructor except through
1167  // factory.
1168 protected:
1170  : OfferDataMarket()
1171  {
1172  m_Type = "BidData";
1173  }
1174 
1175 public:
1176  virtual ~BidData()
1177  {
1178  }
1179 
1180  using Displayable::gui_label; // The label that appears in the GUI
1181 
1186  using OfferDataMarket::date;
1187 
1189 };
1190 
1191 class AskData : public OfferDataMarket
1192 {
1193  // You never actually get an instance of this, only its subclasses.
1194  // Therefore, I don't allow you to access the constructor except through
1195  // factory.
1196 protected:
1198  : OfferDataMarket()
1199  {
1200  m_Type = "AskData";
1201  }
1202 
1203 public:
1204  virtual ~AskData()
1205  {
1206  }
1207 
1208  using Displayable::gui_label; // The label that appears in the GUI
1209 
1214  using OfferDataMarket::date;
1215 
1217 };
1218 
1220 {
1221  // You never actually get an instance of this, only its subclasses.
1222  // Therefore, I don't allow you to access the constructor except through
1223  // factory.
1224 protected:
1226  : Storable()
1227  {
1228  m_Type = "OfferListMarket";
1229  }
1230 
1231 public:
1233  {
1234  }
1235 
1238 
1240 };
1241 
1243 {
1244  // You never actually get an instance of this, only its subclasses.
1245  // Therefore, I don't allow you to access the constructor except through
1246  // factory.
1247 protected:
1249  : Displayable()
1250  , transaction_id("0")
1251  , date("0")
1252  , price("0")
1253  , amount_sold("0")
1254  {
1255  m_Type = "TradeDataMarket";
1256  }
1257 
1258 public:
1260  {
1261  }
1262 
1263  using Displayable::gui_label; // The label that appears in the GUI
1264 
1265  std::string transaction_id; // (transaction number for this trade.)
1266  std::string date; // (The date of this trade's execution)
1267  std::string price; // (The price this trade executed at.)
1268  std::string amount_sold; // (Amount of asset sold for that price.)
1269 
1271 };
1272 
1274 {
1275  // You never actually get an instance of this, only its subclasses.
1276  // Therefore, I don't allow you to access the constructor except through
1277  // factory.
1278 protected:
1280  : Storable()
1281  {
1282  m_Type = "TradeListMarket";
1283  }
1284 
1285 public:
1287  {
1288  }
1289 
1291 
1293 };
1294 
1296 {
1297  // You never actually get an instance of this, only its subclasses.
1298  // Therefore, I don't allow you to access the constructor except through
1299  // factory.
1300 protected:
1302  : Displayable()
1303  , valid_from("0")
1304  , valid_to("0")
1305  , selling(false)
1306  , scale("1")
1307  , price_per_scale("1")
1308  , transaction_id("0")
1309  , total_assets("1")
1310  , finished_so_far("0")
1311  , minimum_increment("1")
1312  , stop_price("0")
1313  , date("0")
1314  {
1315  m_Type = "OfferDataNym";
1316  }
1317 
1318 public:
1319  virtual ~OfferDataNym()
1320  {
1321  }
1322 
1323  using Displayable::gui_label; // The label that appears in the GUI
1324 
1325  std::string valid_from;
1326  std::string valid_to;
1327 
1328  std::string server_id;
1329  std::string asset_type_id; // the asset type on offer.
1330  std::string asset_acct_id; // the account where the asset is.
1331  std::string currency_type_id; // the currency being used to purchase the
1332  // asset.
1333  std::string currency_acct_id; // the account where currency is.
1334 
1335  bool selling; // true for ask, false for bid.
1336 
1337  std::string scale; // 1oz market? 100oz market? 10,000oz market? This
1338  // determines size and granularity.
1339  std::string price_per_scale;
1340 
1341  std::string transaction_id;
1342 
1343  std::string total_assets;
1344  std::string finished_so_far;
1345 
1346  // Each sale or purchase against (total_assets - finished_so_far) must be in
1347  // minimum increments.
1348  // Minimum Increment must be evenly divisible by scale.
1349  // (This effectively becomes a "FILL OR KILL" order if set to the same value
1350  // as total_assets. Also, MUST be 1
1351  // or greater. CANNOT be zero. Enforce this at class level. You cannot sell
1352  // something in minimum increments of 0.)
1353 
1354  std::string minimum_increment;
1355 
1356  std::string stop_sign; // If this is a stop order, this will contain '<' or
1357  // '>'.
1358  std::string stop_price; // The price at which the stop order activates (less
1359  // than X or greater than X, based on sign.)
1360 
1361  std::string date; // (NEW FIELD) The date on which this offer was added to
1362  // the market.
1363 
1365 };
1366 
1367 class OfferListNym : public Storable
1368 {
1369  // You never actually get an instance of this, only its subclasses.
1370  // Therefore, I don't allow you to access the constructor except through
1371  // factory.
1372 protected:
1374  : Storable()
1375  {
1376  m_Type = "OfferListNym";
1377  }
1378 
1379 public:
1380  virtual ~OfferListNym()
1381  {
1382  }
1383 
1385 
1387 };
1388 
1390 {
1391  // You never actually get an instance of this, only its subclasses.
1392  // Therefore, I don't allow you to access the constructor except through
1393  // factory.
1394 protected:
1396  : Displayable()
1397  , transaction_id("0")
1398  , completed_count("0")
1399  , date("0")
1400  , price("0")
1401  , amount_sold("0")
1402  , updated_id("0")
1403  , offer_price("0")
1404  , finished_so_far("0")
1405  , currency_paid("0")
1406  {
1407  m_Type = "TradeDataNym";
1408  }
1409 
1410 public:
1411  virtual ~TradeDataNym()
1412  {
1413  }
1414 
1415  using Displayable::gui_label; // The label that appears in the GUI
1416 
1417  std::string transaction_id; // (transaction number for original offer.)
1418 
1419  std::string completed_count; // (How many trades have processed for the
1420  // associated offer? We keep count for each
1421  // trade.)
1422  std::string date; // (The date of this trade's execution)
1423  std::string price; // (The price this trade executed at.)
1424  std::string amount_sold; // (Amount of asset sold for that price.)
1425  std::string updated_id; // NEW FIELD (Transaction ID for trade receipt.)
1426  std::string offer_price; // NEW FIELD (price limit on the original offer.)
1427  std::string finished_so_far; // NEW FIELD (total amount sold across all
1428  // trades.)
1429  std::string asset_id; // NEW FIELD asset ID for trade
1430  std::string currency_id; // NEW FIELD currency ID for trade
1431  std::string currency_paid; // NEW FIELD currency paid for trade
1432 
1434 };
1435 
1436 class TradeListNym : public Storable
1437 {
1438  // You never actually get an instance of this, only its subclasses.
1439  // Therefore, I don't allow you to access the constructor except through
1440  // factory.
1441 protected:
1443  : Storable()
1444  {
1445  m_Type = "TradeListNym";
1446  }
1447 
1448 public:
1449  virtual ~TradeListNym()
1450  {
1451  }
1452 
1454 
1456 };
1457 
1458 // ACCOUNT (GUI local storage about my own accounts, in my wallet.)
1459 
1460 class Acct : public Displayable
1461 {
1462  // You never actually get an instance of this, only its subclasses.
1463  // Therefore, I don't allow you to access the constructor except through
1464  // factory.
1465 protected:
1467  : Displayable()
1468  {
1469  m_Type = "Acct";
1470  }
1471 
1472 public:
1473  virtual ~Acct()
1474  {
1475  }
1476 
1477  using Displayable::gui_label; // The label that appears in the GUI
1478 
1479  std::string acct_id;
1480  std::string server_id;
1481 
1483 };
1484 
1485 class BitcoinAcct : public Acct
1486 {
1487  // You never actually get an instance of this, only its subclasses.
1488  // Therefore, I don't allow you to access the constructor except through
1489  // factory.
1490 protected:
1492  : Acct()
1493  {
1494  m_Type = "BitcoinAcct";
1495  }
1496 
1497 public:
1498  virtual ~BitcoinAcct()
1499  {
1500  }
1501 
1502  using Displayable::gui_label; // The label that appears in the GUI
1503 
1504  using Acct::acct_id;
1505  using Acct::server_id;
1506 
1507  std::string bitcoin_acct_name;
1508 
1510 };
1511 
1512 // SERVER (GUI local storage about servers.)
1513 
1514 class ServerInfo : public Displayable
1515 {
1516  // You never actually get an instance of this, only its subclasses.
1517  // Therefore, I don't allow you to access the constructor except through
1518  // factory.
1519 protected:
1521  : Displayable()
1522  {
1523  m_Type = "ServerInfo";
1524  }
1525 
1526 public:
1527  virtual ~ServerInfo()
1528  {
1529  }
1530 
1531  using Displayable::gui_label; // The label that appears in the GUI
1532 
1533  std::string server_id;
1534  std::string server_type;
1535 
1537 };
1538 
1539 class Server : public ServerInfo
1540 {
1541  // You never actually get an instance of this, only its subclasses.
1542  // Therefore, I don't allow you to access the constructor except through
1543  // factory.
1544 protected:
1546  : ServerInfo()
1547  {
1548  m_Type = "Server";
1549  }
1550 
1551 public:
1552  virtual ~Server()
1553  {
1554  }
1555 
1556  using Displayable::gui_label; // The label that appears in the GUI
1557 
1558  using ServerInfo::server_id; // in base class
1559  using ServerInfo::server_type; // in base class
1560 
1561  std::string server_host;
1562  std::string server_port;
1563 
1565 };
1566 
1567 class BitcoinServer : public Server
1568 {
1569  // You never actually get an instance of this, only its subclasses.
1570  // Therefore, I don't allow you to access the constructor except through
1571  // factory.
1572 protected:
1574  : Server()
1575  {
1576  m_Type = "BitcoinServer";
1577  }
1578 
1579 public:
1580  virtual ~BitcoinServer()
1581  {
1582  }
1583 
1584  using Displayable::gui_label; // The label that appears in the GUI
1585 
1586  using ServerInfo::server_id; // in base class
1587  using ServerInfo::server_type; // in base class
1588 
1589  using Server::server_host; // in base class
1590  using Server::server_port; // in base class
1591 
1592  std::string bitcoin_username;
1593  std::string bitcoin_password;
1594 
1596 };
1597 
1598 class RippleServer : public Server
1599 {
1600  // You never actually get an instance of this, only its subclasses.
1601  // Therefore, I don't allow you to access the constructor except through
1602  // factory.
1603 protected:
1605  : Server()
1606  {
1607  m_Type = "RippleServer";
1608  }
1609 
1610 public:
1611  virtual ~RippleServer()
1612  {
1613  }
1614 
1615  using Displayable::gui_label; // The label that appears in the GUI
1616 
1617  using ServerInfo::server_id; // in base class
1618  using ServerInfo::server_type; // in base class
1619 
1620  using Server::server_host; // in base class
1621  using Server::server_port; // in base class
1622 
1623  std::string ripple_username;
1624  std::string ripple_password;
1625 
1626  std::string namefield_id;
1627  std::string passfield_id;
1628 
1630 };
1631 
1632 class LoomServer : public Server
1633 {
1634  // You never actually get an instance of this, only its subclasses.
1635  // Therefore, I don't allow you to access the constructor except through
1636  // factory.
1637 protected:
1639  : Server()
1640  {
1641  m_Type = "LoomServer";
1642  }
1643 
1644 public:
1645  virtual ~LoomServer()
1646  {
1647  }
1648 
1649  using Displayable::gui_label; // The label that appears in the GUI
1650 
1651  using ServerInfo::server_id; // in base class
1652  using ServerInfo::server_type; // in base class
1653 
1654  using Server::server_host; // in base class
1655  using Server::server_port; // in base class
1656 
1657  std::string loom_username;
1658 
1659  std::string namefield_id;
1660 
1662 };
1663 
1664 class ContactNym : public Displayable
1665 {
1666  // You never actually get an instance of this, only its subclasses.
1667  // Therefore, I don't allow you to access the constructor except through
1668  // factory.
1669 protected:
1671  : Displayable()
1672  {
1673  m_Type = "ContactNym";
1674  }
1675 
1676 public:
1677  virtual ~ContactNym();
1678 
1679  using Displayable::gui_label; // The label that appears in the GUI
1680 
1681  std::string nym_type;
1682  std::string nym_id;
1683  std::string public_key;
1684  std::string memo;
1685 
1687 
1689 };
1690 
1691 class WalletData : public Storable
1692 {
1693  // You never actually get an instance of this, only its subclasses.
1694  // Therefore, I don't allow you to access the constructor except through
1695  // factory.
1696 protected:
1698  : Storable()
1699  {
1700  m_Type = "WalletData";
1701  }
1702 
1703 public:
1704  virtual ~WalletData()
1705  {
1706  std::cout << "WalletData destructor" << std::endl;
1707  }
1708 
1709  // List of Bitcoin servers
1710  // List of Bitcoin accounts
1711  // Loom, etc.
1712 
1715 
1718 
1720 };
1721 
1722 class ContactAcct : public Displayable
1723 {
1724  // You never actually get an instance of this, only its subclasses.
1725  // Therefore, I don't allow you to access the constructor except through
1726  // factory.
1727 protected:
1729  : Displayable()
1730  {
1731  m_Type = "ContactAcct";
1732  }
1733 
1734 public:
1735  virtual ~ContactAcct()
1736  {
1737  }
1738 
1739  using Displayable::gui_label; // The label that appears in the GUI
1740 
1741  std::string server_type;
1742  std::string server_id;
1743  std::string asset_type_id;
1744  std::string acct_id;
1745  std::string nym_id;
1746  std::string memo;
1747  std::string public_key;
1748 
1750 };
1751 
1752 class Contact : public Displayable
1753 {
1754  // You never actually get an instance of this, only its subclasses.
1755  // Therefore, I don't allow you to access the constructor except through
1756  // factory.
1757 protected:
1759  : Displayable()
1760  {
1761  m_Type = "Contact";
1762  }
1763 
1764 public:
1765  virtual ~Contact();
1766 
1767  using Displayable::gui_label; // The label that appears in the GUI
1768 
1769  std::string contact_id;
1770  std::string email;
1771  std::string memo;
1772  std::string public_key;
1773 
1776 
1778 };
1779 
1780 class AddressBook : public Storable
1781 {
1782  // You never actually get an instance of this, only its subclasses.
1783  // Therefore, I don't allow you to access the constructor except through
1784  // factory.
1785 protected:
1787  : Storable()
1788  {
1789  m_Type = "AddressBook";
1790  }
1791 
1792 public:
1793  virtual ~AddressBook();
1794 
1796 
1798 };
1799 } // Namespace OTDB
1800 
1801 #ifndef SWIG
1802 
1803 // StorageFS -- FILE-SYSTEM Storage Context
1804 //
1805 //
1806 namespace OTDB
1807 {
1808 // StorageFS means "Storage on Filesystem."
1809 //
1810 // This is the first subclass of OTDB::Storage -- but it won't be the last!
1811 //
1812 class StorageFS : public Storage
1813 {
1814 private:
1815  std::string m_strDataPath;
1816 
1817 protected:
1818  StorageFS(); // You have to use the factory to instantiate (so it can create
1819  // the Packer also.)
1820  // But from there, however you Init, Store, Query, etc is entirely up to
1821  // you.
1822 
1823  // Confirms if a file exists. If it exists at path; return length.
1824  int64_t ConstructAndConfirmPath(std::string& strOutput,
1825  std::string strFolder,
1826  std::string oneStr = "",
1827  std::string twoStr = "",
1828  std::string threeStr = "");
1829 
1830  // Verifies whether path exists AND creates folders where necessary.
1831  int64_t ConstructAndCreatePath(std::string& strOutput,
1832  std::string strFolder,
1833  std::string oneStr = "",
1834  std::string twoStr = "",
1835  std::string threeStr = "");
1836 
1837 private:
1838  int64_t ConstructAndConfirmPathImp(bool bMakePath, std::string& strOutput,
1839  std::string zeroStr, std::string oneStr,
1840  std::string twoStr,
1841  std::string threeStr);
1842 
1843 protected:
1844  // If you wish to make your own subclass of OTDB::Storage, then use
1845  // StorageFS as an example.
1846  // The below 6 methods are the only overrides you need to copy.
1847  //
1848  virtual bool onStorePackedBuffer(PackedBuffer& theBuffer,
1849  std::string strFolder,
1850  std::string oneStr = "",
1851  std::string twoStr = "",
1852  std::string threeStr = "");
1853 
1854  virtual bool onQueryPackedBuffer(PackedBuffer& theBuffer,
1855  std::string strFolder,
1856  std::string oneStr = "",
1857  std::string twoStr = "",
1858  std::string threeStr = "");
1859 
1860  virtual bool onStorePlainString(std::string& theBuffer,
1861  std::string strFolder,
1862  std::string oneStr = "",
1863  std::string twoStr = "",
1864  std::string threeStr = "");
1865 
1866  virtual bool onQueryPlainString(std::string& theBuffer,
1867  std::string strFolder,
1868  std::string oneStr = "",
1869  std::string twoStr = "",
1870  std::string threeStr = "");
1871 
1872  virtual bool onEraseValueByKey(std::string strFolder,
1873  std::string oneStr = "",
1874  std::string twoStr = "",
1875  std::string threeStr = "");
1876 
1877 public:
1878  // virtual bool Init_Basic(OTString strWalletFilename); // OTLog::Path must
1879  // be first set to use this command
1880 
1881  // virtual bool Init(std::string oneStr="", std::string twoStr="",
1882  // std::string threeStr="",
1883  // std::string fourStr="", std::string fiveStr="", std::string
1884  // sixStr="");
1885 
1886  // See if the file is there.
1887  virtual bool Exists(std::string strFolder, std::string oneStr = "",
1888  std::string twoStr = "", std::string threeStr = "");
1889 
1890  virtual int64_t FormPathString(std::string& strOutput,
1891  std::string strFolder,
1892  std::string oneStr = "",
1893  std::string twoStr = "",
1894  std::string threeStr = "");
1895 
1897  {
1898  return new StorageFS;
1899  }
1900 
1901  virtual ~StorageFS();
1902 
1903  // lower level calls.
1904 
1905  bool ConfirmOrCreateFolder(const char* szFolderName,
1906  struct stat* pst = nullptr); // local to
1907  // data_folder
1908  bool ConfirmFile(const char* szFileName,
1909  struct stat* pst = nullptr); // local to data_folder
1910 
1911  /*
1912  IN BASE CLASS:
1913 
1914  // Store/Retrieve a string.
1915 
1916  bool StoreString(std::string strContents, std::string strFolder,
1917  std::string oneStr="", std::string twoStr="", std::string threeStr="");
1918 
1919  std::string QueryString(std::string strFolder, std::string oneStr="",
1920  std::string twoStr="", std::string threeStr="");
1921 
1922  bool StorePlainString(std::string strContents, std::string strFolder,
1923  std::string oneStr="", std::string twoStr="", std::string threeStr="");
1924 
1925  std::string QueryPlainString(std::string strFolder, std::string oneStr="",
1926  std::string twoStr="", std::string threeStr="");
1927 
1928  // Store/Retrieve an object. (Storable.)
1929 
1930  bool StoreObject(Storable& theContents, std::string strFolder,
1931  std::string oneStr="", std::string twoStr="", std::string threeStr="");
1932 
1933  // Use %newobject OTDB::Storage::Query();
1934  Storable * QueryObject(StoredObjectType theObjectType,
1935  std::string strFolder, std::string oneStr="",
1936  std::string twoStr="", std::string threeStr="");
1937  */
1938 };
1939 
1940 // Other storage subclasses may go here, for storing in SQL lite,
1941 // or couchDB, mongoDB, distributed DB, etc...
1942 
1943 // class StorageCouchDB
1944 // class CloudMagic
1945 // class SQL-LITE
1946 //
1947 // Etc.
1948 
1949 // Also, coders using the API should be able to subclass Storage in their own
1950 // language via SWIG.
1951 
1952 } // namespace OTDB
1953 
1954 // IStorable-derived types...
1955 //
1956 //
1957 // BELOW are the SUBCLASSES of the storable objects that actually get
1958 // INSTANTIATED,
1959 // based on WHICH PACKER is being used.
1960 
1961 // If you are adding a new DATA OBJECT, then you probably want to add lines
1962 // below
1963 // for EACH of the different packer types (MsgPack, Protocol Buffers, JSON,
1964 // etc.)
1965 //
1966 
1967 #define OT_USING_ISTORABLE_HOOKS \
1968  using IStorable::hookBeforePack; \
1969  using IStorable::hookAfterUnpack
1970 
1971 #endif // (not) SWIG
1972 
1973 } // namespace opentxs
1974 
1975 #endif // OPENTXS_CORE_OTSTORAGE_HPP
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:698
EXPORT Storage * GetDefaultStorage()
Definition: OTStorage.cpp:480
Storable *( InstantiateFunc)()
Definition: OTStorage.hpp:327
EXPORT Storable * CreateObject(StoredObjectType eType)
Definition: OTStorage.cpp:530
std::map< InstantiateFuncKey, InstantiateFunc * > mapOfFunctions
Definition: OTStorage.hpp:340
EXPORT bool Unpack(PackedBuffer &inBuf, Storable &outObj)
Definition: OTStorage.cpp:972
OTDBString(const std::string &rhs)
Definition: OTStorage.hpp:921
static StorageFS * Instantiate()
Definition: OTStorage.hpp:1896
virtual void hookAfterUnpack()
Definition: OTStorage.hpp:384
EXPORT std::string QueryString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:671
EXPORT std::string EncodeObject(Storable &theContents)
Definition: OTStorage.cpp:2389
std::string acct_id
Definition: OTStorage.hpp:1479
void SetPacker(OTPacker &thePacker)
Definition: OTStorage.hpp:627
virtual bool onStorePackedBuffer(PackedBuffer &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2696
PackedBuffer * Pack(Storable &inObj)
Definition: OTStorage.cpp:930
EXPORT bool StorePlainString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2283
EXPORT bool StoreString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2203
std::vector< uint8_t > m_memBuffer
Definition: OTStorage.hpp:956
#define OTDB_DEFAULT_PACKER
Definition: OTStorage.hpp:167
virtual bool PackString(std::string &theString)=0
virtual bool ReadFromIStream(std::istream &inStream, int64_t lFilesize)=0
virtual int64_t FormPathString(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2948
EXPORT std::string QueryString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2237
EXPORT bool InitDefaultStorage(StorageType eStoreType, PackType ePackType)
Definition: OTStorage.cpp:491
virtual void hookBeforePack()
Definition: OTStorage.hpp:380
virtual bool onEraseValueByKey(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
static EXPORT Storage * Create(StorageType eStorageType, PackType ePackType)
Definition: OTStorage.cpp:2145
EXPORT bool CheckStringsExistInOrder(std::string &strFolder, std::string &oneStr, std::string &twoStr, std::string &threeStr, const char *szFuncName=nullptr)
Definition: OTStorage.cpp:549
virtual bool onQueryPlainString(std::string &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
bool ConfirmOrCreateFolder(const char *szFolderName, struct stat *pst=nullptr)
Definition: OTStorage.cpp:2516
EXPORT Storable * QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:788
EXPORT std::string EncodeObject(Storable &theContents)
Definition: OTStorage.cpp:818
EXPORT Storable * DecodeObject(StoredObjectType theObjectType, std::string strInput)
Definition: OTStorage.cpp:2435
virtual bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
EXPORT Storable * CreateObject(StoredObjectType eType)
Definition: OTStorage.cpp:2128
virtual bool onQueryPlainString(std::string &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2810
std::string server_host
Definition: OTStorage.hpp:1561
DECLARE_GET_ADD_REMOVE(BitcoinServer)
virtual bool onQueryPackedBuffer(PackedBuffer &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
#define EndInterface
Definition: OTStorage.hpp:203
std::pair< PackType, StoredObjectType > InstantiateFuncKey
Definition: OTStorage.hpp:329
DECLARE_GET_ADD_REMOVE(MarketData)
virtual void SetData(const uint8_t *pData, size_t theSize)=0
virtual bool WriteToOStream(std::ostream &outStream)=0
EXPORT Storage * CreateStorageContext(StorageType eStoreType, PackType ePackType=OTDB_DEFAULT_PACKER)
Definition: OTStorage.cpp:522
const char * StoredObjectTypeStrings[]
Definition: OTStorage.cpp:300
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:728
virtual bool onQueryPackedBuffer(PackedBuffer &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2730
int64_t ConstructAndConfirmPath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2562
DeclareInterface(IStorable) virtual bool onPack(PackedBuffer &theBuffer
std::string GetValue(const std::string &strKey)
Definition: OTStorage.hpp:990
std::string server_port
Definition: OTStorage.hpp:1562
#define OT_ASSERT(x)
Definition: Assert.hpp:150
static OTPacker * Create(PackType ePackType)
Definition: OTStorage.cpp:889
virtual bool onStorePlainString(std::string &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
OTDB::Storage * s_pStorage
Definition: OTStorage.cpp:293
EXPORT std::string QueryPlainString(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2290
EXPORT bool EraseValueByKey(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:843
virtual bool UnpackString(std::string &theString)=0
DECLARE_GET_ADD_REMOVE(ContactNym)
virtual bool onStorePackedBuffer(PackedBuffer &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
EXPORT StorageType GetType() const
Definition: OTStorage.cpp:2187
EXPORT bool StoreString(std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:644
virtual size_t GetSize()=0
std::string server_id
Definition: OTStorage.hpp:1480
bool ConfirmFile(const char *szFileName, struct stat *pst=nullptr)
Definition: OTStorage.cpp:2530
DECLARE_GET_ADD_REMOVE(OfferDataNym)
EXPORT bool EraseValueByKey(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2488
DECLARE_GET_ADD_REMOVE(ServerInfo)
EXPORT OTPacker * GetPacker(PackType ePackType=OTDB_DEFAULT_PACKER)
Definition: OTStorage.cpp:2103
std::map< std::string, std::string > the_map
Definition: OTStorage.hpp:981
Storable & inObj
Definition: OTStorage.hpp:376
OTDB::mapOfFunctions * pFunctionMap
Definition: OTStorage.cpp:295
virtual PackedBuffer * CreateBuffer()=0
EXPORT Storable * QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2336
virtual int64_t FormPathString(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")=0
DECLARE_GET_ADD_REMOVE(TradeDataMarket)
EXPORT int64_t FormPathString(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:612
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
std::string recent_highest_bid
Definition: OTStorage.hpp:1083
PackType GetType() const
Definition: OTStorage.cpp:914
static EXPORT Storable * Create(StoredObjectType eType, PackType thePackType)
Definition: OTStorage.cpp:860
EXPORT Storable * DecodeObject(StoredObjectType theObjectType, std::string strInput)
Definition: OTStorage.cpp:830
virtual PackedBuffer * CreateBuffer()
Definition: OTStorage.hpp:582
virtual const uint8_t * GetData()=0
virtual bool onEraseValueByKey(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2862
EXPORT bool StoreObject(Storable &theContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:759
DECLARE_GET_ADD_REMOVE(TradeDataNym)
#define DEFINE_OT_DYNAMIC_CAST(CLASS_NAME)
Definition: OTStorage.hpp:414
Storage(const Storage &)
Definition: OTStorage.hpp:621
virtual bool onUnpack(PackedBuffer &theBuffer, Storable &outObj)=0
void SetValue(const std::string &strKey, const std::string &strValue)
Definition: OTStorage.hpp:983
virtual bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2937
int64_t ConstructAndCreatePath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2552
virtual bool onStorePlainString(std::string &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2768
EXPORT bool StoreObject(Storable &theContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2301