Skip to content

Commit e11c31d

Browse files
Merge pull request #5279 from lxcmyf/release_v4.7.2
feat(freezeV2): modify CancelAllUnfreezeV2 return info
2 parents 6c20014 + 0c19160 commit e11c31d

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

actuator/src/main/java/org/tron/core/actuator/CancelAllUnfreezeV2Actuator.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import static org.tron.core.config.Parameter.ChainConstant.TRX_PRECISION;
66
import static org.tron.protos.contract.Common.ResourceCode.BANDWIDTH;
77
import static org.tron.protos.contract.Common.ResourceCode.ENERGY;
8+
import static org.tron.protos.contract.Common.ResourceCode.TRON_POWER;
89

910
import com.google.protobuf.ByteString;
1011
import com.google.protobuf.InvalidProtocolBufferException;
12+
import java.util.HashMap;
1113
import java.util.List;
14+
import java.util.Map;
1215
import java.util.Objects;
1316
import java.util.concurrent.atomic.AtomicLong;
1417
import lombok.extern.slf4j.Slf4j;
18+
import org.apache.commons.lang3.tuple.Pair;
1519
import org.apache.commons.lang3.tuple.Triple;
1620
import org.tron.common.utils.DecodeUtil;
1721
import 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;

chainbase/src/main/java/org/tron/core/capsule/TransactionResultCapsule.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.protobuf.ByteString;
44
import com.google.protobuf.InvalidProtocolBufferException;
55
import java.util.List;
6+
import java.util.Map;
67
import lombok.extern.slf4j.Slf4j;
78
import org.tron.core.exception.BadItemException;
89
import org.tron.protos.Protocol.MarketOrderDetail;
@@ -89,13 +90,13 @@ public void setWithdrawExpireAmount(long amount) {
8990
.setWithdrawExpireAmount(amount).build();
9091
}
9192

92-
public long getCancelAllUnfreezeV2Amount() {
93-
return transactionResult.getCancelAllUnfreezeV2Amount();
93+
public Map<String, Long> getCancelUnfreezeV2AmountMap() {
94+
return transactionResult.getCancelUnfreezeV2AmountMap();
9495
}
9596

96-
public void setCancelAllUnfreezeV2Amount(long amount) {
97+
public void putAllCancelUnfreezeV2AmountMap(Map<String, Long> map) {
9798
this.transactionResult = this.transactionResult.toBuilder()
98-
.setCancelAllUnfreezeV2Amount(amount).build();
99+
.putAllCancelUnfreezeV2Amount(map).build();
99100
}
100101

101102
public long getExchangeReceivedAmount() {

chainbase/src/main/java/org/tron/core/capsule/utils/TransactionUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static TransactionInfoCapsule buildTransactionInfoInstance(TransactionCap
100100
builder.setExchangeId(programResult.getRet().getExchangeId());
101101
builder.setWithdrawAmount(programResult.getRet().getWithdrawAmount());
102102
builder.setWithdrawExpireAmount(programResult.getRet().getWithdrawExpireAmount());
103-
builder.setCancelAllUnfreezeV2Amount(programResult.getRet().getCancelAllUnfreezeV2Amount());
103+
builder.putAllCancelUnfreezeV2Amount(programResult.getRet().getCancelUnfreezeV2AmountMap());
104104
builder.setExchangeReceivedAmount(programResult.getRet().getExchangeReceivedAmount());
105105
builder.setExchangeInjectAnotherAmount(programResult.getRet().getExchangeInjectAnotherAmount());
106106
builder.setExchangeWithdrawAnotherAmount(

framework/src/main/java/org/tron/core/services/jsonrpc/JsonRpcApiUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ public static long getAmountFromTransactionInfo(String hash, ContractType contra
337337
amount = transactionInfo.getWithdrawExpireAmount();
338338
break;
339339
case CancelAllUnfreezeV2Contract:
340-
amount = transactionInfo.getCancelAllUnfreezeV2Amount();
340+
amount = transactionInfo.getCancelUnfreezeV2AmountMap().values()
341+
.stream().mapToLong(v -> v).sum();
341342
break;
342343
default:
343344
break;

framework/src/test/java/org/tron/core/actuator/CancelAllUnfreezeV2ActuatorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.google.protobuf.Any;
1111
import com.google.protobuf.ByteString;
12+
import java.util.Map;
1213
import lombok.extern.slf4j.Slf4j;
1314
import org.junit.Before;
1415
import org.junit.Test;
@@ -81,8 +82,13 @@ public void testCancelAllUnfreezeV2() {
8182
assertEquals(SUCESS, ret.getInstance().getRet());
8283
AccountCapsule owner = dbManager.getAccountStore()
8384
.get(ByteArray.fromHexString(OWNER_ADDRESS));
85+
Map<String, Long> cancelUnfreezeV2AmountMap = ret.getInstance()
86+
.getCancelUnfreezeV2AmountMap();
8487
assertEquals(2000000L, ret.getInstance().getWithdrawExpireAmount());
8588
assertEquals(0, owner.getUnfrozenV2List().size());
89+
assertEquals(8000000L, cancelUnfreezeV2AmountMap.get("BANDWIDTH").longValue());
90+
assertEquals(8000000L, cancelUnfreezeV2AmountMap.get("ENERGY").longValue());
91+
assertEquals(0, cancelUnfreezeV2AmountMap.get("TRON_POWER").longValue());
8692
} catch (ContractValidateException | ContractExeException e) {
8793
fail();
8894
}

protocol/src/main/protos/core/Tron.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ message Transaction {
423423
bytes orderId = 25;
424424
repeated MarketOrderDetail orderDetails = 26;
425425
int64 withdraw_expire_amount = 27;
426-
int64 cancel_all_unfreezeV2_amount = 28;
426+
map<string, int64> cancel_unfreezeV2_amount = 28;
427427
}
428428

429429
message raw {
@@ -484,7 +484,7 @@ message TransactionInfo {
484484
int64 packingFee = 27;
485485

486486
int64 withdraw_expire_amount = 28;
487-
int64 cancel_all_unfreezeV2_amount = 29;
487+
map<string, int64> cancel_unfreezeV2_amount = 29;
488488
}
489489

490490
message TransactionRet {

0 commit comments

Comments
 (0)