]> Git Repo - VerusCoin.git/blob - src/cc/eval.h
tests for getting MoM in Eval and fixes
[VerusCoin.git] / src / cc / eval.h
1 #ifndef CC_EVAL_H
2 #define CC_EVAL_H
3
4 #include <cryptoconditions.h>
5
6 #include "chain.h"
7 #include "streams.h"
8 #include "version.h"
9 #include "consensus/validation.h"
10 #include "primitives/transaction.h"
11
12
13 class AppVM;
14 class NotarisationData;
15
16
17 class Eval
18 {
19 public:
20     CValidationState state;
21
22     bool Invalid(std::string s) { return state.Invalid(false, 0, s); }
23     bool Error(std::string s) { return state.Error(s); }
24     bool Valid() { return true; }
25
26     /*
27      * Test validity of a CC_Eval node
28      */
29     virtual bool Dispatch(const CC *cond, const CTransaction &tx, unsigned int nIn);
30
31     /*
32      * Dispute a payout using a VM
33      */
34     bool DisputePayout(AppVM &vm, const CC *cond, const CTransaction &disputeTx, unsigned int nIn);
35
36     /*
37      * Test an ImportPayout CC Eval condition
38      */
39     bool ImportPayout(const CC *cond, const CTransaction &payoutTx, unsigned int nIn);
40
41     /*
42      * IO functions
43      */
44     virtual bool GetTx(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow) const;
45     virtual unsigned int GetCurrentHeight() const;
46     virtual bool GetSpends(uint256 hash, std::vector<CTransaction> &spends) const;
47     virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const;
48     virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const;
49     virtual bool GetNotarisationData(uint256 notarisationHash, NotarisationData &data) const;
50     virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const;
51 };
52
53
54 bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn);
55
56
57 /*
58  * Virtual machine to use in the case of on-chain app evaluation
59  */
60 class AppVM
61
62 public:
63     /*
64      * in:  header   - paramters agreed upon by all players
65      * in:  body     - gamestate
66      * out: length   - length of game (longest wins)
67      * out: payments - vector of CTxOut, always deterministically sorted.
68      */
69     virtual std::pair<int,std::vector<CTxOut>>
70         evaluate(std::vector<unsigned char> header, std::vector<unsigned char> body) = 0;
71 };
72
73
74 /*
75  * Data from notarisation OP_RETURN
76  */
77 class NotarisationData {
78 public:
79     uint256 blockHash;
80     uint32_t height;
81     uint256 txHash;
82     char symbol[64];
83     uint256 MoM;
84     uint32_t MoMDepth;
85
86     bool Parse(CScript scriptPubKey);
87 };
88
89
90 /*
91  * Serialisation boilerplate
92  */
93 template <class T>
94 std::vector<unsigned char> CheckSerialize(T &in)
95 {
96     CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
97     ss << in;
98     return std::vector<unsigned char>(ss.begin(), ss.end());
99 }
100
101 template <class T>
102 bool CheckDeserialize(std::vector<unsigned char> vIn, T &out)
103 {
104     CDataStream ss(vIn, SER_NETWORK, PROTOCOL_VERSION);
105     try {
106          ss >> out;
107         if (ss.eof()) return true;
108     } catch(...) {}
109     return false;
110 }
111
112
113 #endif /* CC_EVAL_H */
This page took 0.030681 seconds and 4 git commands to generate.