diff --git a/actuator/src/main/java/org/tron/core/actuator/CancelAllUnfreezeV2Actuator.java b/actuator/src/main/java/org/tron/core/actuator/CancelAllUnfreezeV2Actuator.java index 8fd58124b1a..000b8443a59 100755 --- a/actuator/src/main/java/org/tron/core/actuator/CancelAllUnfreezeV2Actuator.java +++ b/actuator/src/main/java/org/tron/core/actuator/CancelAllUnfreezeV2Actuator.java @@ -5,13 +5,17 @@ import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION; import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH; import static org.tron.protos.contract.Common.ResourceCode.ENERGY; +import static org.tron.protos.contract.Common.ResourceCode.TRON_POWER; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicLong; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import org.tron.common.utils.DecodeUtil; import org.tron.common.utils.StringUtil; @@ -55,8 +59,11 @@ public boolean execute(Object result) throws ContractExeException { long now = dynamicStore.getLatestBlockHeaderTimestamp(); AtomicLong atomicWithdrawExpireBalance = new AtomicLong(0L); AtomicLong atomicCancelBalance = new AtomicLong(0L); - Triple triple = - Triple.of(new AtomicLong(0L), new AtomicLong(0L), new AtomicLong(0L)); + Triple, Pair, Pair> + triple = Triple.of( + Pair.of(new AtomicLong(0L), new AtomicLong(0L)), + Pair.of(new AtomicLong(0L), new AtomicLong(0L)), + Pair.of(new AtomicLong(0L), new AtomicLong(0L))); for (UnFreezeV2 unFreezeV2 : unfrozenV2List) { updateAndCalculate(triple, ownerCapsule, now, atomicWithdrawExpireBalance, atomicCancelBalance, unFreezeV2); @@ -72,18 +79,26 @@ public boolean execute(Object result) throws ContractExeException { accountStore.put(ownerCapsule.createDbKey(), ownerCapsule); ret.setWithdrawExpireAmount(withdrawExpireBalance); ret.setCancelAllUnfreezeV2Amount(atomicCancelBalance.get()); + Map cancelUnfreezeV2AmountMap = new HashMap<>(); + cancelUnfreezeV2AmountMap.put(BANDWIDTH.name(), triple.getLeft().getRight().get()); + cancelUnfreezeV2AmountMap.put(ENERGY.name(), triple.getMiddle().getRight().get()); + cancelUnfreezeV2AmountMap.put(TRON_POWER.name(), triple.getRight().getRight().get()); + ret.putAllCancelUnfreezeV2AmountMap(cancelUnfreezeV2AmountMap); ret.setStatus(fee, code.SUCESS); return true; } private void addTotalResourceWeight(DynamicPropertiesStore dynamicStore, - Triple triple) { - dynamicStore.addTotalNetWeight(triple.getLeft().get()); - dynamicStore.addTotalEnergyWeight(triple.getMiddle().get()); - dynamicStore.addTotalTronPowerWeight(triple.getRight().get()); + Triple, + Pair, + Pair> triple) { + dynamicStore.addTotalNetWeight(triple.getLeft().getLeft().get()); + dynamicStore.addTotalEnergyWeight(triple.getMiddle().getLeft().get()); + dynamicStore.addTotalTronPowerWeight(triple.getRight().getLeft().get()); } - private void updateAndCalculate(Triple triple, + private void updateAndCalculate(Triple, Pair, + Pair> triple, AccountCapsule ownerCapsule, long now, AtomicLong atomicLong, AtomicLong cancelBalance, UnFreezeV2 unFreezeV2) { if (unFreezeV2.getUnfreezeExpireTime() > now) { @@ -160,25 +175,29 @@ public long calcFee() { public void updateFrozenInfoAndTotalResourceWeight( AccountCapsule accountCapsule, UnFreezeV2 unFreezeV2, - Triple triple) { + Triple, Pair, + Pair> triple) { switch (unFreezeV2.getType()) { case BANDWIDTH: long oldNetWeight = accountCapsule.getFrozenV2BalanceWithDelegated(BANDWIDTH) / TRX_PRECISION; accountCapsule.addFrozenBalanceForBandwidthV2(unFreezeV2.getUnfreezeAmount()); long newNetWeight = accountCapsule.getFrozenV2BalanceWithDelegated(BANDWIDTH) / TRX_PRECISION; - triple.getLeft().addAndGet(newNetWeight - oldNetWeight); + triple.getLeft().getLeft().addAndGet(newNetWeight - oldNetWeight); + triple.getLeft().getRight().addAndGet(unFreezeV2.getUnfreezeAmount()); break; case ENERGY: long oldEnergyWeight = accountCapsule.getFrozenV2BalanceWithDelegated(ENERGY) / TRX_PRECISION; accountCapsule.addFrozenBalanceForEnergyV2(unFreezeV2.getUnfreezeAmount()); long newEnergyWeight = accountCapsule.getFrozenV2BalanceWithDelegated(ENERGY) / TRX_PRECISION; - triple.getMiddle().addAndGet(newEnergyWeight - oldEnergyWeight); + triple.getMiddle().getLeft().addAndGet(newEnergyWeight - oldEnergyWeight); + triple.getMiddle().getRight().addAndGet(unFreezeV2.getUnfreezeAmount()); break; case TRON_POWER: long oldTPWeight = accountCapsule.getTronPowerFrozenV2Balance() / TRX_PRECISION; accountCapsule.addFrozenForTronPowerV2(unFreezeV2.getUnfreezeAmount()); long newTPWeight = accountCapsule.getTronPowerFrozenV2Balance() / TRX_PRECISION; - triple.getRight().addAndGet(newTPWeight - oldTPWeight); + triple.getRight().getLeft().addAndGet(newTPWeight - oldTPWeight); + triple.getRight().getRight().addAndGet(unFreezeV2.getUnfreezeAmount()); break; default: break; diff --git a/chainbase/src/main/java/org/tron/core/capsule/TransactionResultCapsule.java b/chainbase/src/main/java/org/tron/core/capsule/TransactionResultCapsule.java index be86a95f4f6..94fc3f1ee51 100644 --- a/chainbase/src/main/java/org/tron/core/capsule/TransactionResultCapsule.java +++ b/chainbase/src/main/java/org/tron/core/capsule/TransactionResultCapsule.java @@ -3,6 +3,7 @@ import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import java.util.List; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.tron.core.exception.BadItemException; import org.tron.protos.Protocol.MarketOrderDetail; @@ -98,6 +99,15 @@ public void setCancelAllUnfreezeV2Amount(long amount) { .setCancelAllUnfreezeV2Amount(amount).build(); } + public Map getCancelUnfreezeV2AmountMap() { + return transactionResult.getCancelUnfreezeV2AmountMap(); + } + + public void putAllCancelUnfreezeV2AmountMap(Map map) { + this.transactionResult = this.transactionResult.toBuilder() + .putAllCancelUnfreezeV2Amount(map).build(); + } + public long getExchangeReceivedAmount() { return transactionResult.getExchangeReceivedAmount(); } diff --git a/chainbase/src/main/java/org/tron/core/capsule/utils/TransactionUtil.java b/chainbase/src/main/java/org/tron/core/capsule/utils/TransactionUtil.java index 047a21b68cb..0886304af14 100644 --- a/chainbase/src/main/java/org/tron/core/capsule/utils/TransactionUtil.java +++ b/chainbase/src/main/java/org/tron/core/capsule/utils/TransactionUtil.java @@ -101,6 +101,7 @@ public static TransactionInfoCapsule buildTransactionInfoInstance(TransactionCap builder.setWithdrawAmount(programResult.getRet().getWithdrawAmount()); builder.setWithdrawExpireAmount(programResult.getRet().getWithdrawExpireAmount()); builder.setCancelAllUnfreezeV2Amount(programResult.getRet().getCancelAllUnfreezeV2Amount()); + builder.putAllCancelUnfreezeV2Amount(programResult.getRet().getCancelUnfreezeV2AmountMap()); builder.setExchangeReceivedAmount(programResult.getRet().getExchangeReceivedAmount()); builder.setExchangeInjectAnotherAmount(programResult.getRet().getExchangeInjectAnotherAmount()); builder.setExchangeWithdrawAnotherAmount( diff --git a/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java b/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java index 5b417833c1d..fcc545a0fc2 100644 --- a/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java +++ b/framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java @@ -9,6 +9,7 @@ import com.google.protobuf.Any; import com.google.protobuf.ByteString; +import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.junit.Before; import org.junit.Test; @@ -81,8 +82,13 @@ public void testCancelAllUnfreezeV2() { assertEquals(SUCESS, ret.getInstance().getRet()); AccountCapsule owner = dbManager.getAccountStore() .get(ByteArray.fromHexString(OWNER_ADDRESS)); + Map cancelUnfreezeV2AmountMap = ret.getInstance() + .getCancelUnfreezeV2AmountMap(); assertEquals(2000000L, ret.getInstance().getWithdrawExpireAmount()); assertEquals(0, owner.getUnfrozenV2List().size()); + assertEquals(8000000L, cancelUnfreezeV2AmountMap.get("BANDWIDTH").longValue()); + assertEquals(8000000L, cancelUnfreezeV2AmountMap.get("ENERGY").longValue()); + assertEquals(0, cancelUnfreezeV2AmountMap.get("TRON_POWER").longValue()); } catch (ContractValidateException | ContractExeException e) { fail(); } diff --git a/protocol/src/main/protos/core/Tron.proto b/protocol/src/main/protos/core/Tron.proto index f52c21162d6..a3650ee0a38 100644 --- a/protocol/src/main/protos/core/Tron.proto +++ b/protocol/src/main/protos/core/Tron.proto @@ -424,6 +424,7 @@ message Transaction { repeated MarketOrderDetail orderDetails = 26; int64 withdraw_expire_amount = 27; int64 cancel_all_unfreezeV2_amount = 28; + map cancel_unfreezeV2_amount = 29; } message raw { @@ -485,6 +486,7 @@ message TransactionInfo { int64 withdraw_expire_amount = 28; int64 cancel_all_unfreezeV2_amount = 29; + map cancel_unfreezeV2_amount = 30; } message TransactionRet {