Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTClient.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTClient.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_OTCLIENT_HPP
134 #define OPENTXS_CLIENT_OTCLIENT_HPP
135 
138 
139 namespace opentxs
140 {
141 
142 class TransportCallback;
143 class OTAccount;
144 class OTAssetContract;
145 class OTLedger;
146 class OTServerConnection;
147 class OTServerContract;
148 class OTWallet;
149 
150 // This class represents the "test client"
151 //
152 // I have it separate from the wallet because I would like to be
153 // able to use the wallet in a "nice client" too, so I'm forcing
154 // the separation to keep it designed that way.
155 //
156 
157 class OTClient
158 {
159 private:
160  OTWallet* m_pWallet; // NOT owned, but this pointer is here for convenience.
161 
162  OTMessageBuffer m_MessageBuffer; // Incoming server replies are copied here
163  // for easy access.
164  OTMessageOutbuffer m_MessageOutbuffer; // Outgoing messages are copied here
165  // for easy access.
166 
167  bool m_bRunningAsScript; // This is used to determine whether to activate
168  // certain messages automatically in
169  // the client based on various server replies to previous requests (based on
170  // what mode it's being used in...
171  // if we're using the API, then NO auto-messages!) Similarly, if we're using
172  // the interpreted script, then NO auto
173  // messages. But if we are using the test client, aka the command line in
174  // --prompt mode, and the --script switch
175  // wasn't used to startup, (which would mean we're executing a script) then
176  // it's A-Okay to fire those auto messages.
177 
188  int64_t m_lMostRecentRequestNumber;
189 
190 public:
191  int32_t CalcReturnVal(const int64_t& lRequestNumber);
192  bool IsRunningAsScript() const
193  {
194  return m_bRunningAsScript;
195  }
197  {
198  m_bRunningAsScript = true;
199  } // (default is false.)
201  checkServerID, // Your public key is sent along with this message so the
202  // server can reply to
203  // you even without your being a registered user. Other than these top
204  // two commands,
205  // all other commands can only be executed by registered users.
206  //
207  // The server ID is a hash of the server contract. The signature on the
208  // contract
209  // can be verified by a public key that appears in a standard section of
210  // any server
211  // contract. The URL/port information is also derived from the contract.
212  //
213  // Simply by importing the server contract into your wallet, you are
214  // able to connect
215  // to it and encrypt all of your communications to it.
216  //
217  // Thus, the check server ID command really just confirms what you
218  // should already know...
219  // Your wallet still wants to see that the server agrees with the server
220  // ID, and that
221  // the server is able to read messages that were encrypted to the public
222  // key in the
223  // contract, and that the server is able to sign all of its future
224  // correspondence with
225  // the same public key.
226  //
227  // It is the server operator's responsibility to secure the domain name
228  // and web host
229  // that users will connect to when they import the contract, as well as
230  // the private
231  // key that matches the public key from the contract.
232  createUserAccount, // Create user account on a specific server, with
233  // public key. User ID will be hash of said public
234  // key.
235  deleteUserAccount, // Delete user account from a specific server.
236  checkUser, // Request a user's public key based on User ID included with
237  // the request.
238  // (If you want to send him cash or a check, your wallet will encrypt
239  // portions
240  // of the tokens, etc, to the Nym of the recipient.)
241  sendUserMessage, // Send a message to another user, encrypted to his
242  // public key and dropped into his nymbox.
243  getRequest, // Get the next request number from the server (for this
244  // user). Most requests must be
245  // accompanied by a request number, which increments for each Nym with
246  // each request.
247  issueAssetType, // Upload a currency contract to the server and create
248  // an asset ID from a hash of that.
249  // contract. Also creates an issuer account for that asset ID. This ONLY
250  // works if public
251  // key of the user matches the contract key found in the currency
252  // contract, AND if the
253  // contract is signed by the same key.
254  createAccount, // Create an asset account for a certain serverID,
255  // UserID, and Asset Type ID.
256  // These accounts are where users actually store their digital assets of
257  // various
258  // types. Account files are stored on user's computer, signed by notary
259  // server.
260  // Server also maintains its own copy. Users can create an unlimited
261  // number of accounts
262  // for any asset type that they choose.
263  issueBasket, // Create a basket account, which is like an issuer
264  // account, but based on a basket of
265  // other asset types. This way, users can trade with what is apparently
266  // a single currency,
267  // when in fact the issuence is delegated and distributed across
268  // multiple issuers.
269  exchangeBasket, // Use this to exchange assets in and out of a basket
270  // currency.
271  getTransactionNum, // Every transaction requires a transaction number.
272  // If your wallet doesn't have one,
273  // then here it can request the server to send one over. (Or several.)
274  getNymbox, // Grab a copy of my nymbox (contains messages and new
275  // transaction numbers)
276  getInbox, // Grab a copy of my inbox from the server so I can decide
277  // what to do with it.
278  getOutbox, // Grab a copy of my outbox from the server so I can decide
279  // what to do with it.
280  processNymbox, // Used by AcceptEntireNymbox() as it's setting
281  // everything up.
282  processEntireNymbox, // Instruct the server what to do with the various
283  // items sitting in my nymbox. (per user)
284  processInbox, // Instruct the server what to do with the various items
285  // sitting in my inbox. (per asset acct)
286  processEntireInbox, // Just accept everything in the server (used in the
287  // command line test client.)
288  getAccount, // Grab the server's copy of my asset account file, in case
289  // mine is lost.
290  getContract, // Grab the server's copy of any asset contract. Input is
291  // the asset type ID.
292  getMint, // Grab the server's copy of any mint based on Asset ID. (For
293  // blinded tokens.)
294  writeCheque, // Write a cheque. (Actually sends no message to the server
295  // -- returns false.)
296  signContract, // Sign a contract. (Sends no message to the server.)
297  proposePaymentPlan, // (Merchant) Propose a payment plan. (Sends no
298  // message to the server.)
299  confirmPaymentPlan, // (Customer) Confirm a payment plan. (Sends no
300  // message to the server.)
301  notarizeTransfer, // Request the server to transfer from one account to
302  // another.
303  notarizeWithdrawal, // Request the server to withdraw from an asset
304  // account and return digital cash tokens to the
305  // wallet.
306  withdrawVoucher, // Request the server to withdraw from an asset account
307  // and issue a voucher (cashier's cheque)
308  notarizeDeposit, // Request the server to accept some digital cash and
309  // deposit it to an asset account.
310  notarizePurse, // Same as the above, but sends an entire purse of tokens
311  // at once instead of sending individual tokens.
312  notarizeCheque, // Deposit like the above, but deposits a cheque instead
313  // of cash tokens.
314  marketOffer, // Create an Offer object and add it to one of the server's
315  // Market objects.
316  // This will also create a Trade object and add it to the server's Cron
317  // object.
318  // (The Trade provides the payment authorization for the Offer, as well
319  // as the rules
320  // for processing and expiring it.)
321  paymentPlan, // Send a payment plan to the server (request to activate
322  // one onto yourself, basically.)
323  // The test client will ask you to input the plan, which you must
324  // already have (like a cheque).
325  // The Payee must create it and sign it, then he sends it to the Payer,
326  // who uses this command
327  // to sign it and submit it to the server.
328  setAccountName, // For setting the client-side label on an asset
329  // account.
330  setNymName, // For setting the client-side label on a Nym.
331  setServerName, // For setting the client-side label on a server
332  // contract.
333  setAssetName, // For setting the client-side label on an asset contract.
335  };
336 
337  // Right now this wallet just supports a SINGLE server connection.
338  // Eventually it will be a whole list of server connections.
339  // For now one is good enough for testing.
340  // All commands for the server will be sent here.
341  //
342  // Here was the problem, you see: You can't attach the connection to the
343  // Nym,
344  // because the same Nym might have connections to different servers. And you
345  // can't
346  // attach it to the server contract, because the user might access that
347  // server
348  // through multiple nym accounts on the same server.
349  // So I decided the wallet should manage the connections, and when new
350  // connections
351  // are made, the serverconnection object will be given a pointer at that
352  // time to
353  // the server and nym for that connection. That way the two are always
354  // available
355  // for processing the commands.
356 
358 
360  {
361  return m_MessageBuffer;
362  }
364  {
365  return m_MessageOutbuffer;
366  }
367 
368  // inline bool IsConnected() { return m_pConnection->IsConnected(); }
369 
370  // For RPC mode
371  EXPORT bool SetFocusToServerAndNym(OTServerContract& theServerContract,
372  OTPseudonym& theNym,
373  TransportCallback* pCallback) const;
374 
375  // For the test client in SSL / TCP mode.
376  bool ConnectToTheFirstServerOnList(const OTPseudonym& theNym,
377  const OTString& strCA_FILE,
378  const OTString& strKEY_FILE,
379  const OTString& strKEY_PASSWORD) const;
380 
381  // Eventually, the wallet will have a LIST of these server connections,
382  // and any use of the connection will first require to look up the right one
383  // on that list, based on ID. This will return a pointer, and then you do
384  // the
385  // same call you normally did from there.
386 
387  OTClient();
388  ~OTClient();
389 
390  bool InitClient(OTWallet& theWallet); // Need to call this before using.
391  bool m_bInitialized; // this will be false until InitClient() is called.
392  // These functions manipulate the internal m_pConnection member:
393  void ProcessMessageOut(const char* buf, int32_t* pnExpectReply) const;
394  void ProcessMessageOut(const OTMessage& theMessage);
395  bool ProcessInBuffer(const OTMessage& theServerReply) const;
396  // These functions are for command processing:
397 
398  EXPORT int32_t
399  ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand,
400  OTMessage& theMessage, OTPseudonym& theNym,
401  // OTAssetContract& theContract,
402  const OTServerContract& theServer,
403  const OTAccount* pAccount = nullptr,
404  int64_t lTransactionAmount = 0,
405  OTAssetContract* pMyAssetContract = nullptr,
406  const OTIdentifier* pHisNymID = nullptr,
407  const OTIdentifier* pHisAcctID = nullptr);
408 
409  bool ProcessServerReply(OTMessage& theReply,
410  OTLedger* pNymbox = nullptr); // IF the Nymbox is
411  // passed in, then use
412  // that one, where appropriate, instead
413  // of loading it internally.
415  OTMessage& theReply) const;
416  void ProcessWithdrawalResponse(OTTransaction& theTransaction,
417  const OTServerConnection& theConnection,
418  const OTMessage& theReply) const;
419  void ProcessDepositResponse(OTTransaction& theTransaction,
420  const OTServerConnection& theConnection,
421  const OTMessage& theReply) const;
422  void ProcessPayDividendResponse(OTTransaction& theTransaction,
423  const OTServerConnection& theConnection,
424  const OTMessage& theReply) const;
425 
426  // void AcceptEntireInbox (OTLedger& theInbox, OTServerConnection&
427  // theConnection);
428  // void AcceptEntireNymbox(OTLedger& theNymbox, OTServerConnection&
429  // theConnection);
430 
431  bool AcceptEntireInbox(OTLedger& theInbox, const OTIdentifier& theServerID,
432  const OTServerContract& theServerContract,
433  OTPseudonym& theNym, const OTMessage& theMessage,
434  const OTAccount& theAccount);
435 
436  bool AcceptEntireNymbox(OTLedger& theNymbox,
437  const OTIdentifier& theServerID,
438  const OTServerContract& theServerContract,
439  OTPseudonym& theNym, OTMessage& theMessage);
440 
441  // void HarvestTransactionNumbers(OTTransaction& theTransaction,
442  // OTPseudonym& theNym);
443 };
444 
445 } // namespace opentxs
446 
447 #endif // OPENTXS_CLIENT_OTCLIENT_HPP
EXPORT bool SetFocusToServerAndNym(OTServerContract &theServerContract, OTPseudonym &theNym, TransportCallback *pCallback) const
Definition: OTClient.cpp:13747
void ProcessDepositResponse(OTTransaction &theTransaction, const OTServerConnection &theConnection, const OTMessage &theReply) const
Definition: OTClient.cpp:3287
int32_t CalcReturnVal(const int64_t &lRequestNumber)
Definition: OTClient.cpp:173
void ProcessPayDividendResponse(OTTransaction &theTransaction, const OTServerConnection &theConnection, const OTMessage &theReply) const
Definition: OTClient.cpp:3252
bool ProcessServerReply(OTMessage &theReply, OTLedger *pNymbox=nullptr)
Definition: OTClient.cpp:3764
EXPORT int32_t ProcessUserCommand(OT_CLIENT_CMD_TYPE requestedCommand, OTMessage &theMessage, OTPseudonym &theNym, const OTServerContract &theServer, const OTAccount *pAccount=nullptr, int64_t lTransactionAmount=0, OTAssetContract *pMyAssetContract=nullptr, const OTIdentifier *pHisNymID=nullptr, const OTIdentifier *pHisAcctID=nullptr)
Definition: OTClient.cpp:8905
OTServerConnection * m_pConnection
Definition: OTClient.hpp:357
bool ConnectToTheFirstServerOnList(const OTPseudonym &theNym, const OTString &strCA_FILE, const OTString &strKEY_FILE, const OTString &strKEY_PASSWORD) const
Definition: OTClient.cpp:13722
OTMessageOutbuffer & GetMessageOutbuffer()
Definition: OTClient.hpp:363
void ProcessMessageOut(const char *buf, int32_t *pnExpectReply) const
Definition: OTClient.cpp:190
bool ProcessInBuffer(const OTMessage &theServerReply) const
Definition: OTClient.cpp:247
void SetRunningAsScript()
Definition: OTClient.hpp:196
bool AcceptEntireNymbox(OTLedger &theNymbox, const OTIdentifier &theServerID, const OTServerContract &theServerContract, OTPseudonym &theNym, OTMessage &theMessage)
Definition: OTClient.cpp:259
bool InitClient(OTWallet &theWallet)
Need to call this before using.
Definition: OTClient.cpp:13758
bool AcceptEntireInbox(OTLedger &theInbox, const OTIdentifier &theServerID, const OTServerContract &theServerContract, OTPseudonym &theNym, const OTMessage &theMessage, const OTAccount &theAccount)
Definition: OTClient.cpp:1158
void ProcessWithdrawalResponse(OTTransaction &theTransaction, const OTServerConnection &theConnection, const OTMessage &theReply) const
Definition: OTClient.cpp:3565
void ProcessIncomingTransactions(OTServerConnection &theConnection, OTMessage &theReply) const
Definition: OTClient.cpp:2056
bool IsRunningAsScript() const
Definition: OTClient.hpp:192
OTMessageBuffer & GetMessageBuffer()
Definition: OTClient.hpp:359