Rationale
After the stake2.0 code was launched, some of the codes were found that could be optimized, and here these codes are proposed for discussion and optimization.
-
call in the for loop: votesCapsule.addNewVotes
- Solution: It is recommended to add to the list first, and then call addAll
-
The code of estimateConsumeBandWidthSize is too complicated and needs to be simplified
- Solution: It is recommended to remove redundant code and streamline the code.
-
GetCanDelegatedMaxSize has many repeated codes.
- Solution: It is recommended to encapsulate it into a function and reuse the code.
-
The description of exception information in stake 2.0 is inaccurate.
- Solution: It is recommended to describe the exception information accurately.
Implementation
-
Located in: updateVote method of UnfreezeBalanceV2Actuator class
- Add a List addVotes instead and do addAll once.
-
Located in: estimateConsumeBandWidthSize method of TransactionUtil class
- There are some redundant codes in the method of calculating the estimated transaction size, which can be simplified
-
The getCanDelegatedMaxSize function in the Wallet are duplicated with other codes in the other place, and can be reused
- It can be abstracted: getV2NetUsage, getV2EnergyUsage for code reuse.
-
Optimize the description of Stake 2.0 exception messages
- When delegateBalance < TRX_PRECISION in DelegateResourceActuator.java, description 'delegateBalance must be more than 1 TRX' is replaced with'delegateBalance must be greater than or equal to 1 TRX'
- When ownerCapsule.getFrozenV2BalanceForBandwidth() - remainNetUsage < delegateBalance in DelegateResourceActuator.java, description 'delegateBalance must be less than available FreezeBandwidthV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeBandwidthV2 balance'
- When ownerCapsule.getFrozenV2BalanceForEnergy() - remainEnergyUsage < delegateBalance in DelegateResourceActuator.java, description 'delegateBalance must be less than available FreezeEnergyV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeEnergyV2 balance'
- When frozenBalance < TRX_PRECISION in FreezeBalanceActuator.java, description 'frozenBalance must be more than 1TRX' is replaced with 'frozenBalance must be greater than or equal to 1 TRX'
- When frozenBalance > accountCapsule.getBalance() in FreezeBalanceActuator.java, description 'frozenBalance must be less than accountBalance' is replaced with 'frozenBalance must be less than or equal to accountBalance'
- When frozenBalance < TRX_PRECISION in FreezeBalanceV2Actuator.java, description 'frozenBalance must be more than 1TRX' is replaced with 'frozenBalance must be greater than or equal to 1 TRX'
- When frozenBalance > accountCapsule.getBalance() in FreezeBalanceV2Actuator.java, description 'frozenBalance must be less than accountBalance' is replaced with 'frozenBalance must be less than or equal to accountBalance'
- When delegateBalance < TRX_PRECISION in DelegateResourceProcessor.java, description 'delegateBalance must be more than 1TRX' is replaced with 'delegateBalance must be greater than or equal to 1 TRX'
- When ownerCapsule.getFrozenV2BalanceForBandwidth() - v2NetUsage < delegateBalance in DelegateResourceProcessor.java, description 'delegateBalance must be less than available FreezeBandwidthV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeBandwidthV2 balance'
- When ownerCapsule.getFrozenV2BalanceForEnergy() - v2EnergyUsage < delegateBalance in DelegateResourceProcessor.java, description 'delegateBalance must be less than available FreezeEnergyV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeEnergyV2 balance'
- When frozenBalance < TRX_PRECISION in FreezeBalanceProcessor.java, description 'FrozenBalance must be less than accountBalance' is replaced with 'FrozenBalance must be less than or equal to accountBalance'
- When frozenBalance < TRX_PRECISION in FreezeBalanceV2Processor.java, description 'FrozenBalance must be more than 1TRX' is replaced with 'FrozenBalance must be greater than or equal to 1 TRX'
- When frozenBalance > ownerCapsule.getBalance() in FreezeBalanceV2Processor.java, description 'FrozenBalance must be less than accountBalance' is replaced with 'FrozenBalance must be less than or equal to accountBalance'
Are you willing to implement this feature?
Yes, I have completed the code
Rationale
After the stake2.0 code was launched, some of the codes were found that could be optimized, and here these codes are proposed for discussion and optimization.
call in the for loop: votesCapsule.addNewVotes
The code of estimateConsumeBandWidthSize is too complicated and needs to be simplified
GetCanDelegatedMaxSize has many repeated codes.
The description of exception information in stake 2.0 is inaccurate.
Implementation
Located in: updateVote method of UnfreezeBalanceV2Actuator class
Located in: estimateConsumeBandWidthSize method of TransactionUtil class
The getCanDelegatedMaxSize function in the Wallet are duplicated with other codes in the other place, and can be reused
Optimize the description of Stake 2.0 exception messages
- When
delegateBalance < TRX_PRECISIONin DelegateResourceActuator.java, description'delegateBalance must be more than 1 TRX'is replaced with'delegateBalance must be greater than or equal to 1 TRX'- When
ownerCapsule.getFrozenV2BalanceForBandwidth() - remainNetUsage < delegateBalancein DelegateResourceActuator.java, description'delegateBalance must be less than available FreezeBandwidthV2 balance'is replaced with'delegateBalance must be less than or equal to available FreezeBandwidthV2 balance'- When
ownerCapsule.getFrozenV2BalanceForEnergy() - remainEnergyUsage < delegateBalancein DelegateResourceActuator.java, description'delegateBalance must be less than available FreezeEnergyV2 balance'is replaced with'delegateBalance must be less than or equal to available FreezeEnergyV2 balance'- When
frozenBalance < TRX_PRECISIONin FreezeBalanceActuator.java, description'frozenBalance must be more than 1TRX'is replaced with'frozenBalance must be greater than or equal to 1 TRX'- When
frozenBalance > accountCapsule.getBalance()in FreezeBalanceActuator.java, description'frozenBalance must be less than accountBalance'is replaced with'frozenBalance must be less than or equal to accountBalance'- When
frozenBalance < TRX_PRECISIONin FreezeBalanceV2Actuator.java, description'frozenBalance must be more than 1TRX'is replaced with'frozenBalance must be greater than or equal to 1 TRX'- When
frozenBalance > accountCapsule.getBalance()in FreezeBalanceV2Actuator.java, description'frozenBalance must be less than accountBalance'is replaced with'frozenBalance must be less than or equal to accountBalance'- When
delegateBalance < TRX_PRECISIONin DelegateResourceProcessor.java, description'delegateBalance must be more than 1TRX'is replaced with'delegateBalance must be greater than or equal to 1 TRX'- When
ownerCapsule.getFrozenV2BalanceForBandwidth() - v2NetUsage < delegateBalancein DelegateResourceProcessor.java, description'delegateBalance must be less than available FreezeBandwidthV2 balance'is replaced with'delegateBalance must be less than or equal to available FreezeBandwidthV2 balance'- When
ownerCapsule.getFrozenV2BalanceForEnergy() - v2EnergyUsage < delegateBalancein DelegateResourceProcessor.java, description'delegateBalance must be less than available FreezeEnergyV2 balance'is replaced with'delegateBalance must be less than or equal to available FreezeEnergyV2 balance'- When
frozenBalance < TRX_PRECISIONin FreezeBalanceProcessor.java, description'FrozenBalance must be less than accountBalance'is replaced with'FrozenBalance must be less than or equal to accountBalance'- When
frozenBalance < TRX_PRECISIONin FreezeBalanceV2Processor.java, description'FrozenBalance must be more than 1TRX'is replaced with'FrozenBalance must be greater than or equal to 1 TRX'- When
frozenBalance > ownerCapsule.getBalance()in FreezeBalanceV2Processor.java, description'FrozenBalance must be less than accountBalance'is replaced with'FrozenBalance must be less than or equal to accountBalance'Are you willing to implement this feature?
Yes, I have completed the code