Description
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
- WhendelegateBalance < 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'
- WhenownerCapsule.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'
- WhenownerCapsule.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'
- WhenfrozenBalance < 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'
- WhenfrozenBalance > accountCapsule.getBalance()
in FreezeBalanceActuator.java, description'frozenBalance must be less than accountBalance'
is replaced with'frozenBalance must be less than or equal to accountBalance'
- WhenfrozenBalance < 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'
- WhenfrozenBalance > accountCapsule.getBalance()
in FreezeBalanceV2Actuator.java, description'frozenBalance must be less than accountBalance'
is replaced with'frozenBalance must be less than or equal to accountBalance'
- WhendelegateBalance < 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'
- WhenownerCapsule.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'
- WhenownerCapsule.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'
- WhenfrozenBalance < TRX_PRECISION
in FreezeBalanceProcessor.java, description'FrozenBalance must be less than accountBalance'
is replaced with'FrozenBalance must be less than or equal to accountBalance'
- WhenfrozenBalance < 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'
- WhenfrozenBalance > 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