@@ -23,9 +23,12 @@ contract DARC is Runtime, Dashboard {
23
23
function entrance (Program memory program ) public payable returns (string memory ) {
24
24
require (program.programOperatorAddress == msg .sender ,
25
25
string .concat (string .concat ("Invalid program address. Msg.sender: " , StringUtils.toAsciiString (msg .sender )), string .concat (", and program operator address: " , StringUtils.toAsciiString (program.programOperatorAddress))));
26
- for (uint256 opIdx = 0 ; opIdx < program.operations.length ; opIdx ++ ) {
26
+ for (uint256 opIdx; opIdx < program.operations.length ;) {
27
27
require (program.operations[opIdx].operatorAddress == msg .sender ,
28
28
string .concat (string .concat ("Invalid program address. Msg.sender: " , StringUtils.toAsciiString (msg .sender )), string .concat (", and program operator address: " , StringUtils.toAsciiString (program.operations[opIdx].operatorAddress))));
29
+ unchecked {
30
+ ++ opIdx;
31
+ }
29
32
}
30
33
return runtimeEntrance (program);
31
34
}
@@ -44,8 +47,8 @@ contract DARC is Runtime, Dashboard {
44
47
require (amount <= currentMachineState.withdrawableCashMap[msg .sender ], string .concat ("Invalid withdraw amount. Amount: " , Strings.toString (amount), ", and withdrawable cash: " , Strings.toString (currentMachineState.withdrawableCashMap[msg .sender ])));
45
48
46
49
// first update the withdrawable cash map
47
- bool bIsValid = false ;
48
- uint256 result = 0 ;
50
+ bool bIsValid;
51
+ uint256 result;
49
52
(bIsValid, result) = SafeMathUpgradeable.trySub (currentMachineState.withdrawableCashMap[msg .sender ], amount);
50
53
require (bIsValid, string .concat ("Invalid withdraw amount. Amount: " , Strings.toString (amount), ", and withdrawable cash: " , Strings.toString (currentMachineState.withdrawableCashMap[msg .sender ])));
51
54
@@ -54,18 +57,25 @@ contract DARC is Runtime, Dashboard {
54
57
// if the message sender owns zero withdrawable cash balance, then remove it from the withdrawable cash owner list
55
58
if (currentMachineState.withdrawableCashMap[msg .sender ] == 0 ) {
56
59
address [] memory newWithdrawableCashOwnerList = new address [](currentMachineState.withdrawableCashOwnerList.length );
57
- uint256 pt = 0 ;
58
- for (uint256 index = 0 ; index < currentMachineState.withdrawableCashOwnerList.length ; index ++ ) {
60
+ uint256 pt;
61
+ for (uint256 index; index < currentMachineState.withdrawableCashOwnerList.length ;) {
59
62
if (currentMachineState.withdrawableCashOwnerList[index] != msg .sender ) {
60
63
newWithdrawableCashOwnerList[pt] = currentMachineState.withdrawableCashOwnerList[index];
61
64
pt++ ;
62
65
}
66
+
67
+ unchecked {
68
+ ++ index;
69
+ }
63
70
}
64
71
65
72
// update the withdrawable cash owner list
66
73
currentMachineState.withdrawableCashOwnerList = new address [](pt);
67
- for (uint256 index = 0 ; index < pt; index ++ ) {
74
+ for (uint256 index; index < pt;) {
68
75
currentMachineState.withdrawableCashOwnerList[index] = newWithdrawableCashOwnerList[index];
76
+ unchecked {
77
+ ++ index;
78
+ }
69
79
}
70
80
}
71
81
@@ -74,7 +84,7 @@ contract DARC is Runtime, Dashboard {
74
84
}
75
85
76
86
/**
77
- * This is the only way to withdraw dividens from the DARC virtual machine
87
+ * This is the only way to withdraw dividends from the DARC virtual machine
78
88
* @param amount The amount of cash to be withdrawn
79
89
*/
80
90
function withdrawDividends (uint256 amount ) public {
@@ -86,8 +96,8 @@ contract DARC is Runtime, Dashboard {
86
96
require (amount <= currentMachineState.withdrawableDividendMap[msg .sender ], string .concat ("Invalid withdraw amount. Amount: " , Strings.toString (amount), ", and withdrawable dividends: " , Strings.toString (currentMachineState.withdrawableDividendMap[msg .sender ])));
87
97
88
98
// first update the withdrawable cash map
89
- bool bIsValid = false ;
90
- uint256 result = 0 ;
99
+ bool bIsValid;
100
+ uint256 result;
91
101
(bIsValid, result) = SafeMathUpgradeable.trySub (currentMachineState.withdrawableDividendMap[msg .sender ], amount);
92
102
require (bIsValid, string .concat ("Invalid withdraw amount. Amount: " , Strings.toString (amount), ", and withdrawable dividends: " , Strings.toString (currentMachineState.withdrawableDividendMap[msg .sender ])));
93
103
@@ -100,20 +110,27 @@ contract DARC is Runtime, Dashboard {
100
110
// if the message sender owns zero withdrawable dividend balance, then remove it from the withdrawable dividend owner list
101
111
if (currentMachineState.withdrawableDividendMap[msg .sender ] == 0 ) {
102
112
address [] memory newWithdrawableDividendsOwnerList = new address [](currentMachineState.withdrawableDividendOwnerList.length );
103
- uint256 pt = 0 ;
104
- for (uint256 index = 0 ; index < currentMachineState.withdrawableDividendOwnerList.length ; index ++ ) {
113
+ uint256 pt;
114
+ for (uint256 index; index < currentMachineState.withdrawableDividendOwnerList.length ;) {
105
115
if (currentMachineState.withdrawableDividendOwnerList[index] != msg .sender ) {
106
116
newWithdrawableDividendsOwnerList[pt] = currentMachineState.withdrawableDividendOwnerList[index];
107
117
pt++ ;
108
118
}
119
+
120
+ unchecked {
121
+ ++ index;
122
+ }
109
123
}
110
124
111
125
// update the withdrawable cash owner list
112
126
currentMachineState.withdrawableDividendOwnerList = new address [](pt);
113
- for (uint256 index = 0 ; index < pt; index ++ ) {
127
+ for (uint256 index; index < pt;) {
114
128
currentMachineState.withdrawableDividendOwnerList[index] = newWithdrawableDividendsOwnerList[index];
129
+ unchecked {
130
+ ++ index;
131
+ }
115
132
}
116
133
}
117
134
118
135
}
119
- }
136
+ }
0 commit comments