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 ;
@@ -55,8 +59,11 @@ public boolean execute(Object result) throws ContractExeException {
5559 long now = dynamicStore .getLatestBlockHeaderTimestamp ();
5660 AtomicLong atomicWithdrawExpireBalance = new AtomicLong (0L );
5761 AtomicLong atomicCancelBalance = new AtomicLong (0L );
58- Triple <AtomicLong , AtomicLong , AtomicLong > triple =
59- Triple .of (new AtomicLong (0L ), new AtomicLong (0L ), new AtomicLong (0L ));
62+ Triple <Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >>
63+ triple = Triple .of (
64+ Pair .of (new AtomicLong (0L ), new AtomicLong (0L )),
65+ Pair .of (new AtomicLong (0L ), new AtomicLong (0L )),
66+ Pair .of (new AtomicLong (0L ), new AtomicLong (0L )));
6067 for (UnFreezeV2 unFreezeV2 : unfrozenV2List ) {
6168 updateAndCalculate (triple , ownerCapsule , now , atomicWithdrawExpireBalance ,
6269 atomicCancelBalance , unFreezeV2 );
@@ -72,18 +79,26 @@ public boolean execute(Object result) throws ContractExeException {
7279 accountStore .put (ownerCapsule .createDbKey (), ownerCapsule );
7380 ret .setWithdrawExpireAmount (withdrawExpireBalance );
7481 ret .setCancelAllUnfreezeV2Amount (atomicCancelBalance .get ());
82+ Map <String , Long > cancelUnfreezeV2AmountMap = new HashMap <>();
83+ cancelUnfreezeV2AmountMap .put (BANDWIDTH .name (), triple .getLeft ().getRight ().get ());
84+ cancelUnfreezeV2AmountMap .put (ENERGY .name (), triple .getMiddle ().getRight ().get ());
85+ cancelUnfreezeV2AmountMap .put (TRON_POWER .name (), triple .getRight ().getRight ().get ());
86+ ret .putAllCancelUnfreezeV2AmountMap (cancelUnfreezeV2AmountMap );
7587 ret .setStatus (fee , code .SUCESS );
7688 return true ;
7789 }
7890
7991 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 ());
92+ Triple <Pair <AtomicLong , AtomicLong >,
93+ Pair <AtomicLong , AtomicLong >,
94+ Pair <AtomicLong , AtomicLong >> triple ) {
95+ dynamicStore .addTotalNetWeight (triple .getLeft ().getLeft ().get ());
96+ dynamicStore .addTotalEnergyWeight (triple .getMiddle ().getLeft ().get ());
97+ dynamicStore .addTotalTronPowerWeight (triple .getRight ().getLeft ().get ());
8498 }
8599
86- private void updateAndCalculate (Triple <AtomicLong , AtomicLong , AtomicLong > triple ,
100+ private void updateAndCalculate (Triple <Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >,
101+ Pair <AtomicLong , AtomicLong >> triple ,
87102 AccountCapsule ownerCapsule , long now , AtomicLong atomicLong , AtomicLong cancelBalance ,
88103 UnFreezeV2 unFreezeV2 ) {
89104 if (unFreezeV2 .getUnfreezeExpireTime () > now ) {
@@ -160,25 +175,29 @@ public long calcFee() {
160175
161176 public void updateFrozenInfoAndTotalResourceWeight (
162177 AccountCapsule accountCapsule , UnFreezeV2 unFreezeV2 ,
163- Triple <AtomicLong , AtomicLong , AtomicLong > triple ) {
178+ Triple <Pair <AtomicLong , AtomicLong >, Pair <AtomicLong , AtomicLong >,
179+ Pair <AtomicLong , AtomicLong >> triple ) {
164180 switch (unFreezeV2 .getType ()) {
165181 case BANDWIDTH :
166182 long oldNetWeight = accountCapsule .getFrozenV2BalanceWithDelegated (BANDWIDTH ) / TRX_PRECISION ;
167183 accountCapsule .addFrozenBalanceForBandwidthV2 (unFreezeV2 .getUnfreezeAmount ());
168184 long newNetWeight = accountCapsule .getFrozenV2BalanceWithDelegated (BANDWIDTH ) / TRX_PRECISION ;
169- triple .getLeft ().addAndGet (newNetWeight - oldNetWeight );
185+ triple .getLeft ().getLeft ().addAndGet (newNetWeight - oldNetWeight );
186+ triple .getLeft ().getRight ().addAndGet (unFreezeV2 .getUnfreezeAmount ());
170187 break ;
171188 case ENERGY :
172189 long oldEnergyWeight = accountCapsule .getFrozenV2BalanceWithDelegated (ENERGY ) / TRX_PRECISION ;
173190 accountCapsule .addFrozenBalanceForEnergyV2 (unFreezeV2 .getUnfreezeAmount ());
174191 long newEnergyWeight = accountCapsule .getFrozenV2BalanceWithDelegated (ENERGY ) / TRX_PRECISION ;
175- triple .getMiddle ().addAndGet (newEnergyWeight - oldEnergyWeight );
192+ triple .getMiddle ().getLeft ().addAndGet (newEnergyWeight - oldEnergyWeight );
193+ triple .getMiddle ().getRight ().addAndGet (unFreezeV2 .getUnfreezeAmount ());
176194 break ;
177195 case TRON_POWER :
178196 long oldTPWeight = accountCapsule .getTronPowerFrozenV2Balance () / TRX_PRECISION ;
179197 accountCapsule .addFrozenForTronPowerV2 (unFreezeV2 .getUnfreezeAmount ());
180198 long newTPWeight = accountCapsule .getTronPowerFrozenV2Balance () / TRX_PRECISION ;
181- triple .getRight ().addAndGet (newTPWeight - oldTPWeight );
199+ triple .getRight ().getLeft ().addAndGet (newTPWeight - oldTPWeight );
200+ triple .getRight ().getRight ().addAndGet (unFreezeV2 .getUnfreezeAmount ());
182201 break ;
183202 default :
184203 break ;
0 commit comments