forked from zeepin/GCPs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCP501(STO_Modified)Sample.c
More file actions
653 lines (583 loc) · 22.2 KB
/
GCP501(STO_Modified)Sample.c
File metadata and controls
653 lines (583 loc) · 22.2 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
//system apis
void * calloc(int count,int length);
void * malloc(int size);
int arrayLen(void *a);
int memcpy(void * dest,void * src,int length);
int memset(void * dest,char c,int length);
//utility apis
int strcmp(char *a,char *b);
char * strconcat(char *a,char *b);
int Atoi(char * s);
long long Atoi64(char *s);
char * Itoa(int a);
char * I64toa(long long amount,int radix);
char * SHA1(char *s);
char * SHA256(char *s);
//parameter apis
int ZPT_ReadInt32Param(char *args);
long long ZPT_ReadInt64Param(char * args);
char * ZPT_ReadStringParam(char * args);
void ZPT_JsonUnmashalInput(void * addr,int size,char * arg);
char * ZPT_JsonMashalResult(void * val,char * types,int succeed);
char * ZPT_JsonMashalParams(void * s);
char * ZPT_RawMashalParams(void *s);
char * ZPT_GetCallerAddress();
char * ZPT_GetSelfAddress();
char * ZPT_CallContract(char * address,char * contractCode,char * method,char * args);
char * ZPT_MarshalNativeParams(void * s);
char * ZPT_MarshalNeoParams(void * s);
//Runtime apis
int ZPT_Runtime_CheckWitness(char * address);
void ZPT_Runtime_Notify(char * address);
int ZPT_Runtime_CheckSig(char * pubkey,char * data,char * sig);
int ZPT_Runtime_GetTime();
void ZPT_Runtime_Log(char * message);
//Attribute apis
int ZPT_Attribute_GetUsage(char * data);
char * ZPT_Attribute_GetData(char * data);
//Block apis
char * ZPT_Block_GetCurrentHeaderHash();
int ZPT_Block_GetCurrentHeaderHeight();
char * ZPT_Block_GetCurrentBlockHash();
int ZPT_Block_GetCurrentBlockHeight();
char * ZPT_Block_GetTransactionByHash(char * hash);
int * ZPT_Block_GetTransactionCountByBlkHash(char * hash);
int * ZPT_Block_GetTransactionCountByBlkHeight(int height);
char ** ZPT_Block_GetTransactionsByBlkHash(char * hash);
char ** ZPT_Block_GetTransactionsByBlkHeight(int height);
//Blockchain apis
int ZPT_BlockChain_GetHeight();
char * ZPT_BlockChain_GetHeaderByHeight(int height);
char * ZPT_BlockChain_GetHeaderByHash(char * hash);
char * ZPT_BlockChain_GetBlockByHeight(int height);
char * ZPT_BlockChain_GetBlockByHash(char * hash);
char * ZPT_BlockChain_GetContract(char * address);
//header apis
char * ZPT_Header_GetHash(char * data);
int ZPT_Header_GetVersion(char * data);
char * ZPT_Header_GetPrevHash(char * data);
char * ZPT_Header_GetMerkleRoot(char * data);
int ZPT_Header_GetIndex(char * data);
int ZPT_Header_GetTimestamp(char * data);
long long ZPT_Header_GetConsensusData(char * data);
char * ZPT_Header_GetNextConsensus(char * data);
//storage apis
void ZPT_Storage_Put(char * key,char * value);
char * ZPT_Storage_Get(char * key);
void ZPT_Storage_Delete(char * key);
//transaction apis
char * ZPT_Transaction_GetHash(char * data);
int ZPT_Transaction_GetType(char * data);
char * ZPT_Transaction_GetAttributes(char * data);
char * mark = "\"";
char * comma = "\,";
char * firstbracket = "\[";
char * lastbracket = "\]";
char * actionMarshal(char * action, char * str_1, char * str_2, char * str_3){
char * str1 = firstbracket;
char * str2;
str2 = strconcat(str1,mark);
str1 = strconcat(str2,action);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,comma);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,str_1);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,comma);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,str_2);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,comma);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,str_3);
str2 = strconcat(str1,mark);
str1 = strconcat(str2,lastbracket);
return str1;
}
//Find how many times a character occurs in an array
int count(char * a){
int len = arrayLen(a);
int cnt = 0;
for(int i = 0; i < len; i++){
if(a[i] == '{')
cnt++;
}
cnt--;
return cnt;
}
//Joint two arrays
char * concat(char * a, char * b){
int lena = arrayLen(a);
int lenb = arrayLen(b);
char * res = (char *)malloc((lena + lenb)*sizeof(char));
for (int i = 0 ;i < lena ;i++){
res[i] = a[i];
}
for (int j = 0; j < lenb ;j++){
res[lena + j] = b[j];
}
return res;
}
char * symbol = "ZUSD";
char * ceoAddress = "ZEuzshrCsE1cnvPuuRrDYgnVYNDtyt5d3X";
char * adminAddress = "ZNEo7CMRpQXGDgSwvhm2iDGPTXhVRJcMfc";
//Check if an account is in the database
int isStored(char * key){
if (arrayLen(ZPT_Storage_Get(key)) == 0)
return 0;
return 1;
}
//Check if an account is appreved by another one
int isApproved(char * owner, char * spender){
char * allowedKey = concat(owner, spender);
if (arrayLen(ZPT_Storage_Get(allowedKey)) == 0)
return 0;
return 1;
}
//Pause the contract to stop increaseTotal, decreaseTotal, transfer, transferFrom and approve methods
char * pause(){
if (Atoi(ZPT_Storage_Get("paused")) == 1)
return "The contract has already been paused.";
if (ZPT_Runtime_CheckWitness(ceoAddress) == 0)
return "You have no permission to pause the contract.";
ZPT_Storage_Put("paused", "1");
return "The cantract is paused successfully.";
}
//Unpause the contract which is paused.
char * unPause(){
if (Atoi(ZPT_Storage_Get("paused")) == 0)
return "No need to unpause because the contract is not under pause situation.";
if (ZPT_Runtime_CheckWitness(ceoAddress) == 0)
return "You have no permission to unpause the contract.";
ZPT_Storage_Put("paused", "0");
return "The cantract is unpaused successfully.";
}
//Initialize the contract, includes the totalSupply value.
char * init(char * totalSupply){
if (arrayLen(ZPT_Storage_Get("totalSupply")) != 0)
return "Already initialized.";
if (ZPT_Runtime_CheckWitness(ceoAddress) == 0)
return "You have no permission to init.";
if (Atoi(totalSupply) <= 0)
return "The totalsupply can not be less than or equal to 0.";
ZPT_Storage_Put("totalSupply", totalSupply);
ZPT_Storage_Put(ceoAddress, totalSupply);
ZPT_Storage_Put("paused", "0");
return "Init success!";
}
char * totalSupply(){
char * total_supply = ZPT_Storage_Get("totalSupply");
if (arrayLen(total_supply) == 0)
return "Please init first.";
return total_supply;
}
char * increaseTotal(char * valueChar){
if (Atoi(ZPT_Storage_Get("paused")) == 1)
return "The contract has been paused.";
if ((ZPT_Runtime_CheckWitness(ceoAddress) == 0) && (ZPT_Runtime_CheckWitness(adminAddress) == 0))
return "You have no permission to increase the totalSupply.";
char * totalSupply = ZPT_Storage_Get("totalSupply");
if (arrayLen(totalSupply) == 0)
return "Please init first.";
int value = Atoi(valueChar);
if (value <= 0)
return "The value increased can not be less than or equal to 0.";
int totalSupplyNew = Atoi(totalSupply) + value;
int ceoBalance = Atoi(ZPT_Storage_Get(ceoAddress)) + value;
ZPT_Storage_Put("totalSupply", Itoa(totalSupplyNew));
ZPT_Storage_Put(ceoAddress, Itoa(ceoBalance));
return actionMarshal("increaseTotal","-",ceoAddress,valueChar);
}
char * decreaseTotal(char * valueChar){
if (Atoi(ZPT_Storage_Get("paused")) == 1)
return "The contract has been paused.";
if ((ZPT_Runtime_CheckWitness(ceoAddress) == 0) && (ZPT_Runtime_CheckWitness(adminAddress) == 0))
return "You have no permission to decrease the totalSupply.";
char * totalSupplyChar = ZPT_Storage_Get("totalSupply");
if (arrayLen(totalSupplyChar) == 0)
return "Please init first.";
int value = Atoi(valueChar);
if (value <= 0)
return "The value decreased can not be less than or equal to 0.";
int totalSupply = Atoi(totalSupplyChar);
if (totalSupply <= value)
return "The value decreased must be less than the current totalSupply.";
int ceoBalance = Atoi(ZPT_Storage_Get(ceoAddress));
if (ceoBalance < value)
return "Admin balance is not enough to support the totalSupply decrease.";
int totalSupplyNew = totalSupply - value;
ceoBalance -= value;
ZPT_Storage_Put("totalSupply", Itoa(totalSupplyNew));
ZPT_Storage_Put(ceoAddress, Itoa(ceoBalance));
return actionMarshal("decreaseTotal","-",ceoAddress,valueChar);
}
char * balanceOf(char * address){
char * balance = ZPT_Storage_Get(address);
if (arrayLen(balance) == 0)
return "Address is not in our database.";
return balance;
}
char * approve(char * ownerAddr, char * spenderAddr, char * allowedChar){
if (Atoi(ZPT_Storage_Get("paused")) == 1)
return "The contract has been paused.";
if (arrayLen(ZPT_Storage_Get("totalSupply")) == 0)
return "Please init first.";
if (ZPT_Runtime_CheckWitness(ownerAddr) == 0)
return "Inconsistent address.";
if (isStored(ownerAddr) == 0)
return "Owner address is not in our database.";
int allowed = Atoi(allowedChar);
if (allowed <= 0)
return "The allowance can not be less than or equal to 0.";
int balance_owner = Atoi(ZPT_Storage_Get(ownerAddr));
if (balance_owner < allowed)
return "The allowance can not be larger than the balance of owner.";
char * allowedKey = concat(ownerAddr, spenderAddr);
ZPT_Storage_Put(allowedKey, Itoa(allowed));
return actionMarshal("approve",ownerAddr,spenderAddr,allowedChar);
}
char * allowance(char * ownerAddr, char * spenderAddr){
if (isStored(ownerAddr) == 0)
return "Owner address is not in our database.";
if (isApproved(ownerAddr, spenderAddr) == 0)
return "Not approved yet.";
char * allowedKey = concat(ownerAddr, spenderAddr);
return ZPT_Storage_Get(allowedKey);
}
///////////////////// STO 新增功能 /////////////////////
//设置账户为正常状态
char * setNormal(char * address){
if ((ZPT_Runtime_CheckWitness(ceoAddress) == 0) && (ZPT_Runtime_CheckWitness(adminAddress) == 0))
return "You have no permission to set account normal.";
char * addrStatus = concat(address, "status");
ZPT_Storage_Delete(addrStatus);
return "Set account normal success";
}
//设置黑名单
char * setBlack(char * address){
if ((ZPT_Runtime_CheckWitness(ceoAddress) == 0) && (ZPT_Runtime_CheckWitness(adminAddress) == 0))
return "You have no permission to set account black.";
char * addrStatus = concat(address, "status");
ZPT_Storage_Put(addrStatus, "1");
return "Set account black success.";
}
//冻结账户
char * setFrozen(char * address){
if ((ZPT_Runtime_CheckWitness(ceoAddress) == 0) && (ZPT_Runtime_CheckWitness(adminAddress) == 0))
return "You have no permission to freeze an account.";
char * addrStatus = concat(address, "status");
ZPT_Storage_Put(addrStatus, "2");
return "Set account frozen success";
}
//返回账户状态
char * status(char * address){
char * addrStatus = concat(address, "status");
if (Atoi(ZPT_Storage_Get(addrStatus)) == 1)
return "black";
if (Atoi(ZPT_Storage_Get(addrStatus)) == 2)
return "frozen";
return "normal";
}
//转账限制的判断函数
int detectTransferRestriction(char * from, char * to){
if (strcmp(status(from),"black") ==0)
return 1;
if (strcmp(status(from),"frozen") ==0)
return 2;
if (strcmp(status(to),"black") == 0)
return 3;
return 0;
}
//判断结果的解释函数
char * messageForTransferRestriction(int restrictionCode){
if (restrictionCode == 1)
return "Sender is in blacklist.";
if (restrictionCode == 2)
return "Sender account has been frozen.";
if (restrictionCode == 3)
return "Receiver is in blacklist.";
return "Unknown account check error.";
}
//在transfer和transferFrom中添加合规检查
char * transfer(char * fromAddr, char * toAddr, char * amountChar){
//合规检查
int restrictionCode = detectTransferRestriction(fromAddr, toAddr);
if (restrictionCode != 0)
return messageForTransferRestriction(restrictionCode);
//////////
if (Atoi(ZPT_Storage_Get("paused")) == 1)
return "The contract has been paused.";
if (arrayLen(ZPT_Storage_Get("totalSupply")) == 0)
return "Please init first.";
if (ZPT_Runtime_CheckWitness(fromAddr) == 0)
return "Inconsistent address.";
if (isStored(fromAddr) == 0)
return "Sender address is not in our database.";
int amount = Atoi(amountChar);
if (amount <= 0)
return "Transfer amount cannot be less than or equal to 0.";
int balance_from = Atoi(ZPT_Storage_Get(fromAddr));
if (balance_from < amount)
return "No sufficient balance.";
balance_from -= amount;
if (balance_from == 0)
ZPT_Storage_Delete(fromAddr);
else
ZPT_Storage_Put(fromAddr,Itoa(balance_from));
int balance_to = Atoi(ZPT_Storage_Get(toAddr));
balance_to += amount;
ZPT_Storage_Put(toAddr,Itoa(balance_to));
return actionMarshal("transfer",fromAddr,toAddr,amountChar);
}
char * transferFrom(char *fromAddr, char *spenderAddr, char *toAddr, char *amountChar){
//合规检查
int restrictionCode = detectTransferRestriction(fromAddr, toAddr);
if (restrictionCode != 0)
return messageForTransferRestriction(restrictionCode);
//////////
if (Atoi(ZPT_Storage_Get("paused")) == 1)
return "The contract has been paused.";
if (arrayLen(ZPT_Storage_Get("totalSupply")) == 0)
return "Please init first.";
if (ZPT_Runtime_CheckWitness(spenderAddr) == 0)
return "Inconsistent address.";
if (isStored(fromAddr) == 0)
return "Sender address is not in our database.";
if (isApproved(fromAddr, spenderAddr) == 0)
return "Not approved.";
int amount = Atoi(amountChar);
if (amount <= 0)
return "TransferFrom amount cannot be less than or equal to 0.";
int balance_from = Atoi(ZPT_Storage_Get(fromAddr));
if (balance_from < amount)
return "No sufficient balance.";
char * allowedKey = concat(fromAddr, spenderAddr);
int allowed = Atoi(ZPT_Storage_Get(allowedKey));
if (allowed < amount)
return "No sufficient allowance.";
balance_from -= amount;
if (balance_from == 0) {
ZPT_Storage_Delete(fromAddr);
ZPT_Storage_Delete(allowedKey);
}
else
ZPT_Storage_Put(fromAddr,Itoa(balance_from));
int balance_to = Atoi(ZPT_Storage_Get(toAddr));
balance_to += amount;
ZPT_Storage_Put(toAddr,Itoa(balance_to));
allowed -= amount;
if (allowed == 0)
ZPT_Storage_Delete(allowedKey);
else
ZPT_Storage_Put(allowedKey, Itoa(allowed));
return actionMarshal("transferFrom",fromAddr,toAddr,amountChar);
}
char * invoke(char * method,char * args){
char * result;
if (strcmp(method, "getSymbol")==0){
ZPT_Runtime_Notify(symbol);
return symbol;
}
if (strcmp(method, "getCeoAddress")==0){
ZPT_Runtime_Notify(ceoAddress);
return ceoAddress;
}
if (strcmp(method, "getAdminAddress")==0){
ZPT_Runtime_Notify(adminAddress);
return adminAddress;
}
if (strcmp(method ,"pause")==0){
result = pause();
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method ,"unPause")==0){
result = unPause();
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method ,"init")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * totalSupply;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = init(p->totalSupply);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "totalSupply")==0){
result = totalSupply();
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "increaseTotal")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * value;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = increaseTotal(p->value);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "decreaseTotal")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * value;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = decreaseTotal(p->value);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "balanceOf")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * address;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = balanceOf(p->address);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "status")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * address;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = status(p->address);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "setNormal")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * address;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = setNormal(p->address);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "setBlack")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * address;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = setBlack(p->address);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "setFrozen")==0){
if(count(args) != 1){
ZPT_Runtime_Notify("The number of params is incorrect. Please input one param.");
return "The number of params is incorrect. Please input one param.";
}
struct Params{
char * address;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = setFrozen(p->address);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "transfer")==0){
if(count(args) != 3){
ZPT_Runtime_Notify("The number of params is incorrect. Please input three params.");
return "The number of params is incorrect. Please input three params.";
}
struct Params{
char * from;
char * to;
char * amount;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = transfer(p->from, p->to, p->amount);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "transferFrom")==0){
if(count(args) != 4){
ZPT_Runtime_Notify("The number of params is incorrect. Please input four params.");
return "The number of params is incorrect. Please input four params.";
}
struct Params{
char * from;
char * spender;
char * to;
char * amount;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = transferFrom(p->from, p->spender, p->to, p->amount);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "approve")==0){
if(count(args) != 3){
ZPT_Runtime_Notify("The number of params is incorrect. Please input three params.");
return "The number of params is incorrect. Please input three params.";
}
struct Params{
char * owner;
char * spender;
char * allowed;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = approve(p->owner, p->spender, p->allowed);
ZPT_Runtime_Notify(result);
return result;
}
if (strcmp(method, "allowance")==0){
if(count(args) != 2){
ZPT_Runtime_Notify("The number of params is incorrect. Please input two params.");
return "The number of params is incorrect. Please input two params.";
}
struct Params{
char * owner;
char * spender;
};
struct Params *p = (struct Params *)malloc(sizeof(struct Params));
ZPT_JsonUnmashalInput(p,sizeof(struct Params),args);
result = allowance(p->owner, p->spender);
ZPT_Runtime_Notify(result);
return result;
}
result = "Invalid invoke method.";
ZPT_Runtime_Notify(result);
return result;
}