-
Notifications
You must be signed in to change notification settings - Fork 4
/
contracts_000.js
751 lines (711 loc) · 26.8 KB
/
contracts_000.js
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
/**
* Node Trinity source code
* See LICENCE file at the top of the source tree
*
* ******************************************
*
* contracts_000.js
* Enecuum smart contracts logic
*
* Working with chain before 001 fork
* Token & POS contracts:
* - tokens creation, mint & burn
* - PoS creation, delegate, undelegate, transfer & get reward contracts
*
* ******************************************
*
* Authors: K. Zhidanov, A. Prudanov, M. Vasil'ev
*/
const Utils = require('./Utils');
const {ContractError} = require('./errors');
let MAX_DECIMALS = BigInt(10);
let ENQ_INTEGER_COIN = BigInt(10000000000);
class Contract{
constructor() {
this._mysql = require('mysql');
this.type = null;
this.pricelist = require('./pricelist').fork_block_000;
}
get mysql(){
return this._mysql;
}
}
class TokenCreateContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
let params = this.data.parameters;
let paramsModel = ["fee_type", "fee_value", "ticker", "decimals", "total_supply", "name"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
let letters_regexp = /^[A-Z]{1,6}$/g;
if(!letters_regexp.test(params.ticker))
throw new ContractError("Incorrect ticker format");
if(params.name.length > 40)
throw new ContractError("token format is too long");
let bigintModel = ["fee_value", "fee_min", "decimals", "total_supply", "max_supply", "block_reward", "min_stake", "ref_share", "referrer_stake"];
if (!bigintModel.every(key => ((typeof params[key] === 'undefined') || (typeof params[key] === 'bigint')))){
throw new ContractError("Incorrect field format, BigInteger expected");
}
if(params.decimals < 0 || params.decimals > MAX_DECIMALS){
throw new ContractError("Incorrect total_supply value");
}
if(params.minable){
if(params.minable !== 0 && params.minable !== 1)
throw new ContractError("Incorrect minable flag, expect 0 or 1");
if(params.minable === 1 && params.reissuable !== 0)
throw new ContractError("Minable token can't be reissuable");
if(params.minable === 1){
// Check structure
let miningModel = ["max_supply", "block_reward", "min_stake", "ref_share", "referrer_stake"];
if (miningModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure for minable token");
}
// Check 0 < x < Utils.MAX_SUPPLY_LIMIT
let amountsModel = ["max_supply", "block_reward", "total_supply", "referrer_stake"];
for(let key of amountsModel){
if (params[key] < 0 || params[key] > Utils.MAX_SUPPLY_LIMIT){
throw new ContractError(`${key} if out of 0...Utils.MAX_SUPPLY_LIMIT range`);
}
}
/**
* max_supply = tsup + block_rew * x years
* 0 [__total_supply___|____to_be_mined__________] Utils.MAX_SUPPLY_LIMIT
*
* 0 <= tsup <= max_supply
* 0 <= to_be_mined <= max_supply
*/
// if(params.max_supply > Utils.MAX_SUPPLY_LIMIT){
// throw new ContractError("max_supply can't be bigger than Utils.MAX_SUPPLY_LIMIT");
// }
if(params.max_supply <= 0 || params.max_supply < params.total_supply){
throw new ContractError("Incorrect supply params");
}
if(params.block_reward > (params.max_supply - params.total_supply)){
throw new ContractError("Incorrect block_reward param");
}
if(params.ref_share > Utils.PERCENT_FORMAT_SIZE || params.ref_share < 0){
throw new ContractError("Incorrect ref_share param");
}
if(params.referrer_stake > params.total_supply || params.referrer_stake < 0){
throw new ContractError("Incorrect referrer_stake param");
}
if(params.min_stake > params.total_supply || params.min_stake <= 0){
throw new ContractError("Incorrect min_stake param");
}
}
}
if(params.reissuable){
if(params.reissuable !== 0 && params.reissuable !== 1)
throw new ContractError("Incorrect reissuable flag, expect 0 or 1");
}
if(params.total_supply < 0 || params.total_supply > Utils.MAX_SUPPLY_LIMIT){
throw new ContractError("Incorrect total_supply value");
}
switch (params.fee_type) {
case 0 : {
if(params.fee_value < 0 || params.fee_value > Utils.MAX_SUPPLY_LIMIT)
throw new ContractError("Incorrect fee params");
break;
}
case 1 : {
if(params.fee_value < 0 || params.fee_value > Utils.PERCENT_FORMAT_SIZE)
throw new ContractError("Incorrect fee params");
if(params.fee_min === undefined){
throw new ContractError("Missing fee_min for fee_type = 1");
}
if(params.fee_min < 0 || params.fee_min > Utils.MAX_SUPPLY_LIMIT){
throw new ContractError("Incorrect fee_min value");
}
break;
}
default : {
throw new ContractError("Incorrect fee params");
}
}
return true;
}
async execute(tx, db) {
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
// Check token exist
let existing = await db.get_tickers_all();
if (existing.some(d => d.ticker === params.ticker))
throw new ContractError(`Ticker ${params.ticker} already exist`);
let tok_data = {
hash : tx.hash,
owner : tx.from,
fee_type : params.fee_type,
fee_value : params.fee_value,
fee_min : params.fee_min || params.fee_value,
ticker : params.ticker,
caption : params.name,
decimals : params.decimals,
total_supply : params.total_supply,
reissuable : params.reissuable || 0,
minable : params.minable || 0
};
if(params.minable === 1){
tok_data.max_supply = params.max_supply;
tok_data.block_reward = params.block_reward;
tok_data.min_stake = params.min_stake;
tok_data.referrer_stake = params.referrer_stake;
tok_data.ref_share = params.ref_share;
}
return {
amount_changes : [
{
id : tx.from,
amount_change : tok_data.total_supply,
token_hash : tx.hash,
}
],
pos_changes : [],
post_action : [this.sqlInsertToken(tok_data)],
token_info : {
hash : tx.hash,
ticker : params.ticker
}
};
}
sqlInsertToken(data) {
return super.mysql.format(`INSERT INTO tokens SET ?`, [data])
}
}
class PosCreateContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* fee : 0..10000, required
* (opt) name : 0..40 length, any chars
*/
let params = this.data.parameters;
let paramsModel = ["fee"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
let bigintModel = ["fee"];
if (!bigintModel.every(key => ((typeof params[key] === undefined) || (typeof params[key] === 'bigint')))){
throw new ContractError("Incorrect field format, BigInteger expected");
}
if(params.fee < 0 || params.fee > Utils.PERCENT_FORMAT_SIZE){
throw new ContractError("Incorrect fee");
}
if(params.name){
if((params.name.length > 40) || (typeof params.name !== "string"))
throw new ContractError("Incorrect name format");
}
return true;
}
async execute(tx, db) {
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
if(params.name){
let existing = await db.get_pos_names();
if (existing.some(d => d.name === params.name))
throw new ContractError(`Contract with name ${params.name} already exist`);
}
let pos_data = {
id : tx.hash,
owner : tx.from,
fee : params.fee,
name : params.name || null
};
return {
amount_changes : [],
pos_changes : [],
post_action : [this.sqlInsertPos(pos_data)]
};
}
sqlInsertPos(data) {
return super.mysql.format(`INSERT INTO poses SET ?`, [data])
}
}
class PosDelegateContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* pos_id : hex string 64 chars
* amount : 0...max_supply, integer
*/
let params = this.data.parameters;
let paramsModel = ["pos_id", "amount"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
//let enq_regexp = /^(02|03)[0-9a-fA-F]{64}$/i;
let hash_regexp = /^[0-9a-fA-F]{64}$/i;
if(!hash_regexp.test(params.pos_id))
throw new ContractError("Incorrect pos_id format");
let bigintModel = ["amount"];
if (!bigintModel.every(key => (typeof params[key] === 'bigint'))){
throw new ContractError("Incorrect field format, BigInteger expected");
}
if(params.amount < 0 || params.amount > Utils.MAX_SUPPLY_LIMIT || ((params.amount % ENQ_INTEGER_COIN) !== BigInt(0))){
throw new ContractError("Incorrect amount");
}
return true;
}
async execute(tx, db) {
/**
* check pos_id exist
* change tx.from balance = balance - amount
* put row in pos_leases table, increase amount
*/
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
// Check pos contract exist
let existing = await db.get_pos_contract_all();
if (!existing.some(d => d.id === params.pos_id))
throw new ContractError(`POS contract ${params.pos_id} doesn't exist`);
let lend_data = {
pos_id : params.pos_id,
delegator : tx.from,
amount : params.amount
};
return {
amount_changes : [
{
id : tx.from,
amount_change : BigInt(-1) * BigInt(params.amount),
token_hash : tx.ticker,
}
],
pos_changes : [
{
pos_id : params.pos_id,
delegator : tx.from,
delegated : params.amount,
undelegated : BigInt(0),
reward : BigInt(0)
}
],
post_action : [this.sqlInsertDelegates(lend_data)]
};
}
sqlInsertDelegates(data) {
return super.mysql.format(`INSERT INTO delegates (pos_id, delegator, amount) VALUES (?)
ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount)`, [[data.pos_id, data.delegator, data.amount]])
}
}
class PosUndelegateContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* pos_id : hex string 64 chars
* amount : 0...max_supply, integer
*/
let params = this.data.parameters;
let paramsModel = ["pos_id", "amount"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
//let enq_regexp = /^(02|03)[0-9a-fA-F]{64}$/i;
let hash_regexp = /^[0-9a-fA-F]{64}$/i;
if(!hash_regexp.test(params.pos_id))
throw new ContractError("Incorrect pos_id format");
let bigintModel = ["amount"];
if (!bigintModel.every(key => (typeof params[key] === 'bigint'))){
throw new ContractError("Incorrect field format, BigInteger expected");
}
if(params.amount < 0 || params.amount > Utils.MAX_SUPPLY_LIMIT || ((params.amount % ENQ_INTEGER_COIN) !== BigInt(0))){
throw new ContractError("Incorrect amount");
}
return true;
}
async execute(tx, db, kblock) {
/**
* get lend row from delegates table
* check amount <= delegated amount
* decrease delegated amount
* put ertry to undelegates table
*/
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
let leased = (await db.get_pos_delegates(params.pos_id, [tx.from]))[0];
if(!leased)
throw new ContractError("pos_id not found");
if(params.amount > leased.amount)
throw new ContractError("Unbond amount is bigger than leased amount");
// Amount will be deducted from current DB value in finalize_macroblock
let delegates_data = {
pos_id : params.pos_id,
delegator : tx.from,
amount : BigInt(-1) * BigInt(params.amount),
};
let undelegates_data = {
id : tx.hash,
pos_id : params.pos_id,
delegator : tx.from,
amount : params.amount,
height : kblock.n
};
return {
amount_changes : [],
pos_changes : [
{
pos_id : params.pos_id,
delegator : tx.from,
delegated : BigInt(-1) * BigInt(params.amount),
undelegated : params.amount,
reward : BigInt(0)
}
],
post_action : [
this.sqlUpdateDelegates(delegates_data),
this.sqlInsertUndelegates(undelegates_data)
]
};
}
sqlUpdateDelegates(data) {
// TODO: CAST(? AS UNSIGNED INTEGER)
return super.mysql.format(`UPDATE delegates SET amount = amount + ? WHERE pos_id = ? AND delegator = ?`,
[data.amount, data.pos_id, data.delegator])
}
sqlInsertUndelegates(data) {
return super.mysql.format(`INSERT INTO undelegates (id, pos_id, amount, height) VALUES (?)`,
[[data.id, data.pos_id, data.amount, data.height]])
}
}
class PosTransferContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* undelegate_id : hex string 64 chars
*/
let params = this.data.parameters;
let paramsModel = ["undelegate_id"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
let hash_regexp = /^[0-9a-fA-F]{64}$/i;
if(!hash_regexp.test(params.undelegate_id))
throw new ContractError("Incorrect undelegate_id format");
return true;
}
async execute(tx, db, kblock) {
/**
* get undelegated from undelegates table by undelegated_id
* check TRANSFER_LOCK time
* update pos_transits
* return new balance
*/
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
let transfer = (await db.get_pos_undelegates(params.undelegate_id))[0];
let und_tx = (await db.get_tx(params.undelegate_id))[0];
if(und_tx === undefined) {
throw new ContractError("Undelegate TX not found");
}
if(und_tx.status !== 3) {
throw new ContractError("Invalid undelegate TX status");
}
if(und_tx.from !== tx.from) {
throw new ContractError("Undelegate TX sender and transfer TX sender doesn't match");
}
if(!transfer)
throw new ContractError("Transfer not found");
if(transfer.amount === 0)
throw new ContractError("Transfer has already been processed");
if(!this.checkTime(transfer, db.app_config.transfer_lock, kblock))
throw new ContractError("Freeze time has not passed yet");
let data = {
id : params.undelegate_id,
amount : BigInt(0)
};
return {
amount_changes : [
{
id : tx.from,
amount_change : transfer.amount,
token_hash : tx.ticker,
}
],
pos_changes : [
{
pos_id : transfer.pos_id,
delegator : tx.from,
delegated : BigInt(0),
undelegated : BigInt(0),
transfer : params.undelegate_id,
reward : BigInt(0)
}
],
post_action : [this.sqlUpdateUndelegates(data)]
};
}
checkTime(transfer, transfer_lock, kblock){
return false;
}
sqlUpdateUndelegates(data) {
return super.mysql.format(`UPDATE undelegates SET amount = ? WHERE id = ?`, [data.amount, data.id])
}
}
class PosGetRewardContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* pos_id : hex string 64 chars
*/
let params = this.data.parameters;
let paramsModel = ["pos_id"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
let hash_regexp = /^[0-9a-fA-F]{64}$/i;
if(!hash_regexp.test(params.pos_id))
throw new ContractError("Incorrect pos_id format");
return true;
}
async execute(tx, db) {
/**
* check pos exist
* get delegator's reward
* change delegator's ledger amount
* set delegator's reward to 0
*/
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
let leased = (await db.get_pos_delegates(params.pos_id, [tx.from]))[0];
if(!leased)
throw new ContractError("Delegate not found");
if(leased.reward <= BigInt(0))
throw new ContractError(`Delegator ${tx.from} has no reward on contract ${params.pos_id}`);
let data = {
pos_id : params.pos_id,
delegator : tx.from,
amount : BigInt(-1) * BigInt(leased.reward)
};
return {
amount_changes : [
{
id : tx.from,
amount_change : leased.reward,
token_hash : tx.ticker,
}
],
pos_changes : [
{
pos_id : params.pos_id,
delegator : tx.from,
delegated : BigInt(0),
undelegated : BigInt(0),
reward : BigInt(-1) * BigInt(leased.reward)
}
],
post_action : [this.sqlUpdateDelegatesReward(data)]
};
}
sqlUpdateDelegatesReward(data) {
// TODO: CAST(? AS UNSIGNED INTEGER)
return super.mysql.format(`UPDATE delegates SET reward = reward + ? WHERE pos_id = ? AND delegator = ?`,
[data.amount, data.pos_id, data.delegator])
}
}
class TokenMintContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* token_hash : hex string 64 chars
* amount : 0...max_supply
*/
let params = this.data.parameters;
let paramsModel = ["token_hash", "amount"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
let hash_regexp = /^[0-9a-fA-F]{64}$/i;
if(!hash_regexp.test(params.token_hash))
throw new ContractError("Incorrect token_hash format");
let bigintModel = ["amount"];
if (!bigintModel.every(key => (typeof params[key] === 'bigint'))){
throw new ContractError("Incorrect field format, BigInteger expected");
}
if(params.amount < 0 || params.amount > Utils.MAX_SUPPLY_LIMIT){
throw new ContractError("Incorrect amount");
}
return true;
}
async execute(tx, db) {
/**
* check token exist
* check token reissuable
* check token owner
* check current TS + amount < MAX_SUPPLY
* update tokens table total_supply = total_supply + amount
* update token owner's ledger amount
*/
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
let token_info = (await db.get_tokens(params.token_hash))[0];
if(!token_info)
throw new ContractError("Token not found");
if(token_info.owner !== tx.from)
throw new ContractError("From account is not a token owner");
if(token_info.reissuable !== 1)
throw new ContractError("Token is not reissuable");
if((BigInt(token_info.total_supply) + params.amount) > Utils.MAX_SUPPLY_LIMIT)
throw new ContractError("New total supply is higher than MAX_SUPPLY");
let data = {
token_hash : params.token_hash,
mint_amount : params.amount
};
return {
amount_changes : [
{
id : tx.from,
amount_change : params.amount,
token_hash : params.token_hash,
}
],
pos_changes : [],
post_action : [this.sqlUpdateTokensSupply(data)]
};
}
sqlUpdateTokensSupply(data) {
return super.mysql.format(`UPDATE tokens SET total_supply = total_supply + CAST(? AS UNSIGNED INTEGER) WHERE hash = ?`,
[data.mint_amount, data.token_hash])
}
}
class TokenBurnContract extends Contract {
constructor(data) {
super();
this.data = data;
this.type = this.data.type;
if(!this.validate())
throw new ContractError("Incorrect contract");
}
validate() {
/**
* parameters:
* token_hash : hex string 64 chars
* amount : 0...max_supply
*/
let params = this.data.parameters;
let paramsModel = ["token_hash", "amount"];
if (paramsModel.some(key => params[key] === undefined)){
throw new ContractError("Incorrect param structure");
}
let hash_regexp = /^[0-9a-fA-F]{64}$/i;
if(!hash_regexp.test(params.token_hash))
throw new ContractError("Incorrect token_hash format");
let bigintModel = ["amount"];
if (!bigintModel.every(key => (typeof params[key] === 'bigint'))){
throw new ContractError("Incorrect field format, BigInteger expected");
}
if(params.amount < 0 || params.amount > Utils.MAX_SUPPLY_LIMIT){
throw new ContractError("Incorrect amount");
}
return true;
}
async execute(tx, db) {
/**
* check token exist
* check token reissuable
* check token owner
* chech new amount > 0
* update tokens table total_supply = total_supply - amount
* update token owner's ledger amount
*/
if(this.data.type === undefined)
return null;
let params = this.data.parameters;
let token_info = (await db.get_tokens(params.token_hash))[0];
if(!token_info)
throw new ContractError("Token not found");
if(token_info.owner !== tx.from)
throw new ContractError("From account is not a token owner");
if(token_info.reissuable !== 1)
throw new ContractError("Token is not reissuable");
// if((token_info.total_supply - params.amount) < 0)
// throw new ContractError("Total supply can't be negative");
let data = {
token_hash : params.token_hash,
burn_amount : params.amount
};
return {
amount_changes : [
{
id : tx.from,
amount_change : BigInt(-1) * params.amount,
token_hash : params.token_hash,
}
],
pos_changes : [],
post_action : [this.sqlUpdateTokensSupply(data)],
token_info : {
hash : params.token_hash,
db_supply : token_info.total_supply,
supply_change : BigInt(-1) * params.amount
}
};
}
sqlUpdateTokensSupply(data) {
return super.mysql.format(`UPDATE tokens SET total_supply = total_supply - CAST(? AS UNSIGNED INTEGER) WHERE hash = ?`,
[data.burn_amount, data.token_hash])
}
}
module.exports.Contract = Contract;
module.exports.TokenCreateContract = TokenCreateContract;
module.exports.PosCreateContract = PosCreateContract;
module.exports.PosDelegateContract = PosDelegateContract;
module.exports.PosUndelegateContract = PosUndelegateContract;
module.exports.PosTransferContract = PosTransferContract;
module.exports.PosGetRewardContract = PosGetRewardContract;
module.exports.TokenMintContract = TokenMintContract;
module.exports.TokenBurnContract = TokenBurnContract;