-
Notifications
You must be signed in to change notification settings - Fork 610
/
Copy pathRecordStorage.sol
839 lines (711 loc) · 25.2 KB
/
RecordStorage.sol
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./RecordInterface.sol";
import "./UserStorage.sol";
import "./OrderStorage.sol";
interface TokenTransfer {
function transfer(address recipient, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external;
function allowance(address _owner, address _spender)
external
view
returns (uint256 remaining);
}
contract RecordStorage is Ownable {
mapping(string => address) coinTypeMaping;
string[] coinTypeList = ["USDT", "USDC", "BUSD"];
uint256 merchantNeedCount = 10000000000 * (10**18);
uint256 witnessNeedCount = 100000000000 * (10**18);
uint256 congressNeedCount = 1000000000000 * (10**18);
string[] appealFeeCoinTypeList = ["AIR"];
uint256 appealFee = 1000000 * (10**18);
uint256 appealFeeFinal = 10000000 * (10**18);
uint256 canWithdrawToTime = 28;
uint256 subWitFee = 2000000 * (10**18);
uint256 subWitCredit = 10;
uint256 witnessHandleReward = 1000000 * (10**18);
uint256 observerHandleReward = 10000000 * (10**18);
uint256 witnessHandleCredit = 1;
uint256 observerHandleCredit = 1;
bool openTrade = false;
uint256 tradeCredit = 1;
uint256 subTCredit = 10;
mapping(address => uint256) witnessFlag;
mapping(address => uint256) congressFlag;
function setWitnessFlag(address _addr, uint256 _flag) public onlyOwner {
witnessFlag[_addr] = _flag;
if (_flag == 1) {
uint256 _amt = availableTotal[_addr]["AIR"];
require(_amt >= witnessNeedCount, "coin not enough");
_userStorage.updateUserRole(_addr, 1);
} else {
_userStorage.updateUserRole(_addr, 0);
}
}
function getWitnessFlag(address _addr) public view returns (uint256) {
return witnessFlag[_addr];
}
function setCongressFlag(address _addr, uint256 _flag) public onlyOwner {
congressFlag[_addr] = _flag;
if (_flag == 1) {
uint256 _amt = availableTotal[_addr]["AIR"];
require(_amt >= congressNeedCount, "coin not enough");
_userStorage.updateUserRole(_addr, 2);
} else {
_userStorage.updateUserRole(_addr, 0);
}
}
function getCongressFlag(address _addr) public view returns (uint256) {
return congressFlag[_addr];
}
function setCoinType(string[] memory _coinTypeList) public onlyOwner {
coinTypeList = _coinTypeList;
}
function getCoinType() public view returns (string[] memory) {
return coinTypeList;
}
function setCoinTypeMapping(string memory _coinType, address _coinTypeAddr)
public
onlyOwner
{
coinTypeMaping[_coinType] = _coinTypeAddr;
}
function getCoinTypeMapping(string memory _coinType)
public
view
returns (address)
{
return coinTypeMaping[_coinType];
}
function setMerchantNeedCount(uint256 _count) public onlyOwner {
merchantNeedCount = _count * (10**18);
}
function getMerchantNeedCount() public view returns (uint256) {
return merchantNeedCount;
}
function setWitnessNeedCount(uint256 _count) public onlyOwner {
witnessNeedCount = _count * (10**18);
}
function getWitnessNeedCount() public view returns (uint256) {
return witnessNeedCount;
}
function setCongressNeedCount(uint256 _count) public onlyOwner {
congressNeedCount = _count * (10**18);
}
function getCongressNeedCount() public view returns (uint256) {
return congressNeedCount;
}
function setAppealFee(uint256 _count) public onlyOwner {
appealFee = _count * (10**18);
}
function getAppealFee() public view returns (uint256) {
return appealFee;
}
function setAppealFeeFinal(uint256 _count) public onlyOwner {
appealFeeFinal = _count * (10**18);
}
function getAppealFeeFinal() public view returns (uint256) {
return appealFeeFinal;
}
function setCanWithdrawToTime(uint256 _days) public onlyOwner {
canWithdrawToTime = _days;
}
function getCanWithdrawToTime() public view returns (uint256) {
return canWithdrawToTime;
}
function setAppealFeeCoinTypeList(string[] memory _list) public onlyOwner {
appealFeeCoinTypeList = _list;
}
function getAppealFeeCoinTypeList() public view returns (string[] memory) {
return appealFeeCoinTypeList;
}
function setSubWitFee(uint256 _c) public onlyOwner {
subWitFee = _c * (10**18);
}
function getSubWitFee() public view returns (uint256) {
return subWitFee;
}
function setSubWitCredit(uint256 _c) public onlyOwner {
subWitCredit = _c;
}
function getSubWitCredit() public view returns (uint256) {
return subWitCredit;
}
function setWitnessHandleReward(uint256 _c) public onlyOwner {
witnessHandleReward = _c * (10**18);
}
function getWitnessHandleReward() public view returns (uint256) {
return witnessHandleReward;
}
function setObserverHandleReward(uint256 _c) public onlyOwner {
observerHandleReward = _c * (10**18);
}
function getObserverHandleReward() public view returns (uint256) {
return observerHandleReward;
}
function setWitnessHandleCredit(uint256 _c) public onlyOwner {
witnessHandleCredit = _c;
}
function getWitnessHandleCredit() public view returns (uint256) {
return witnessHandleCredit;
}
function setObserverHandleCredit(uint256 _c) public onlyOwner {
observerHandleCredit = _c;
}
function getObserverHandleCredit() public view returns (uint256) {
return observerHandleCredit;
}
function setOpenTrade(bool _c) public onlyOwner {
openTrade = _c;
}
function getOpenTrade() public view returns (bool) {
return openTrade;
}
function setTradeCredit(uint256 _c) public onlyOwner {
tradeCredit = _c;
}
function getTradeCredit() public view returns (uint256) {
return tradeCredit;
}
function setSubTCredit(uint256 _c) public onlyOwner {
subTCredit = _c;
}
function getSubTCredit() public view returns (uint256) {
return subTCredit;
}
function punishPerson(
address _from,
address _to,
uint256 _count
) public onlyOwner {
require(_from != address(0), "Invalid from");
require(_to != address(0), "Invalid to");
UserStorage.User memory _user = _userStorage.searchUser(_from);
require(
_user.userFlag == 1 || _user.userFlag == 2,
"can't punish this person"
);
require(
availableTotal[_from]["AIR"] >= _count,
"user balance not enough"
);
availableTotal[_from]["AIR"] = SafeMath.sub(
availableTotal[_from]["AIR"],
_count
);
availableTotal[_to]["AIR"] = SafeMath.add(
availableTotal[_to]["AIR"],
_count
);
}
UserInterface private _userStorage;
OrderInterface private _orderStorage;
struct Record {
uint256 recordNo;
address userAddr;
string tradeHash;
string coinType;
uint256 hostCount;
uint256 hostStatus;
uint256 hostType;
uint256 hostDirection;
uint256 hostTime;
uint256 updateTime;
}
mapping(uint256 => Record) public records;
mapping(uint256 => uint256) public recordIndex;
Record[] public recordList;
uint256 subFromDraing = 0;
mapping(address => mapping(string => uint256)) public availableTotal;
mapping(address => mapping(string => uint256)) public frozenTotal;
mapping(address => mapping(string => uint256)) public unfrozenTotal;
mapping(address => uint256) lastWithdrawTime;
mapping(address => mapping(uint256 => uint256)) lastWithdrawAmount;
mapping(address => mapping(string => uint256)) public withdrawingTotal;
mapping(address => mapping(uint256 => uint256)) orderSubFrozenList;
constructor(
address _usdtAddress,
address _usdcAddress,
address _busdAddress,
address _airAddress
) {
coinTypeMaping["USDT"] = _usdtAddress;
coinTypeMaping["USDC"] = _usdcAddress;
coinTypeMaping["BUSD"] = _busdAddress;
coinTypeMaping["AIR"] = _airAddress;
}
function setERC20Address(string memory _coinType)
public
view
returns (TokenTransfer)
{
require(bytes(_coinType).length != 0, "Invalid coin type");
address _remoteAddr = coinTypeMaping[_coinType];
require(_remoteAddr != address(0), "Invalid coin type");
TokenTransfer _tokenTransfer = TokenTransfer(_remoteAddr);
return _tokenTransfer;
}
event RecordAdd(
uint256 _recordNo,
address _addr,
string _tradeHash,
string _coinType,
uint256 _hostCount,
uint256 _hostStatus,
uint256 _hostType,
uint256 _hostDirection
);
event RecordApplyUnfrozen(address _addr, uint256 _amt);
event UnfrozenTotalTransfer(
address _addr,
string _coinType,
uint256 _lastAmount
);
event RecordUpdate(
address _addr,
uint256 _recordNo,
string _hash,
uint256 _hostStatus
);
address _userAddr;
address _restCAddr;
address _orderCAddr;
address _appealCAddr;
modifier onlyAuthFromAddr() {
require(_userAddr != address(0), "Invalid address call user");
require(_restCAddr != address(0), "Invalid address call rest");
require(_orderCAddr != address(0), "Invalid address call order");
require(_appealCAddr != address(0), "Invalid address call appeal");
_;
}
function authFromContract(
address _fromUser,
address _fromRest,
address _fromOrder,
address _fromAppeal
) external {
require(_userAddr == address(0), "rest address has Auth");
require(_restCAddr == address(0), "rest address has Auth");
require(_orderCAddr == address(0), "order address has Auth");
require(_appealCAddr == address(0), "appeal address has Auth");
_userAddr = _fromUser;
_restCAddr = _fromRest;
_orderCAddr = _fromOrder;
_appealCAddr = _fromAppeal;
_userStorage = UserInterface(_userAddr);
_orderStorage = OrderInterface(_orderCAddr);
}
function _insert(
address _addr,
string memory _tradeHash,
string memory _coinType,
uint256 _hostCount,
uint256 _hostStatus,
uint256 _hostType,
uint256 _hostDirection
) internal returns (uint256 recordNo) {
require(_addr != address(0), "address null is not allowed");
require(bytes(_coinType).length != 0, "coinType null is not allowed");
require(_hostCount != uint256(0), "hostCount null is not allowed");
require(_hostType != uint256(0), "hostType null is not allowed");
require(
_hostDirection != uint256(0),
"hostDirection null is not allowed"
);
uint256 _recordNo = block.timestamp;
Record memory _record = Record({
recordNo: _recordNo,
userAddr: _addr,
tradeHash: _tradeHash,
coinType: _coinType,
hostCount: _hostCount,
hostStatus: _hostStatus,
hostType: _hostType,
hostDirection: _hostDirection,
hostTime: block.timestamp,
updateTime: 0
});
records[_recordNo] = _record;
recordList.push(_record);
recordIndex[_recordNo] = recordList.length - 1;
emit RecordAdd(
_recordNo,
_addr,
_tradeHash,
_coinType,
_hostCount,
_hostStatus,
_hostType,
_hostDirection
);
return _recordNo;
}
function tokenEscrow(string memory _coinType, uint256 _amt) external {
require(_amt > 0, "Invalid transfer amount");
require(
availableTotal[msg.sender][_coinType] + _amt >
availableTotal[msg.sender][_coinType],
"Invalid transfer amount"
);
availableTotal[msg.sender][_coinType] = SafeMath.add(
availableTotal[msg.sender][_coinType],
_amt
);
uint256 _hostType = 1;
if (
keccak256(abi.encodePacked(_coinType)) ==
keccak256(abi.encodePacked("AIR"))
) {
_hostType = 3;
UserStorage.User memory _user = _userStorage.searchUser(msg.sender);
UserStorage.MorgageStats memory _morgageStats = _user.morgageStats;
_morgageStats.mortgage = SafeMath.add(_morgageStats.mortgage, _amt);
_userStorage.updateMorgageStats(msg.sender, _morgageStats);
if (
_user.userFlag == 0 &&
_morgageStats.mortgage >= merchantNeedCount
) {
_userStorage.updateUserRole(msg.sender, 3);
}
}
_insert(msg.sender, "", _coinType, _amt, 2, _hostType, 1);
TokenTransfer _tokenTransfer = setERC20Address(_coinType);
_tokenTransfer.transferFrom(msg.sender, address(this), _amt);
}
function addRecord(
address _addr,
string memory _tradeHash,
string memory _coinType,
uint256 _hostCount,
uint256 _hostStatus,
uint256 _hostType,
uint256 _hostDirection
) public onlyAuthFromAddr {
require(
msg.sender == _restCAddr || msg.sender == _orderCAddr,
"RedocrdStorage:Invalid from contract address"
);
frozenTotal[_addr][_coinType] = SafeMath.add(
frozenTotal[_addr][_coinType],
_hostCount
);
_insert(
_addr,
_tradeHash,
_coinType,
_hostCount,
_hostStatus,
_hostType,
_hostDirection
);
}
function addAvailableTotal(
address _addr,
string memory _coinType,
uint256 _amt
) public onlyAuthFromAddr {
require(
msg.sender == _restCAddr || msg.sender == _orderCAddr,
"Invalid address"
);
require(_amt > 0, "Invalid transfer amount");
uint256 _aBalance = getErcBalance(_coinType, address(this));
require(_aBalance >= _amt, "balance not enough");
require(frozenTotal[_addr][_coinType] >= _amt, "Invalid amount");
require(
SafeMath.sub(frozenTotal[_addr][_coinType], _amt) <=
frozenTotal[_addr][_coinType],
"Invalid amount"
);
frozenTotal[_addr][_coinType] = SafeMath.sub(
frozenTotal[_addr][_coinType],
_amt
);
TokenTransfer _tokenTransfer = setERC20Address(_coinType);
_tokenTransfer.transfer(_addr, _amt);
}
function getAvailableTotal(address _addr, string memory _coinType)
public
view
returns (uint256)
{
return availableTotal[_addr][_coinType];
}
function subFrozenTotal(uint256 _orderNo, address _addr)
public
onlyAuthFromAddr
{
require(
msg.sender == _orderCAddr || msg.sender == _appealCAddr,
"Invalid from contract address"
);
OrderStorage.Order memory _order = _orderStorage.searchOrder(_orderNo);
require(_order.orderNo != uint256(0), "order not exist");
address _seller = _order.orderDetail.sellerAddr;
string memory _coinType = _order.orderDetail.coinType;
uint256 _subAmount = orderSubFrozenList[_seller][_orderNo];
require(_subAmount == 0, "order not exist");
uint256 _frozen = frozenTotal[_seller][_coinType];
uint256 _orderCount = _order.coinCount;
require(_frozen >= _orderCount, "Invalid amount");
require(
SafeMath.sub(_frozen, _orderCount) <= _frozen,
"Invalid amount 2"
);
frozenTotal[_seller][_coinType] = SafeMath.sub(_frozen, _orderCount);
orderSubFrozenList[_seller][_orderNo] = _orderCount;
TokenTransfer _tokenTransfer = setERC20Address(_coinType);
_tokenTransfer.transfer(_addr, _orderCount);
}
function subAvaAppeal(
address _from,
address _to,
AppealStorage.Appeal memory _al,
uint256 _amt,
uint256 _t,
uint256 _self
) public onlyAuthFromAddr {
require(
msg.sender == _appealCAddr,
"RedocrdStorage:Invalid from contract address"
);
uint256 _available = getAvailableTotal(_from, "AIR");
uint256 _need = 0;
address _opt = _t == 1 ? _al.witness : _al.detail.observerAddr;
if (_available >= _amt) {
_need = _amt;
} else {
_need = _available;
}
if (
(_t == 1 && _self == 0) ||
(_t == 2 && _al.detail.finalAppealAddr != _from)
) {
availableTotal[_from]["AIR"] = SafeMath.sub(
availableTotal[_from]["AIR"],
_need
);
availableTotal[_to]["AIR"] = SafeMath.add(
availableTotal[_to]["AIR"],
_need
);
}
availableTotal[_opt]["AIR"] = SafeMath.add(
availableTotal[_opt]["AIR"],
_amt
);
chanRole(_from);
UserStorage.User memory _user = _userStorage.searchUser(_opt);
if (_t == 1) {
_user.credit = _user.credit + witnessHandleCredit;
} else if (_t == 2) {
_user.credit = _user.credit + observerHandleCredit;
}
UserStorage.TradeStats memory _tradeStats = _user.tradeStats;
_userStorage.updateTradeStats(_opt, _tradeStats, _user.credit);
}
function subWitnessAvailable(address _addr) public onlyAuthFromAddr {
require(
msg.sender == _appealCAddr,
"RedocrdStorage:Invalid from contract address"
);
require(_addr != address(0), "witness address is null");
uint256 _availableTotal = availableTotal[_addr]["AIR"];
uint256 _need = 0;
if (_availableTotal >= subWitFee) {
_need = subWitFee;
availableTotal[_addr]["AIR"] = SafeMath.sub(_availableTotal, _need);
} else {
availableTotal[_addr]["AIR"] = 0;
uint256 _draing = withdrawingTotal[_addr]["AIR"];
if (SafeMath.add(_availableTotal, _draing) >= subWitFee) {
_need = subWitFee;
subFromDraing = subWitFee - _availableTotal - _draing;
withdrawingTotal[_addr]["AIR"] = SafeMath.sub(
withdrawingTotal[_addr]["AIR"],
subFromDraing
);
} else {
_need = SafeMath.add(
withdrawingTotal[_addr]["AIR"],
availableTotal[_addr]["AIR"]
);
withdrawingTotal[_addr]["AIR"] = 0;
}
}
chanRole(_addr);
UserStorage.User memory _user = _userStorage.searchUser(_addr);
_user.credit = _user.credit >= subWitCredit
? (_user.credit - subWitCredit)
: 0;
UserStorage.TradeStats memory _tradeStats = _user.tradeStats;
_userStorage.updateTradeStats(_addr, _tradeStats, _user.credit);
TokenTransfer _tokenTransfer = setERC20Address("AIR");
_tokenTransfer.transfer(owner(), _need);
}
function getFrozenTotal(address _addr, string memory _coinType)
public
view
returns (uint256)
{
return frozenTotal[_addr][_coinType];
}
function applyUnfrozen(uint256 _amt) public returns (uint256) {
string memory _coinType = "AIR";
require(_amt > 0, "Invalid transfer amount");
require(
availableTotal[msg.sender][_coinType] >= _amt,
"Invalid amount"
);
require(
SafeMath.sub(availableTotal[msg.sender][_coinType], _amt) <
availableTotal[msg.sender][_coinType],
"Invalid amount 2"
);
lastWithdrawTime[msg.sender] = block.timestamp;
lastWithdrawAmount[msg.sender][lastWithdrawTime[msg.sender]] = _amt;
availableTotal[msg.sender][_coinType] = SafeMath.sub(
availableTotal[msg.sender][_coinType],
_amt
);
withdrawingTotal[msg.sender][_coinType] = SafeMath.add(
withdrawingTotal[msg.sender][_coinType],
_amt
);
chanRole(msg.sender);
_insert(msg.sender, "", _coinType, _amt, 3, 3, 2);
emit RecordApplyUnfrozen(msg.sender, _amt);
return getAvailableTotal(msg.sender, _coinType);
}
function chanRole(address _addr) internal {
uint256 _avail = availableTotal[_addr]["AIR"];
UserStorage.User memory _user = _userStorage.searchUser(_addr);
UserStorage.MorgageStats memory _morgageStats = _user.morgageStats;
_morgageStats.mortgage = _avail;
_userStorage.updateMorgageStats(_addr, _morgageStats);
if (
_user.userFlag == 2 &&
_avail < congressNeedCount &&
_avail >= merchantNeedCount
) {
_userStorage.updateUserRole(_addr, 3);
}
if (
_user.userFlag == 1 &&
_avail < witnessNeedCount &&
_avail >= merchantNeedCount
) {
_userStorage.updateUserRole(_addr, 3);
}
if (_avail < merchantNeedCount) {
_userStorage.updateUserRole(_addr, 0);
}
}
function applyWithdraw(uint256 _recordNo) public {
Record memory _record = records[_recordNo];
require(_record.recordNo != uint256(0), "record not exist");
require(_record.userAddr == msg.sender, "record user not exist");
require(_record.hostStatus == 3, "status error");
require(
withdrawingTotal[msg.sender]["AIR"] >= _record.hostCount,
"balance not enough"
);
require(
block.timestamp >= (_record.hostTime + canWithdrawToTime * 1 days),
"can't withdraw"
);
withdrawingTotal[msg.sender]["AIR"] = SafeMath.sub(
withdrawingTotal[msg.sender]["AIR"],
_record.hostCount
);
unfrozenTotal[msg.sender]["AIR"] = SafeMath.add(
unfrozenTotal[msg.sender]["AIR"],
_record.hostCount
);
_record.hostCount = SafeMath.sub(_record.hostCount, subFromDraing);
_record.hostStatus = 4;
_record.updateTime = block.timestamp;
records[_recordNo] = _record;
recordList[recordIndex[_recordNo]] = _record;
emit RecordUpdate(msg.sender, _recordNo, _record.tradeHash, 4);
TokenTransfer _tokenTransfer = setERC20Address("AIR");
_tokenTransfer.transfer(msg.sender, _record.hostCount);
}
function unfrozenTotalSearch(address _addr, string memory _coinType)
public
view
returns (uint256)
{
require(_addr != address(0), "user address is null");
return unfrozenTotal[_addr][_coinType];
}
function getUnfrozenTotal(address _addr, string memory _coinType)
external
view
returns (uint256)
{
return unfrozenTotal[_addr][_coinType];
}
function getWithdrawingTotal(address _addr, string memory _coinType)
public
view
returns (uint256)
{
return withdrawingTotal[_addr][_coinType];
}
function getErcBalance(string memory _coinType, address _addr)
public
view
returns (uint256)
{
TokenTransfer _tokenTransfer = setERC20Address(_coinType);
return _tokenTransfer.balanceOf(_addr);
}
function _updateInfo(
address _addr,
uint256 _recordNo,
string memory _hash,
uint256 _hostStatus
) internal returns (bool) {
Record memory _record = records[_recordNo];
require(_record.userAddr == _addr, "record not exist");
require(_hostStatus == 1 || _hostStatus == 2, "invalid hostStatus");
if (_hostStatus != uint256(0)) {
_record.hostStatus = _hostStatus;
}
if (bytes(_hash).length != 0) {
_record.tradeHash = _hash;
}
_record.updateTime = block.timestamp;
records[_recordNo] = _record;
recordList[recordIndex[_recordNo]] = _record;
emit RecordUpdate(_addr, _recordNo, _hash, _hostStatus);
return true;
}
function updateInfo(
address _addr,
uint256 _recordNo,
string memory _hash,
uint256 _hostStatus
) external returns (bool) {
return _updateInfo(_addr, _recordNo, _hash, _hostStatus);
}
function searchRecord(uint256 _recordNo)
external
view
returns (Record memory record)
{
return records[_recordNo];
}
function searchRecordList() external view returns (Record[] memory) {
return recordList;
}
}