Repository navigation
Expand file tree
/
Copy pathCommonStruct.h
More file actions
399 lines (312 loc) · 10.5 KB
/
Copy pathCommonStruct.h
File metadata and controls
399 lines (312 loc) · 10.5 KB
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#pragma once
#include <Windows.h>
#include <fstream>
#include <Tlhelp32.h>
#include <shlwapi.h>
#include <afxmt.h >
#pragma comment(lib,"Shlwapi.lib")
#include <string>
#include <vector>
#include "json\json.h"
#include "RpcCmd.h"
#include "RPCDlg.h"
using namespace std;
typedef long long int64_t;
static const ULONGLONG COIN = 100000000;
#define REAL_MONEY(x) static_cast<int64_t>((x)*COIN)
#define BEGIN(a) ((char*)&(a))
#define END(a) ((char*)&((&(a))[1]))
#define WM_SEND_RPC_DATA WM_USER+1
#define WM_SHOW_RECV_DATA WM_USER+2
#define WM_SOCKET_RECEIVE WM_USER+3
#define WM_SOCKET_CLOSE WM_USER+4
#define WM_SOCKET_CONNECT WM_USER+5
#define WM_SHOW_SEND_DATA WM_USER+6
#define WM_UPDATE_HEIGHT WM_USER+7
#define WM_GET_ACCOUNTINFO WM_USER+8
#define WM_LIST_TX WM_USER+9
#define WM_GET_ACCLIST WM_USER+10
#define WM_GET_BET_RANDOM_DATA WM_USER+11
#define WM_UPDATE WM_USER+12
#define WINDOW_TAG _T("Dacrs-UIDemo")
typedef enum
{
emRPCCommand = 1,
emBaseFunction,
emRegisterScript,
emContract,
emGetAccData,
emGetAccountInfo,
emGetRegScriptHash,
emGetRegScriptID,
emGetBetRandomData,
emListTx,
emNoType
}emSendDataType;
#define DEFINE_SINGLETON(cls)\
private:\
static std::auto_ptr<cls> m_pInstance;\
protected:\
cls(){}\
public:\
~cls(){}\
static cls* getInstance(){\
if(!m_pInstance.get()){\
m_pInstance = std::auto_ptr<cls>(new cls());\
}\
return m_pInstance.get();\
}
#define IMPLEMENT_SINGLETON(cls) \
std::auto_ptr<cls> cls::m_pInstance(NULL);
typedef enum
{
emSesureTx=1,
emDarkTx,
emAnonymTx,
emP2PBet,
emLottery,
emNonType,
}emBusinessType;
//权限结构
typedef struct _AUTHORIZATE
{
_AUTHORIZATE()
{
nAuthorizeTime = 0;
nMaxMoneyPerTime = 0;
nMaxMoneyTotal = 0;
nMaxMoneyPerDay = 0;
}
int nAuthorizeTime;
double nMaxMoneyPerTime;
double nMaxMoneyTotal;
double nMaxMoneyPerDay;
string strUserData;
}AUTHORIZATE;
//*****************************担保合约结构************************************
#define ACCOUNT_ID_SIZE 6
#define MAX_ARBITRATOR 3
#define MAX_ACCOUNT_LEN 20
#define HASH_SIZE 32
#pragma pack(1)
typedef enum
{
emFirstStep = 1,
emSecondStep,
emThirdStep,
emLastStep,
emInvalidStep
}enumSesureTrade;
typedef enum
{
emDarkFirstStep = 1,
emDarkSecondStep = 2,
emDarkThirdStep = 3,
emInvalidDarkStep
}enumDarkTx;
typedef enum
{
emP2PBetASend = 1,
emP2PBetBAccept,
emP2PBetAExpose,
emP2PBetBExpose,
emInvalidP2PBet
}enumP2PBet;
typedef struct tag_INT64 {
unsigned char data[8];
} Int64;
typedef struct tagACCOUNT_ID
{
char accounid[ACCOUNT_ID_SIZE];
}ACCOUNT_ID;
typedef struct {
unsigned char nType; //!<类型
unsigned char nArbitratorCount; //!<仲裁者个数
ACCOUNT_ID buyer; //!<买家ID(采用6字节的账户ID)
ACCOUNT_ID seller; //!<卖家ID(采用6字节的账户ID)
ACCOUNT_ID arbitrator[MAX_ARBITRATOR]; //!<仲裁者ID(采用6字节的账户ID)
long nHeight; //!<超时绝对高度
Int64 nFineMoney; //!<卖家违约后最大罚款金额
Int64 nPayMoney; //!<买家向卖家支付的金额
Int64 nFee; //!<仲裁手续费
Int64 ndeposit; //!<仲裁押金,申诉时从仲裁者扣除的押金(如果仲裁不响应钱归买家否则买家退还给仲裁者)
}FIRST_CONTRACT;
typedef struct {
unsigned char nType; //!<交易类型
unsigned char hash[HASH_SIZE]; //!<上一个交易包的哈希
} NEXT_CONTRACT;
typedef struct {
unsigned char nType; //!<交易类型
unsigned char hash[HASH_SIZE]; //!<上一个交易的哈希
Int64 nMinus;
}ARBIT_RES_CONTRACT;
//暗黑币
typedef struct {
unsigned char dnType; //!<类型
char buyer[6]; //!<买家ID(采用6字节的账户ID)
char seller[6]; //!<卖家ID(采用6字节的账户ID)
int nHeight; //!<超时绝对高度
ULONGLONG nPayMoney; //!<买家向卖家支付的金额
}DARK_FIRST_CONTRACT;
typedef struct {
unsigned char dnType; //!<交易类型
char hash[32]; //!<上一个交易包的哈希
}DARK_NEXT_CONTRACT;
//匿名交易
typedef struct
{
char account[6]; //!<接受钱的ID(采用6字节的账户ID)
ULONGLONG nReciMoney; //!< 收到钱的金额
} ACCOUNT_INFO;
struct BASE_ANONYM_CONTRACT
{
char szSender[6]; //!<转账人ID(采用6字节的账户ID)
int nHeight; //!<超时绝对高度
ULONGLONG nPayMoney; //!<转账的人支付的金额
unsigned short len; //!<接受钱账户信息长度
};
struct ANONYM_CONTRACT:public BASE_ANONYM_CONTRACT
{
vector<ACCOUNT_INFO> vAccInfo;
};
//P2P赌博
typedef struct {
unsigned char type;
ULONGLONG money;
int hight;
unsigned char dhash[32];
} SEND_DATA;
typedef struct {
unsigned char type;
ULONGLONG money;
unsigned char targetkey[32]; //发起对赌的哈希,也是对赌数据的关键字
unsigned char data[5];
} ACCEPT_DATA;
typedef struct {
unsigned char type;
unsigned char targetkey[32]; //发起对赌的哈希,也是对赌数据的关键字
unsigned char dhash[5];
} OPEN_DATA;
//彩票
typedef struct {
unsigned char type;
ULONGLONG money;
int hight;
}REG_DATA;
typedef struct {
unsigned char type;
unsigned char num[15];
unsigned char numlen;
ULONGLONG money;
}ORDER_DATA;
typedef struct {
unsigned char type;
}DRAW_DATA;
#pragma pack()
const signed char p_util_hexdigit[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0xa, 0xb, 0xc, 0xd, 0xe,
0xf, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, };
inline signed char HexDigit(char c)
{
return p_util_hexdigit[(unsigned char)c];
}
class CSoyPayHelp
{
DEFINE_SINGLETON(CSoyPayHelp)
static const int REG_ID_SIZE = 6;
CRPCDlg* m_pRPCDlg;
CRpcCmd mRpcCmd;
private:
CStringA ParseRecvData(const char*pRecvData);
public:
void InitialRpcCmd(CRPCDlg * pdlg,const CStringA &sendPreHeadstr,const CStringA &sendendHeadstr)
{
mRpcCmd.SetHeadString(sendPreHeadstr,sendendHeadstr);
m_pRPCDlg = pdlg;
}
int SendRpc(CString cmd,CStringA &rev);
string GetReverseHash(const string& strHash);
string GetHexData(const char*pData,size_t nLen);
string ParseTxHashFromJson(const string& strJsonData);
string ParseScriptIDFromJson(const string& strJsonData);
string EncodeBase64(const unsigned char* pch, size_t len);
string EncodeBase64(const string& str);
string CreateContractTx(const string& strScript,const vector<string>& vAddr,const string& strContract,
int nHeight,int64_t nFee);
string SignContractTx(const string& strRawTxHash);
string CreateScriptTx(const char* pAccount,bool bPath,const char* pScript,int64_t nFee,int nHeight,
int nAuthTime=0,int64_t nMoneyPerTime=0,int64_t nMoneyTotal=0,int64_t nMoneyPerDay=0,const string& strUserData="");
string CreateScriptAccountTx(const char* pAccount,int64_t nFee,bool bIsMiner);
string CreateNomalTx(const char* pFrom,const char* pTo,int64_t nMoney,int64_t nFee,int nHeight);
bool GetErrorMsg(const string& strRecvData,string& strErrorMsg);
string Setgenerate(bool bStart);
string GetFullRegID(const string& strRegID);
template<typename T>
std::string HexStr(const T itbegin, const T itend, bool fSpaces = false);
template<typename T>
inline std::string HexStr(const T& vch, bool fSpaces = false);
vector<unsigned char> ParseHex(const char* psz);
vector<unsigned char> ParseHex(const string& str);
};
//*******************************担保交易************************************************
class CSesureTradeHelp
{
public:
string PacketFirstContract(const string& strBuyID,const string& strSellID,const vector<string>& vArRegID,
int nHeight,int64_t nFine,int64_t nPay,int64_t nFee,int64_t ndeposit);
string PacketSecondContract(unsigned char* pHash);
string PacketThirdContract(unsigned char* pHash);
string PacketLastContract(unsigned char* pHash,int64_t nFine);
private:
FIRST_CONTRACT m_FirstContract;
NEXT_CONTRACT m_SecondContract;
NEXT_CONTRACT m_ThirdContract;
ARBIT_RES_CONTRACT m_LastContract;
};
//********************************暗黑币************************************
class CDarkTxHelp
{
public:
string PacketFirstContract(const string& strBuyID,const string& strSellID,int64_t nMoney,int nHeight);
string PacketNextContract(const string& strTxHash);
private:
DARK_FIRST_CONTRACT m_FirstContract;
DARK_NEXT_CONTRACT m_NextContract;
};
//********************************匿名交易************************************
class CAnonymTxHelp
{
public:
string PackAnonymContract(const string& strSender,int nSendMoney,const vector<string>& vRecv,int nHeight);
private:
ANONYM_CONTRACT m_anonymContract;
};
//********************************P2P对赌************************************
class CP2PBetHelp
{
public:
string PacketP2PSendContract(int64_t nMoney,int nHeight,const string& strRandomHash);
string PacketP2PAcceptContract(int64_t nMoney,const string& strSendHash,char* pData);
string PacketP2PExposeContract(const string& SendHash,const string& strRandomHash);
private:
SEND_DATA m_sendContract;
ACCEPT_DATA m_acceptContract;
OPEN_DATA m_openContract;
};
extern void ProductHttpHead(const CStringA& configdir,const string& strCfgFileName,CStringA &strPort,CStringA& strPreHeadstr,CStringA& strendHeadstr);
extern void RPCCommandToJson(const CString& strRPCCommand,CStringA& strSendData);
extern void ParseJsonAddrToMap(const CStringA& strValue,map<CString,CString>& mapAccount);
extern CStringA ParseRecvData(const char*pRecvData);
extern void Setgenerate(bool bStart);
extern string GetFullRegID(const CString& strRegID);
extern CString GetCompressRegID(const CString& strRegID);
extern void SendRPCData(const string& strData,emSendDataType emType);
extern bool CheckRegIDValid(const CString& strRegID);
extern bool CheckHash(const CString& strRegID);