Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Basket.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * Basket.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_BASKET_BASKET_HPP
134 #define OPENTXS_BASKET_BASKET_HPP
135 
136 #include "BasketItem.hpp"
138 
139 /*
140 
141  I figured this one out, it's easy.
142 
143  Someone creates a contract that contains 10 sub-contracts. It just delegates
144  the issuence to the sub-issuers.
145 
146  When he connects to the server he can upload the contract, but he has no
147  control over it at that point,
148  since he is not one of the real issuers.
149 
150  The contract will only work if the sub-issuers actually have issued currencies
151  on that transaction server.
152 
153  Then, the transaction server itself becomes the "issuer" of the basket
154  currency. It simply creates an issuer
155  account, and stores a list of sub-accounts to store the delegated cuts of
156  "real" currencies.
157 
158  For example, if I issue a currency that is 1 part dollar, 1 part gold, and 1
159  part silver, then the server
160  creates an issuer account in "goldbucks" and then ANY other user can create a
161  "goldbucks" asset account and
162  trade it like any other asset. It doesn't even have to be a special account
163  that the trader uses. It's just
164  a normal account, but the asset type ID links to the special basket issuer
165  account maintained by the server.
166 
167  Meanwhile, behind the scenes, the server's "goldbucks" issuer account is not
168  OTAccount, but derived from it.
169  suppose derived from OTAccount, that contains a list of 3 sub-accounts, 1
170  denominated in the dollar asset
171  specified in the contract, 1 denominiated in the gold asset, and so on.
172 
173  The OTAssetBasket contract (with sub-issuers) and the BasketAccount (issuer
174  account) objects handle all the
175  details of converting between the sub-accounts and the main account.
176 
177  If I am trading in goldbucks, and I have 9 goldbucks in my goldbucks account,
178  then the goldbucks issuer account
179  (controlled by the transaction server) must have at least -9 on its balance due
180  to me. And its hidden 3 sub-accounts
181  have at least +3 dollars, +3 gold, and +3 silver stored along with the rest
182  that make up their total balances from
183  all the users of that basket currency.
184 
185  */
186 
187 namespace opentxs
188 {
189 
190 class Basket : public OTContract
191 {
192 protected:
193  int32_t m_nSubCount;
194  int64_t m_lMinimumTransfer; // used in the actual basket
195  int32_t m_nTransferMultiple; // used in a request basket. If non-zero, that
196  // means this is a request basket.
197  OTIdentifier m_RequestAccountID; // used in a request basket so the server
198  // knows your acct ID.
200  bool m_bHideAccountID; // When saving, we might wish to produce a version
201  // without Account IDs
202  // So that the resulting hash will be a consistent ID across different
203  // servers.
204  bool m_bExchangingIn; // True if exchanging INTO the basket, False if
205  // exchanging OUT of the basket.
206  int64_t m_lClosingTransactionNo; // For the main (basket) account, in a
207  // request basket (for exchanges.)
208  // return -1 if error, 0 if nothing, and 1 if the node was processed.
209  virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader*& xml);
210 
211 public:
212  EXPORT Basket();
213  EXPORT Basket(int32_t nCount, int64_t lMinimumTransferAmount);
214  EXPORT virtual ~Basket();
215 
216  virtual void UpdateContents();
217  virtual bool SaveContractWallet(std::ofstream& ofs) const;
218 
219  EXPORT virtual void CalculateContractID(OTIdentifier& newID) const;
220 
221  inline int64_t GetMinimumTransfer() const
222  {
223  return m_lMinimumTransfer;
224  }
225 
226  inline int32_t GetTransferMultiple() const
227  {
228  return m_nTransferMultiple;
229  }
230  inline void SetTransferMultiple(int32_t nTransferMultiple)
231  {
232  m_nTransferMultiple = nTransferMultiple;
233  }
234 
235  inline bool IsExchanging() const
236  {
237  return (m_nTransferMultiple > 0);
238  }
239 
240  inline bool GetExchangingIn() const
241  {
242  return m_bExchangingIn;
243  }
244  inline void SetExchangingIn(bool bDirection)
245  {
246  m_bExchangingIn = bDirection;
247  }
248 
249  EXPORT int32_t Count() const;
250  EXPORT BasketItem* At(uint32_t nIndex);
251 
252  int64_t GetClosingTransactionNoAt(uint32_t nIndex);
253 
254  inline int64_t GetClosingNum() const
255  {
257  }
258  inline void SetClosingNum(const int64_t& lClosingNum)
259  {
260  m_lClosingTransactionNo = lClosingNum;
261  }
262 
263  // For generating a real basket. The user does this part, and the server
264  // creates Account ID later
265  // (That's why you don't see the account ID being passed in to the method.)
266  EXPORT void AddSubContract(const OTIdentifier& SUB_CONTRACT_ID,
267  int64_t lMinimumTransferAmount);
268  inline void IncrementSubCount()
269  {
270  m_nSubCount++;
271  }
272 
273  // For generating a user request to exchange in/out of a basket.
274  // Assumes that SetTransferMultiple has already been called.
275  EXPORT void AddRequestSubContract(const OTIdentifier& SUB_CONTRACT_ID,
276  const OTIdentifier& SUB_ACCOUNT_ID,
277  const int64_t& lClosingTransactionNo);
278 
279  inline void SetRequestAccountID(const OTIdentifier& theAccountID)
280  {
281  m_RequestAccountID = theAccountID;
282  }
284  {
285  return m_RequestAccountID;
286  }
287 
288  virtual void Release();
289  void Release_Basket();
290 
291  // The basket itself only stores the CLOSING numbers.
292  // For the opening number, you have to go deal with the exchangeBasket
293  // TRANSACTION.
294 
295  // Normally do this if your transaction failed so you can get most of your
296  // numbers back
297  //
298  EXPORT void HarvestClosingNumbers(OTPseudonym& theNym,
299  const OTIdentifier& theServerID,
300  bool bSave = true);
301 
302 private:
303  void GenerateContents(OTStringXML& xmlUnsigned, bool bHideAccountID) const;
304 };
305 
306 } // namespace opentxs
307 
308 #endif // OPENTXS_BASKET_BASKET_HPP
int64_t m_lClosingTransactionNo
Definition: Basket.hpp:206
const OTIdentifier & GetRequestAccountID()
Definition: Basket.hpp:283
EXPORT void AddRequestSubContract(const OTIdentifier &SUB_CONTRACT_ID, const OTIdentifier &SUB_ACCOUNT_ID, const int64_t &lClosingTransactionNo)
Definition: Basket.cpp:238
int64_t GetMinimumTransfer() const
Definition: Basket.hpp:221
bool m_bHideAccountID
Definition: Basket.hpp:200
std::deque< BasketItem * > dequeOfBasketItems
Definition: BasketItem.hpp:143
bool IsExchanging() const
Definition: Basket.hpp:235
void IncrementSubCount()
Definition: Basket.hpp:268
virtual void Release()
Definition: Basket.cpp:505
void SetTransferMultiple(int32_t nTransferMultiple)
Definition: Basket.hpp:230
bool m_bExchangingIn
Definition: Basket.hpp:204
int64_t GetClosingNum() const
Definition: Basket.hpp:254
int64_t m_lMinimumTransfer
Definition: Basket.hpp:194
int32_t GetTransferMultiple() const
Definition: Basket.hpp:226
virtual void UpdateContents()
Definition: Basket.cpp:383
int32_t m_nSubCount
Definition: Basket.hpp:193
virtual EXPORT void CalculateContractID(OTIdentifier &newID) const
Definition: Basket.cpp:449
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
Definition: Basket.cpp:311
virtual bool SaveContractWallet(std::ofstream &ofs) const
Definition: Basket.cpp:512
dequeOfBasketItems m_dequeItems
Definition: Basket.hpp:199
virtual EXPORT ~Basket()
Definition: Basket.cpp:482
EXPORT BasketItem * At(uint32_t nIndex)
Definition: Basket.cpp:298
int32_t m_nTransferMultiple
Definition: Basket.hpp:195
EXPORT void HarvestClosingNumbers(OTPseudonym &theNym, const OTIdentifier &theServerID, bool bSave=true)
Definition: Basket.cpp:187
void SetExchangingIn(bool bDirection)
Definition: Basket.hpp:244
bool GetExchangingIn() const
Definition: Basket.hpp:240
void SetRequestAccountID(const OTIdentifier &theAccountID)
Definition: Basket.hpp:279
EXPORT Basket()
Definition: Basket.cpp:471
void SetClosingNum(const int64_t &lClosingNum)
Definition: Basket.hpp:258
int64_t GetClosingTransactionNoAt(uint32_t nIndex)
Definition: Basket.cpp:285
void Release_Basket()
Definition: Basket.cpp:487
EXPORT void AddSubContract(const OTIdentifier &SUB_CONTRACT_ID, int64_t lMinimumTransferAmount)
Definition: Basket.cpp:265
OTIdentifier m_RequestAccountID
Definition: Basket.hpp:197
EXPORT int32_t Count() const
Definition: Basket.cpp:305