55import static org .tron .core .config .Parameter .ChainConstant .TRX_PRECISION ;
66import static org .tron .protos .contract .Common .ResourceCode .BANDWIDTH ;
77import static org .tron .protos .contract .Common .ResourceCode .ENERGY ;
8+ import static org .tron .protos .contract .Common .ResourceCode .TRON_POWER ;
89
910import com .google .protobuf .ByteString ;
1011import com .google .protobuf .InvalidProtocolBufferException ;
12+ import java .util .HashMap ;
1113import java .util .List ;
14+ import java .util .Map ;
1215import java .util .Objects ;
1316import java .util .concurrent .atomic .AtomicLong ;
1417import lombok .extern .slf4j .Slf4j ;
18+ import org .apache .commons .lang3 .tuple .Pair ;
1519import org .apache .commons .lang3 .tuple .Triple ;
1620import org .tron .common .utils .DecodeUtil ;
1721import org .tron .common .utils .StringUtil ;
@@ -54,12 +58,13 @@ public boolean execute(Object result) throws ContractExeException {
5458 List <UnFreezeV2 > unfrozenV2List = ownerCapsule .getUnfrozenV2List ();
5559 long now = dynamicStore .getLatestBlockHeaderTimestamp ();
5660 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 )));
6066 for (UnFreezeV2 unFreezeV2 : unfrozenV2List ) {
61- updateAndCalculate (triple , ownerCapsule , now , atomicWithdrawExpireBalance ,
62- atomicCancelBalance , unFreezeV2 );
67+ updateAndCalculate (triple , ownerCapsule , now , atomicWithdrawExpireBalance , unFreezeV2 );
6368 }
6469 ownerCapsule .clearUnfrozenV2 ();
6570 addTotalResourceWeight (dynamicStore , triple );
@@ -71,24 +76,29 @@ public boolean execute(Object result) throws ContractExeException {
7176
7277 accountStore .put (ownerCapsule .createDbKey (), ownerCapsule );
7378 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 );
7584 ret .setStatus (fee , code .SUCESS );
7685 return true ;
7786 }
7887
7988 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 ());
8495 }
8596
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 ) {
89100 if (unFreezeV2 .getUnfreezeExpireTime () > now ) {
90101 updateFrozenInfoAndTotalResourceWeight (ownerCapsule , unFreezeV2 , triple );
91- cancelBalance .addAndGet (unFreezeV2 .getUnfreezeAmount ());
92102 } else {
93103 atomicLong .addAndGet (unFreezeV2 .getUnfreezeAmount ());
94104 }
@@ -160,25 +170,29 @@ public long calcFee() {
160170
161171 public void updateFrozenInfoAndTotalResourceWeight (
162172 AccountCapsule accountCapsule , UnFreezeV2 unFreezeV2 ,
163- Triple <AtomicLong , AtomicLong , AtomicLong > triple ) {
173+ Triple <Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >,
174+ Pair <AtomicLong , AtomicLong >> triple ) {
164175 switch (unFreezeV2 .getType ()) {
165176 case BANDWIDTH :
166177 long oldNetWeight = accountCapsule .getFrozenV2BalanceWithDelegated (BANDWIDTH ) / TRX_PRECISION ;
167178 accountCapsule .addFrozenBalanceForBandwidthV2 (unFreezeV2 .getUnfreezeAmount ());
168179 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 ());
170182 break ;
171183 case ENERGY :
172184 long oldEnergyWeight = accountCapsule .getFrozenV2BalanceWithDelegated (ENERGY ) / TRX_PRECISION ;
173185 accountCapsule .addFrozenBalanceForEnergyV2 (unFreezeV2 .getUnfreezeAmount ());
174186 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 ());
176189 break ;
177190 case TRON_POWER :
178191 long oldTPWeight = accountCapsule .getTronPowerFrozenV2Balance () / TRX_PRECISION ;
179192 accountCapsule .addFrozenForTronPowerV2 (unFreezeV2 .getUnfreezeAmount ());
180193 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 ());
182196 break ;
183197 default :
184198 break ;
0 commit comments