Skip to content

Commit

Permalink
feat(freezeV2): optimize total delegated resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Liulei committed Dec 27, 2022
1 parent 3cfd401 commit f92cb38
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
16 changes: 4 additions & 12 deletions actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -2120,13 +2120,9 @@ public Pair<Boolean, byte[]> execute(byte[] data) {

long delegatedResource = 0;
if (type == 0) {
delegatedResource =
accountCapsule.getDelegatedFrozenBalanceForBandwidth()
+ accountCapsule.getDelegatedFrozenV2BalanceForBandwidth();
delegatedResource = accountCapsule.getTotalDelegatedFrozenBalanceForBandwidth();
} else if (type == 1) {
delegatedResource =
accountCapsule.getDelegatedFrozenBalanceForEnergy()
+ accountCapsule.getDelegatedFrozenV2BalanceForEnergy();
delegatedResource = accountCapsule.getTotalDelegatedFrozenBalanceForEnergy();
}

return Pair.of(true, longTo32Bytes(delegatedResource));
Expand Down Expand Up @@ -2157,13 +2153,9 @@ public Pair<Boolean, byte[]> execute(byte[] data) {

long acquiredResource = 0;
if (type == 0) {
acquiredResource =
accountCapsule.getAcquiredDelegatedFrozenBalanceForBandwidth()
+ accountCapsule.getAcquiredDelegatedFrozenV2BalanceForBandwidth();
acquiredResource = accountCapsule.getTotalAcquiredDelegatedFrozenBalanceForBandwidth();
} else if (type == 1) {
acquiredResource =
accountCapsule.getAcquiredDelegatedFrozenBalanceForEnergy()
+ accountCapsule.getAcquiredDelegatedFrozenV2BalanceForEnergy();
acquiredResource = accountCapsule.getTotalAcquiredDelegatedFrozenBalanceForEnergy();
}

return Pair.of(true, longTo32Bytes(acquiredResource));
Expand Down
16 changes: 16 additions & 0 deletions chainbase/src/main/java/org/tron/core/capsule/AccountCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ public long getAcquiredDelegatedFrozenV2BalanceForBandwidth() {
return this.account.getAcquiredDelegatedFrozenV2BalanceForBandwidth();
}

public long getTotalAcquiredDelegatedFrozenBalanceForBandwidth() {
return getAcquiredDelegatedFrozenBalanceForBandwidth() + getAcquiredDelegatedFrozenV2BalanceForBandwidth();
}

public void addFrozenBalanceForBandwidthV2(long balance) {
this.addFrozenBalanceForResource(BANDWIDTH, balance);
}
Expand Down Expand Up @@ -415,6 +419,10 @@ public long getAcquiredDelegatedFrozenV2BalanceForEnergy() {
return getAccountResource().getAcquiredDelegatedFrozenV2BalanceForEnergy();
}

public long getTotalAcquiredDelegatedFrozenBalanceForEnergy() {
return getAcquiredDelegatedFrozenBalanceForEnergy() + getAcquiredDelegatedFrozenV2BalanceForEnergy();
}

public void setAcquiredDelegatedFrozenBalanceForEnergy(long balance) {
AccountResource newAccountResource = getAccountResource().toBuilder()
.setAcquiredDelegatedFrozenBalanceForEnergy(balance).build();
Expand All @@ -438,6 +446,10 @@ public long getDelegatedFrozenV2BalanceForEnergy() {
return getAccountResource().getDelegatedFrozenV2BalanceForEnergy();
}

public long getTotalDelegatedFrozenBalanceForEnergy() {
return getDelegatedFrozenBalanceForEnergy() + getDelegatedFrozenV2BalanceForEnergy();
}

public long getDelegatedFrozenBalanceForBandwidth() {
return this.account.getDelegatedFrozenBalanceForBandwidth();
}
Expand All @@ -446,6 +458,10 @@ public long getDelegatedFrozenV2BalanceForBandwidth() {
return this.account.getDelegatedFrozenV2BalanceForBandwidth();
}

public long getTotalDelegatedFrozenBalanceForBandwidth() {
return getDelegatedFrozenBalanceForBandwidth() + getDelegatedFrozenV2BalanceForBandwidth();
}

public void setDelegatedFrozenBalanceForBandwidth(long balance) {
this.account = this.account.toBuilder()
.setDelegatedFrozenBalanceForBandwidth(balance)
Expand Down

0 comments on commit f92cb38

Please sign in to comment.