This repository has been archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
/
OTScript.h
317 lines (250 loc) · 11 KB
/
OTScript.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/************************************************************************************
*
* OTScript.h
*
*/
/************************************************************
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
* OPEN TRANSACTIONS
*
* Financial Cryptography and Digital Cash
* Library, Protocol, API, Server, CLI, GUI
*
* -- Anonymous Numbered Accounts.
* -- Untraceable Digital Cash.
* -- Triple-Signed Receipts.
* -- Cheques, Vouchers, Transfers, Inboxes.
* -- Basket Currencies, Markets, Payment Plans.
* -- Signed, XML, Ricardian-style Contracts.
* -- Scripted smart contracts.
*
* Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
*
* EMAIL:
* FellowTraveler@rayservers.net
*
* BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
*
* KEY FINGERPRINT (PGP Key in license file):
* 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
*
* OFFICIAL PROJECT WIKI(s):
* https://github.com/FellowTraveler/Moneychanger
* https://github.com/FellowTraveler/Open-Transactions/wiki
*
* WEBSITE:
* http://www.OpenTransactions.org/
*
* Components and licensing:
* -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
* -- otlib.........A class library.......LICENSE:...LAGPLv3
* -- otapi.........A client API..........LICENSE:...LAGPLv3
* -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
* -- otserver......Server Application....LICENSE:....AGPLv3
* Github.com/FellowTraveler/Open-Transactions/wiki/Components
*
* All of the above OT components were designed and written by
* Fellow Traveler, with the exception of Moneychanger, which
* was contracted out to Vicky C (bitcointrader4@gmail.com).
* The open-source community has since actively contributed.
*
* -----------------------------------------------------
*
* LICENSE:
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* ADDITIONAL PERMISSION under the GNU Affero GPL version 3
* section 7: (This paragraph applies only to the LAGPLv3
* components listed above.) If you modify this Program, or
* any covered work, by linking or combining it with other
* code, such other code is not for that reason alone subject
* to any of the requirements of the GNU Affero GPL version 3.
* (==> This means if you are only using the OT API, then you
* don't have to open-source your code--only your changes to
* Open-Transactions itself must be open source. Similar to
* LGPLv3, except it applies to software-as-a-service, not
* just to distributing binaries.)
*
* Extra WAIVER for OpenSSL, Lucre, and all other libraries
* used by Open Transactions: This program is released under
* the AGPL with the additional exemption that compiling,
* linking, and/or using OpenSSL is allowed. The same is true
* for any other open source libraries included in this
* project: complete waiver from the AGPL is hereby granted to
* compile, link, and/or use them with Open-Transactions,
* according to their own terms, as long as the rest of the
* Open-Transactions terms remain respected, with regard to
* the Open-Transactions code itself.
*
* Lucre License:
* This code is also "dual-license", meaning that Ben Lau-
* rie's license must also be included and respected, since
* the code for Lucre is also included with Open Transactions.
* See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
* The Laurie requirements are light, but if there is any
* problem with his license, simply remove the Lucre code.
* Although there are no other blind token algorithms in Open
* Transactions (yet. credlib is coming), the other functions
* will continue to operate.
* See Lucre on Github: https://github.com/benlaurie/lucre
* -----------------------------------------------------
* You should have received a copy of the GNU Affero General
* Public License along with this program. If not, see:
* http://www.gnu.org/licenses/
*
* If you would like to use this software outside of the free
* software license, please contact FellowTraveler.
* (Unfortunately many will run anonymously and untraceably,
* so who could really stop them?)
*
* DISCLAIMER:
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Affero General Public License for
* more details.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
kamH0Y/n11lCvo1oQxM+
=uSzz
-----END PGP SIGNATURE-----
**************************************************************/
#ifndef __OT_SCRIPT_H__
#define __OT_SCRIPT_H__
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif
#ifndef EXPORT
#define EXPORT
#endif
#include <ExportWrapper.h>
#include <string>
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4702 ) // warning C4702: unreachable code
#endif
#include <chaiscript/chaiscript.hpp>
#ifdef OT_USE_CHAI5
#include <chaiscript/chaiscript_stdlib.hpp>
#endif
#ifdef _MSC_VER
#pragma warning( pop )
#endif
#include "OTBylaw.h"
// ------------------------------------------------------------
// A script should be "Dumb", meaning that you just stick it with its
// parties and other resources, and it EXPECTS them to be the correct
// ones. It uses them low-level style.
//
// Any verification should be done at a higher level, in OTSmartContract.
// There, multiple parties might be loaded, as well as multiple scripts
// (clauses) and that is where the proper resources, accounts, etc are
// instantiated and validated before any use.
//
// Thus by the time you get down to OTScript, all that validation is already
// done. The programmatic user will interact with OTSmartContract, likely,
// and not with OTScript itself.
//
class OTScript
{
protected:
std::string m_str_script; // the script itself.
std::string m_str_display_filename; // for error handling, there is option to set this string for display.
mapOfParties m_mapParties; // no need to clean this up. Script doesn't own the parties, just references them.
mapOfPartyAccounts m_mapAccounts; // no need to clean this up. Script doesn't own the accounts, just references them.
mapOfVariables m_mapVariables; // no need to clean this up. Script doesn't own the variables, just references them.
// List
// Construction -- Destruction
public:
OTScript();
OTScript(const OTString & strValue);
OTScript(const char * new_string);
OTScript(const char * new_string, size_t sizeLength);
OTScript(const std::string & new_string);
virtual ~OTScript();
EXPORT void SetScript(const OTString & strValue);
EXPORT void SetScript(const char * new_string);
EXPORT void SetScript(const char * new_string, size_t sizeLength);
EXPORT void SetScript(const std::string & new_string);
void SetDisplayFilename(const std::string str_display_filename)
{ m_str_display_filename = str_display_filename;}
// ---------------------------------------------------
// The same OTSmartContract that loads all the clauses (scripts) will
// also load all the parties, so it will call this function whenever before it
// needs to actually run a script.
//
// NOTE: OTScript does NOT take ownership of the party, since there could be
// multiple scripts (with all scripts and parties being owned by a OTSmartContract.)
// Therefore it's ASSUMED that the owner OTSmartContract will handle all the work of
// cleaning up the mess! theParty is passed as reference to insure it already exists.
//
void AddParty (const std::string str_party_name, OTParty & theParty);
void AddAccount (const std::string str_acct_name, OTPartyAccount & theAcct);
EXPORT void AddVariable (const std::string str_var_name, OTVariable & theVar);
EXPORT void RemoveVariable (OTVariable & theVar);
// Note: any relevant assets or asset accounts are listed by their owner / contributor
// parties. Therefore there's no need to separately input any accounts or assets to
// a script, since the necessary ones are already present inside their respective parties.
virtual bool ExecuteScript(OTVariable * pReturnVar=NULL)=0;
};
#ifndef OT_USE_TR1
typedef std::shared_ptr <OTScript> OTScript_SharedPtr;
typedef std::weak_ptr <OTScript> OTScript_WeakPtr;
#else
typedef std::tr1::shared_ptr <OTScript> OTScript_SharedPtr;
typedef std::tr1::weak_ptr <OTScript> OTScript_WeakPtr;
#endif
typedef std::auto_ptr<OTScript> OTScript_AutoPtr;
// -----------------------------------
EXPORT OTScript_SharedPtr OTScriptFactory(const std::string & script_contents,
const std::string * p_script_type=NULL);
EXPORT OTScript_SharedPtr OTScriptFactory(const std::string * p_script_type=NULL);
// ********************************************************************
//
// SUBCLASS: CHAI SCRIPT
//
// ********************************************************************
class OTScriptChai : public OTScript
{
public:
OTScriptChai();
OTScriptChai(const OTString & strValue);
OTScriptChai(const char * new_string);
OTScriptChai(const char * new_string, size_t sizeLength);
OTScriptChai(const std::string & new_string);
virtual ~OTScriptChai();
virtual bool ExecuteScript(OTVariable * pReturnVar=NULL);
// ------------------------
chaiscript::ChaiScript chai;
};
#ifndef OT_USE_TR1
typedef std::shared_ptr <OTScriptChai> OTScriptChai_SharedPtr;
typedef std::weak_ptr <OTScriptChai> OTScriptChai_WeakPtr;
#else
typedef std::tr1::shared_ptr <OTScriptChai> OTScriptChai_SharedPtr;
typedef std::tr1::weak_ptr <OTScriptChai> OTScriptChai_WeakPtr;
#endif
typedef std::auto_ptr<OTScriptChai> OTScriptChai_AutoPtr;
#if __clang__
#pragma clang diagnostic pop
#endif
// ------------------------------------------------------------------
#endif // __OT_SCRIPT_H__