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

Made use of get_first_public_key to always return a public key even i… #280

Merged
4 commits merged into from
Apr 21, 2022

Conversation

prix-uniris
Copy link
Contributor

Made use of TransactionChain.get_first_public_key/1 to always return a public key even in case of nonexistent transactions and lower I/O operations which are not required if only want to get First_Public_Key for any given address.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

…n case of non existent transactions and lower I/O operations which are not required if only want to get First_Public_Key for any given address
@prix-uniris
Copy link
Contributor Author

This Fixes Issue #276

@@ -1227,12 +1227,9 @@ defmodule ArchEthic.P2P.Message do
end

def process(%GetFirstPublicKey{address: address}) do
Copy link

Choose a reason for hiding this comment

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

We should also rename address to public_key, don't you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure sam, that makes more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but we are supplying address to get a public key for a given address right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so address also is a better argument name, also %GetFirstPublicKey{} accepts a address: , so variable name of address make more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, please keep it as public key, and in comments put address explaining it .

Copy link

@ghost ghost Apr 19, 2022

Choose a reason for hiding this comment

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

The name is misleading the purpose of the function.
So in GetFirstPublicKey, the public key should have more meaning.
Moreover, the implementation underneath is not using the address at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay thanks, I think it's more clear now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the changes.

Copy link
Contributor

@apoorv-2204 apoorv-2204 left a comment

Choose a reason for hiding this comment

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

@ghost
Copy link

ghost commented Apr 20, 2022

I think you can rename the field in the struct get_first_public_key.ex

@prix-uniris
Copy link
Contributor Author

Thanks sam, changed that too and in relevant places.

@@ -706,10 +706,10 @@ defmodule ArchEthic.P2P.Message do
end

def decode(<<20::8, rest::bitstring>>) do
{address, rest} = Utils.deserialize_address(rest)
{public_key, rest} = Utils.deserialize_address(rest)
Copy link

Choose a reason for hiding this comment

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

You should use Utils.deserialize_public_key here

%NotFound{}
# Returns the first public_key for a given public_key and if the public_key is used for the first time, return the same public_key.
def process(%GetFirstPublicKey{public_key: public_key}) do
case TransactionChain.get_first_public_key(public_key) do
Copy link

Choose a reason for hiding this comment

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

I think the case statement is not required anymore, as you are expecting a single result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so should we just directly return it as return value is always expected

Copy link

Choose a reason for hiding this comment

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

I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes more sense to directly return

…xpected from the function and changed decode function from `deserialize_address` to `deserialize_public_key`
@prix-uniris
Copy link
Contributor Author

Made the above mentioned changes.

@ghost ghost added bug Something isn't working P2P Involve P2P networking serialization Involve message serialization labels Apr 21, 2022
@ghost ghost merged commit 2879c2f into archethic-foundation:develop Apr 21, 2022
@ghost ghost mentioned this pull request Apr 27, 2022
ghost pushed a commit that referenced this pull request May 6, 2022
* Made use of get_first_public_key to always return a public key even in case of non existent transactions and lower I/O operations which are not required if only want to get First_Public_Key for any given address
* Renamed `address` to `public_key` as it is more meaningful
* Changed Struct atom of GetFirstPublicKey to `public_key` from `address`
* Removed case statement from %GetFirstPublicKey as a value is always expected from the function and changed decode function from `deserialize_address` to `deserialize_public_key`
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2P Involve P2P networking serialization Involve message serialization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants