5
5
import static org .tron .core .config .Parameter .ChainConstant .TRX_PRECISION ;
6
6
import static org .tron .protos .contract .Common .ResourceCode .BANDWIDTH ;
7
7
import static org .tron .protos .contract .Common .ResourceCode .ENERGY ;
8
+ import static org .tron .protos .contract .Common .ResourceCode .TRON_POWER ;
8
9
9
10
import com .google .protobuf .ByteString ;
10
11
import com .google .protobuf .InvalidProtocolBufferException ;
12
+ import java .util .HashMap ;
11
13
import java .util .List ;
14
+ import java .util .Map ;
12
15
import java .util .Objects ;
13
16
import java .util .concurrent .atomic .AtomicLong ;
14
17
import lombok .extern .slf4j .Slf4j ;
18
+ import org .apache .commons .lang3 .tuple .Pair ;
15
19
import org .apache .commons .lang3 .tuple .Triple ;
16
20
import org .tron .common .utils .DecodeUtil ;
17
21
import org .tron .common .utils .StringUtil ;
@@ -54,12 +58,13 @@ public boolean execute(Object result) throws ContractExeException {
54
58
List <UnFreezeV2 > unfrozenV2List = ownerCapsule .getUnfrozenV2List ();
55
59
long now = dynamicStore .getLatestBlockHeaderTimestamp ();
56
60
AtomicLong atomicWithdrawExpireBalance = new AtomicLong (0L );
57
- AtomicLong atomicCancelBalance = new AtomicLong (0L );
58
- Triple <AtomicLong , AtomicLong , AtomicLong > triple =
59
- Triple .of (new AtomicLong (0L ), new AtomicLong (0L ), new AtomicLong (0L ));
61
+ Triple <Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >>
62
+ triple = Triple .of (
63
+ Pair .of (new AtomicLong (0L ), new AtomicLong (0L )),
64
+ Pair .of (new AtomicLong (0L ), new AtomicLong (0L )),
65
+ Pair .of (new AtomicLong (0L ), new AtomicLong (0L )));
60
66
for (UnFreezeV2 unFreezeV2 : unfrozenV2List ) {
61
- updateAndCalculate (triple , ownerCapsule , now , atomicWithdrawExpireBalance ,
62
- atomicCancelBalance , unFreezeV2 );
67
+ updateAndCalculate (triple , ownerCapsule , now , atomicWithdrawExpireBalance , unFreezeV2 );
63
68
}
64
69
ownerCapsule .clearUnfrozenV2 ();
65
70
addTotalResourceWeight (dynamicStore , triple );
@@ -71,24 +76,29 @@ public boolean execute(Object result) throws ContractExeException {
71
76
72
77
accountStore .put (ownerCapsule .createDbKey (), ownerCapsule );
73
78
ret .setWithdrawExpireAmount (withdrawExpireBalance );
74
- ret .setCancelAllUnfreezeV2Amount (atomicCancelBalance .get ());
79
+ Map <String , Long > cancelUnfreezeV2AmountMap = new HashMap <>();
80
+ cancelUnfreezeV2AmountMap .put (BANDWIDTH .name (), triple .getLeft ().getRight ().get ());
81
+ cancelUnfreezeV2AmountMap .put (ENERGY .name (), triple .getMiddle ().getRight ().get ());
82
+ cancelUnfreezeV2AmountMap .put (TRON_POWER .name (), triple .getRight ().getRight ().get ());
83
+ ret .putAllCancelUnfreezeV2AmountMap (cancelUnfreezeV2AmountMap );
75
84
ret .setStatus (fee , code .SUCESS );
76
85
return true ;
77
86
}
78
87
79
88
private void addTotalResourceWeight (DynamicPropertiesStore dynamicStore ,
80
- Triple <AtomicLong , AtomicLong , AtomicLong > triple ) {
81
- dynamicStore .addTotalNetWeight (triple .getLeft ().get ());
82
- dynamicStore .addTotalEnergyWeight (triple .getMiddle ().get ());
83
- dynamicStore .addTotalTronPowerWeight (triple .getRight ().get ());
89
+ Triple <Pair <AtomicLong , AtomicLong >,
90
+ Pair <AtomicLong , AtomicLong >,
91
+ Pair <AtomicLong , AtomicLong >> triple ) {
92
+ dynamicStore .addTotalNetWeight (triple .getLeft ().getLeft ().get ());
93
+ dynamicStore .addTotalEnergyWeight (triple .getMiddle ().getLeft ().get ());
94
+ dynamicStore .addTotalTronPowerWeight (triple .getRight ().getLeft ().get ());
84
95
}
85
96
86
- private void updateAndCalculate (Triple <AtomicLong , AtomicLong , AtomicLong > triple ,
87
- AccountCapsule ownerCapsule , long now , AtomicLong atomicLong , AtomicLong cancelBalance ,
88
- UnFreezeV2 unFreezeV2 ) {
97
+ private void updateAndCalculate (Triple <Pair < AtomicLong , AtomicLong >, Pair < AtomicLong , AtomicLong > ,
98
+ Pair < AtomicLong , AtomicLong >> triple ,
99
+ AccountCapsule ownerCapsule , long now , AtomicLong atomicLong , UnFreezeV2 unFreezeV2 ) {
89
100
if (unFreezeV2 .getUnfreezeExpireTime () > now ) {
90
101
updateFrozenInfoAndTotalResourceWeight (ownerCapsule , unFreezeV2 , triple );
91
- cancelBalance .addAndGet (unFreezeV2 .getUnfreezeAmount ());
92
102
} else {
93
103
atomicLong .addAndGet (unFreezeV2 .getUnfreezeAmount ());
94
104
}
@@ -160,25 +170,29 @@ public long calcFee() {
160
170
161
171
public void updateFrozenInfoAndTotalResourceWeight (
162
172
AccountCapsule accountCapsule , UnFreezeV2 unFreezeV2 ,
163
- Triple <AtomicLong , AtomicLong , AtomicLong > triple ) {
173
+ Triple <Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >,
174
+ Pair <AtomicLong , AtomicLong >> triple ) {
164
175
switch (unFreezeV2 .getType ()) {
165
176
case BANDWIDTH :
166
177
long oldNetWeight = accountCapsule .getFrozenV2BalanceWithDelegated (BANDWIDTH ) / TRX_PRECISION ;
167
178
accountCapsule .addFrozenBalanceForBandwidthV2 (unFreezeV2 .getUnfreezeAmount ());
168
179
long newNetWeight = accountCapsule .getFrozenV2BalanceWithDelegated (BANDWIDTH ) / TRX_PRECISION ;
169
- triple .getLeft ().addAndGet (newNetWeight - oldNetWeight );
180
+ triple .getLeft ().getLeft ().addAndGet (newNetWeight - oldNetWeight );
181
+ triple .getLeft ().getRight ().addAndGet (unFreezeV2 .getUnfreezeAmount ());
170
182
break ;
171
183
case ENERGY :
172
184
long oldEnergyWeight = accountCapsule .getFrozenV2BalanceWithDelegated (ENERGY ) / TRX_PRECISION ;
173
185
accountCapsule .addFrozenBalanceForEnergyV2 (unFreezeV2 .getUnfreezeAmount ());
174
186
long newEnergyWeight = accountCapsule .getFrozenV2BalanceWithDelegated (ENERGY ) / TRX_PRECISION ;
175
- triple .getMiddle ().addAndGet (newEnergyWeight - oldEnergyWeight );
187
+ triple .getMiddle ().getLeft ().addAndGet (newEnergyWeight - oldEnergyWeight );
188
+ triple .getMiddle ().getRight ().addAndGet (unFreezeV2 .getUnfreezeAmount ());
176
189
break ;
177
190
case TRON_POWER :
178
191
long oldTPWeight = accountCapsule .getTronPowerFrozenV2Balance () / TRX_PRECISION ;
179
192
accountCapsule .addFrozenForTronPowerV2 (unFreezeV2 .getUnfreezeAmount ());
180
193
long newTPWeight = accountCapsule .getTronPowerFrozenV2Balance () / TRX_PRECISION ;
181
- triple .getRight ().addAndGet (newTPWeight - oldTPWeight );
194
+ triple .getRight ().getLeft ().addAndGet (newTPWeight - oldTPWeight );
195
+ triple .getRight ().getRight ().addAndGet (unFreezeV2 .getUnfreezeAmount ());
182
196
break ;
183
197
default :
184
198
break ;
0 commit comments