Skip to content

Commit 84b0116

Browse files
committed
fix(freezeV2): optimize the query return of the interface
1 parent da2673c commit 84b0116

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,26 @@ public DelegatedResourceList getDelegatedResourceV2(
765765
.createDbKeyV2(fromAddress.toByteArray(), toAddress.toByteArray(), false);
766766
DelegatedResourceCapsule unlockResource = chainBaseManager.getDelegatedResourceStore()
767767
.get(dbKey);
768-
if (unlockResource != null) {
768+
if (nonEmptyResource(unlockResource)) {
769769
builder.addDelegatedResource(unlockResource.getInstance());
770770
}
771771
dbKey = DelegatedResourceCapsule
772772
.createDbKeyV2(fromAddress.toByteArray(), toAddress.toByteArray(), true);
773773
DelegatedResourceCapsule lockResource = chainBaseManager.getDelegatedResourceStore()
774774
.get(dbKey);
775-
if (lockResource != null) {
775+
if (nonEmptyResource(lockResource)) {
776776
builder.addDelegatedResource(lockResource.getInstance());
777777
}
778778
return builder.build();
779779
}
780780

781+
private boolean nonEmptyResource(DelegatedResourceCapsule resource) {
782+
return Objects.nonNull(resource) && !(resource.getExpireTimeForBandwidth() == 0
783+
&& resource.getExpireTimeForEnergy() == 0
784+
&& resource.getFrozenBalanceForBandwidth() == 0
785+
&& resource.getFrozenBalanceForEnergy() == 0);
786+
}
787+
781788
public GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage getCanWithdrawUnfreezeAmount(
782789
ByteString ownerAddress, long timestamp) {
783790
GrpcAPI.CanWithdrawUnfreezeAmountResponseMessage.Builder builder =

framework/src/test/java/org/tron/core/WalletTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ private Any getLockedDelegateContractForBandwidth(String ownerAddress, String re
728728
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(ownerAddress)))
729729
.setReceiverAddress(ByteString.copyFrom(ByteArray.fromHexString(receiveAddress)))
730730
.setBalance(unfreezeBalance)
731-
.setResource(Common.ResourceCode.BANDWIDTH)
731+
.setResource(BANDWIDTH)
732732
.setLock(lock)
733733
.build());
734734
}
@@ -753,6 +753,11 @@ public void testGetDelegatedResourceV2() {
753753
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
754754
ByteString.copyFrom(ByteArray.fromHexString(RECEIVER_ADDRESS)));
755755

756+
Protocol.Account account = Protocol.Account.newBuilder()
757+
.setAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))).build();
758+
wallet.getAccount(account);
759+
wallet.getProposalList();
760+
wallet.getWitnessList();
756761
Assert.assertEquals(1L, delegatedResourceList.getDelegatedResourceCount());
757762
Assert.assertEquals(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
758763
delegatedResourceList.getDelegatedResource(0).getFrom());
@@ -809,7 +814,7 @@ public void testGetCanDelegatedMaxSizeBandWidth() {
809814

810815
GrpcAPI.CanDelegatedMaxSizeResponseMessage message = wallet.getCanDelegatedMaxSize(
811816
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
812-
Common.ResourceCode.BANDWIDTH.getNumber());
817+
BANDWIDTH.getNumber());
813818
Assert.assertEquals(initBalance - 280L, message.getMaxSize());
814819

815820
}
@@ -832,7 +837,7 @@ private Any getContractForBandwidthV2(String ownerAddress, long unfreezeBalance)
832837
ByteString.copyFrom(ByteArray.fromHexString(ownerAddress))
833838
)
834839
.setUnfreezeBalance(unfreezeBalance)
835-
.setResource(Common.ResourceCode.BANDWIDTH)
840+
.setResource(BANDWIDTH)
836841
.build()
837842
);
838843
}

0 commit comments

Comments
 (0)