-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
…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
This Fixes Issue #276 |
lib/archethic/p2p/message.ex
Outdated
@@ -1227,12 +1227,9 @@ defmodule ArchEthic.P2P.Message do | |||
end | |||
|
|||
def process(%GetFirstPublicKey{address: address}) do |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can rename the field in the struct get_first_public_key.ex |
Thanks sam, changed that too and in relevant places. |
lib/archethic/p2p/message.ex
Outdated
@@ -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) |
There was a problem hiding this comment.
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
lib/archethic/p2p/message.ex
Outdated
%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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
There was a problem hiding this comment.
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`
Made the above mentioned changes. |
* 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`
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.
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
Checklist: