aboutsummaryrefslogtreecommitdiff
path: root/market.h
blob: 2714787307ba42de51f2c0c502d5879f15f96ac7 (plain)
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
// Copyright (c) 2009 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.

class CUser;
class CReview;
class CProduct;

static const unsigned int nFlowthroughRate = 2;




bool AdvertInsert(const CProduct& product);
void AdvertErase(const CProduct& product);
bool AddAtomsAndPropagate(uint256 hashUserStart, const vector<unsigned short>& vAtoms, bool fOrigin);








class CUser
{
public:
    vector<unsigned short> vAtomsIn;
    vector<unsigned short> vAtomsNew;
    vector<unsigned short> vAtomsOut;
    vector<uint256> vLinksOut;

    CUser()
    {
    }

    IMPLEMENT_SERIALIZE
    (
        if (!(nType & SER_GETHASH))
            READWRITE(nVersion);
        READWRITE(vAtomsIn);
        READWRITE(vAtomsNew);
        READWRITE(vAtomsOut);
        READWRITE(vLinksOut);
    )

    void SetNull()
    {
        vAtomsIn.clear();
        vAtomsNew.clear();
        vAtomsOut.clear();
        vLinksOut.clear();
    }

    uint256 GetHash() const { return SerializeHash(*this); }


    int GetAtomCount() const
    {
        return (vAtomsIn.size() + vAtomsNew.size());
    }

    void AddAtom(unsigned short nAtom, bool fOrigin);
};







class CReview
{
public:
    int nVersion;
    uint256 hashTo;
    map<string, string> mapValue;
    vector<unsigned char> vchPubKeyFrom;
    vector<unsigned char> vchSig;

    // memory only
    unsigned int nTime;
    int nAtoms;


    CReview()
    {
        nVersion = 1;
        hashTo = 0;
        nTime = 0;
        nAtoms = 0;
    }

    IMPLEMENT_SERIALIZE
    (
        READWRITE(this->nVersion);
        nVersion = this->nVersion;
        if (!(nType & SER_DISK))
            READWRITE(hashTo);
        READWRITE(mapValue);
        READWRITE(vchPubKeyFrom);
        if (!(nType & SER_GETHASH))
            READWRITE(vchSig);
    )

    uint256 GetHash() const { return SerializeHash(*this); }
    uint256 GetSigHash() const { return SerializeHash(*this, SER_GETHASH|SER_SKIPSIG); }
    uint256 GetUserHash() const { return Hash(vchPubKeyFrom.begin(), vchPubKeyFrom.end()); }


    bool AcceptReview();
};







class CProduct
{
public:
    int nVersion;
    CAddress addr;
    map<string, string> mapValue;
    map<string, string> mapDetails;
    vector<pair<string, string> > vOrderForm;
    unsigned int nSequence;
    vector<unsigned char> vchPubKeyFrom;
    vector<unsigned char> vchSig;

    // disk only
    int nAtoms;

    // memory only
    set<unsigned int> setSources;

    CProduct()
    {
        nVersion = 1;
        nAtoms = 0;
        nSequence = 0;
    }

    IMPLEMENT_SERIALIZE
    (
        READWRITE(this->nVersion);
        nVersion = this->nVersion;
        READWRITE(addr);
        READWRITE(mapValue);
        if (!(nType & SER_GETHASH))
        {
            READWRITE(mapDetails);
            READWRITE(vOrderForm);
            READWRITE(nSequence);
        }
        READWRITE(vchPubKeyFrom);
        if (!(nType & SER_GETHASH))
            READWRITE(vchSig);
        if (nType & SER_DISK)
            READWRITE(nAtoms);
    )

    uint256 GetHash() const { return SerializeHash(*this); }
    uint256 GetSigHash() const { return SerializeHash(*this, SER_GETHASH|SER_SKIPSIG); }
    uint256 GetUserHash() const { return Hash(vchPubKeyFrom.begin(), vchPubKeyFrom.end()); }


    bool CheckSignature();
    bool CheckProduct();
};








extern map<uint256, CProduct> mapProducts;
extern CCriticalSection cs_mapProducts;
extern map<uint256, CProduct> mapMyProducts;