Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mechanism): optimize address parsing of stake interfaces #5419

Conversation

CarlChaoCarl
Copy link
Contributor

@CarlChaoCarl CarlChaoCarl commented Aug 14, 2023

What does this PR do?
optimize address parsing of stake interfaces, close #5411

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

@CarlChaoCarl CarlChaoCarl changed the title feat(mechanism): optimize new transaction address parsing feat(mechanism): optimize address parsing of stake-related interfaces Aug 15, 2023
transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(unfreezeBalanceContract.getOwnerAddress().toByteArray()));
}
if (Objects.nonNull(unfreezeBalanceContract.getReceiverAddress())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frequency of these if statements is too high, you can encapsulate a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, Ok, I encapsulate the code

@CarlChaoCarl CarlChaoCarl changed the title feat(mechanism): optimize address parsing of stake-related interfaces feat(mechanism): optimize address parsing of stake interfaces Aug 15, 2023
transactionLogTrigger.setFromAddress(StringUtil
.encode58Check(freezeBalanceV2Contract.getOwnerAddress().toByteArray()));
}
transactionLogTrigger.setAssetAmount(freezeBalanceV2Contract.getFrozenBalance());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactionLogTrigger.setAssetName("trx"); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I get it.

transactionLogTrigger.setToAddress(StringUtil
.encode58Check(delegateResourceContract.getReceiverAddress().toByteArray()));
}
transactionLogTrigger.setAssetAmount(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactionLogTrigger.setAssetName("trx");?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I get it.

if (Objects.nonNull(withdrawExpireUnfreezeContract)) {
transactionLogTrigger.setFromAddress(StringUtil.encode58Check(
withdrawExpireUnfreezeContract.getOwnerAddress().toByteArray()));
transactionLogTrigger.setAssetAmount(transactionInfo.getWithdrawExpireAmount());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactionLogTrigger.setAssetName("trx");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

WithdrawExpireUnfreezeContract withdrawExpireUnfreezeContract = contractParameter
.unpack(WithdrawExpireUnfreezeContract.class);

if (Objects.nonNull(withdrawExpireUnfreezeContract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

UnfreezeBalanceContract unfreezeBalanceContract = contractParameter
.unpack(UnfreezeBalanceContract.class);

if (Objects.nonNull(unfreezeBalanceContract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

FreezeBalanceV2Contract freezeBalanceV2Contract = contractParameter
.unpack(FreezeBalanceV2Contract.class);

if (Objects.nonNull(freezeBalanceV2Contract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

UnfreezeBalanceV2Contract unfreezeBalanceV2Contract = contractParameter
.unpack(UnfreezeBalanceV2Contract.class);

if (Objects.nonNull(unfreezeBalanceV2Contract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

DelegateResourceContract delegateResourceContract = contractParameter
.unpack(DelegateResourceContract.class);

if (Objects.nonNull(delegateResourceContract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

UnDelegateResourceContract unDelegateResourceContract = contractParameter
.unpack(UnDelegateResourceContract.class);

if (Objects.nonNull(unDelegateResourceContract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

CancelAllUnfreezeV2Contract cancelAllUnfreezeV2Contract = contractParameter
.unpack(CancelAllUnfreezeV2Contract.class);

if (Objects.nonNull(cancelAllUnfreezeV2Contract)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract cannot be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

if (!ByteString.EMPTY.equals(unfreezeBalanceContract.getReceiverAddress())) {
transactionLogTrigger.setToAddress(StringUtil
.encode58Check(unfreezeBalanceContract.getReceiverAddress().toByteArray()));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be added?

 transactionLogTrigger.setAssetName("trx");
           transactionLogTrigger.setAssetAmount(transactionInfo.getUnfreezeAmount());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I get it

@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2023

Codecov Report

Merging #5419 (eaaa323) into develop (ad728fa) will increase coverage by 0.05%.
The diff coverage is 85.48%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

@@              Coverage Diff              @@
##             develop    #5419      +/-   ##
=============================================
+ Coverage      61.35%   61.41%   +0.05%     
- Complexity      9348     9351       +3     
=============================================
  Files            846      846              
  Lines          50211    50273      +62     
  Branches        5583     5584       +1     
=============================================
+ Hits           30805    30873      +68     
+ Misses         17002    16981      -21     
- Partials        2404     2419      +15     
Files Changed Coverage Δ
...mmon/logsfilter/trigger/TransactionLogTrigger.java 96.72% <0.00%> (-3.28%) ⬇️
...gsfilter/capsule/TransactionLogTriggerCapsule.java 41.70% <88.33%> (+41.70%) ⬆️

... and 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.7.3 milestone Aug 30, 2023
@halibobo1205 halibobo1205 merged commit d6ff733 into tronprotocol:develop Sep 4, 2023
7 checks passed
@halibobo1205 halibobo1205 added topic: Event subscribe transaction trigger, block trigger, contract event, contract log status:delivery test labels Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:delivery test topic: Event subscribe transaction trigger, block trigger, contract event, contract log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize address parsing of stake-related interfaces
6 participants