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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/archethic/p2p/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.

case TransactionChain.get_first_transaction(address, [:previous_public_key]) do
{:ok, %Transaction{previous_public_key: key}} ->
case TransactionChain.get_first_public_key(address) do
key ->
%FirstPublicKey{public_key: key}

{:error, :transaction_not_exists} ->
%NotFound{}
end
end

Expand Down