|
1 | 1 | #pragma once |
2 | | -#include "network_messages/common_def.h" |
3 | | -#include "platform/m256.h" |
4 | 2 |
|
5 | 3 | ////////// Smart contracts \\\\\\\\\\ |
6 | 4 |
|
|
10 | 8 | // Additionally, most types, functions, and variables of the core have to be defined after including |
11 | 9 | // the contract to keep them unavailable in the contract code. |
12 | 10 |
|
13 | | -namespace QPI |
14 | | -{ |
15 | | - struct QpiContextProcedureCall; |
16 | | - struct QpiContextFunctionCall; |
17 | | -} |
18 | | - |
19 | | -// TODO: add option for having locals to SYSTEM and EXPAND procedures |
20 | | -typedef void (*SYSTEM_PROCEDURE)(const QPI::QpiContextProcedureCall&, void* state, void* input, void* output, void* locals); |
21 | | -typedef void (*EXPAND_PROCEDURE)(const QPI::QpiContextFunctionCall&, void*, void*); // cannot not change anything except state |
22 | | -typedef void (*USER_FUNCTION)(const QPI::QpiContextFunctionCall&, void* state, void* input, void* output, void* locals); |
23 | | -typedef void (*USER_PROCEDURE)(const QPI::QpiContextProcedureCall&, void* state, void* input, void* output, void* locals); |
24 | | - |
25 | | -constexpr unsigned long long MAX_CONTRACT_STATE_SIZE = 1073741824; |
26 | | - |
27 | | -// Maximum size of local variables that may be used by a contract function or procedure |
28 | | -// If increased, the size of contractLocalsStack should be increased as well. |
29 | | -constexpr unsigned int MAX_SIZE_OF_CONTRACT_LOCALS = 32 * 1024; |
30 | | - |
31 | | -// TODO: make sure the limit of nested calls is not violated |
32 | | -constexpr unsigned short MAX_NESTED_CONTRACT_CALLS = 10; |
33 | | - |
34 | | -// Size of the contract action tracker, limits the number of transfers that one contract call can execute. |
35 | | -constexpr unsigned long long CONTRACT_ACTION_TRACKER_SIZE = 16 * 1024 * 1024; |
36 | | - |
37 | | - |
38 | | -static void __beginFunctionOrProcedure(const unsigned int); // TODO: more human-readable form of function ID? |
39 | | -static void __endFunctionOrProcedure(const unsigned int); |
40 | | -template <typename T> static m256i __K12(T); |
41 | | -template <typename T> static void __logContractDebugMessage(unsigned int, T&); |
42 | | -template <typename T> static void __logContractErrorMessage(unsigned int, T&); |
43 | | -template <typename T> static void __logContractInfoMessage(unsigned int, T&); |
44 | | -template <typename T> static void __logContractWarningMessage(unsigned int, T&); |
45 | | -static void* __scratchpad(); // TODO: concurrency support (n buffers for n allowed concurrent contract executions) |
46 | | -// static void* __tryAcquireScratchpad(unsigned int size); // Thread-safe, may return nullptr if no appropriate buffer is available |
47 | | -// static void __ReleaseScratchpad(void*); |
48 | | - |
49 | | -template <unsigned int functionOrProcedureId> |
50 | | -struct __FunctionOrProcedureBeginEndGuard |
51 | | -{ |
52 | | - // Constructor calling __beginFunctionOrProcedure() |
53 | | - __FunctionOrProcedureBeginEndGuard() |
54 | | - { |
55 | | - __beginFunctionOrProcedure(functionOrProcedureId); |
56 | | - } |
57 | | - |
58 | | - // Destructor making sure __endFunctionOrProcedure() is called for every return path |
59 | | - ~__FunctionOrProcedureBeginEndGuard() |
60 | | - { |
61 | | - __endFunctionOrProcedure(functionOrProcedureId); |
62 | | - } |
63 | | -}; |
64 | | - |
65 | 11 |
|
66 | 12 | // With no other includes before, the following are the only headers available to contracts. |
67 | 13 | // When adding something, be cautious to keep access of contracts limited to safe features only. |
| 14 | +#include "pre_qpi_def.h" |
68 | 15 | #include "contracts/qpi.h" |
69 | 16 | #include "qpi_proposal_voting.h" |
70 | 17 |
|
@@ -222,7 +169,11 @@ struct __FunctionOrProcedureBeginEndGuard |
222 | 169 | #define CONTRACT_INDEX RL_CONTRACT_INDEX |
223 | 170 | #define CONTRACT_STATE_TYPE RL |
224 | 171 | #define CONTRACT_STATE2_TYPE RL2 |
225 | | -#include "contracts/RandomLottery.h" |
| 172 | +#ifdef RL_V1 |
| 173 | + #include "contracts/RandomLottery_v1.h" |
| 174 | +#else |
| 175 | + #include "contracts/RandomLottery.h" |
| 176 | +#endif |
226 | 177 |
|
227 | 178 | #undef CONTRACT_INDEX |
228 | 179 | #undef CONTRACT_STATE_TYPE |
@@ -283,6 +234,8 @@ constexpr unsigned short TESTEXD_CONTRACT_INDEX = (CONTRACT_INDEX + 1); |
283 | 234 | #undef POST_RELEASE_SHARES |
284 | 235 | #undef POST_ACQUIRE_SHARES |
285 | 236 | #undef POST_INCOMING_TRANSFER |
| 237 | +#undef SET_SHAREHOLDER_PROPOSAL |
| 238 | +#undef SET_SHAREHOLDER_VOTES |
286 | 239 |
|
287 | 240 |
|
288 | 241 | // The following are included after the contracts to keep their definitions and dependencies |
@@ -336,8 +289,8 @@ constexpr struct ContractDescription |
336 | 289 | {"QBOND", 182, 10000, sizeof(QBOND)}, // proposal in epoch 180, IPO in 181, construction and first use in 182 |
337 | 290 | // new contracts should be added above this line |
338 | 291 | #ifdef INCLUDE_CONTRACT_TEST_EXAMPLES |
339 | | - {"TESTEXA", 138, 10000, sizeof(IPO)}, |
340 | | - {"TESTEXB", 138, 10000, sizeof(IPO)}, |
| 292 | + {"TESTEXA", 138, 10000, sizeof(TESTEXA)}, |
| 293 | + {"TESTEXB", 138, 10000, sizeof(TESTEXB)}, |
341 | 294 | {"TESTEXC", 138, 10000, sizeof(IPO)}, |
342 | 295 | {"TESTEXD", 155, 10000, sizeof(IPO)}, |
343 | 296 | #endif |
@@ -377,6 +330,8 @@ enum SystemProcedureID |
377 | 330 | POST_RELEASE_SHARES, |
378 | 331 | POST_ACQUIRE_SHARES, |
379 | 332 | POST_INCOMING_TRANSFER, |
| 333 | + SET_SHAREHOLDER_PROPOSAL, |
| 334 | + SET_SHAREHOLDER_VOTES, |
380 | 335 | contractSystemProcedureCount, |
381 | 336 | }; |
382 | 337 |
|
@@ -414,6 +369,10 @@ if (!contractName::__postReleaseSharesEmpty) contractSystemProcedures[contractIn |
414 | 369 | contractSystemProcedureLocalsSizes[contractIndex][POST_RELEASE_SHARES] = contractName::__postReleaseSharesLocalsSize; \ |
415 | 370 | if (!contractName::__postIncomingTransferEmpty) contractSystemProcedures[contractIndex][POST_INCOMING_TRANSFER] = (SYSTEM_PROCEDURE)contractName::__postIncomingTransfer;\ |
416 | 371 | contractSystemProcedureLocalsSizes[contractIndex][POST_INCOMING_TRANSFER] = contractName::__postIncomingTransferLocalsSize; \ |
| 372 | +if (!contractName::__setShareholderProposalEmpty) contractSystemProcedures[contractIndex][SET_SHAREHOLDER_PROPOSAL] = (SYSTEM_PROCEDURE)contractName::__setShareholderProposal;\ |
| 373 | +contractSystemProcedureLocalsSizes[contractIndex][SET_SHAREHOLDER_PROPOSAL] = contractName::__setShareholderProposalLocalsSize; \ |
| 374 | +if (!contractName::__setShareholderVotesEmpty) contractSystemProcedures[contractIndex][SET_SHAREHOLDER_VOTES] = (SYSTEM_PROCEDURE)contractName::__setShareholderVotes;\ |
| 375 | +contractSystemProcedureLocalsSizes[contractIndex][SET_SHAREHOLDER_VOTES] = contractName::__setShareholderVotesLocalsSize; \ |
417 | 376 | if (!contractName::__expandEmpty) contractExpandProcedures[contractIndex] = (EXPAND_PROCEDURE)contractName::__expand;\ |
418 | 377 | QpiContextForInit qpi(contractIndex); \ |
419 | 378 | contractName::__registerUserFunctionsAndProcedures(qpi); \ |
|
0 commit comments