-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add getGenesisAddress query to graphql #808
Add getGenesisAddress query to graphql #808
Conversation
@@ -18,6 +18,30 @@ defmodule ArchethicWeb.GraphQLSchema.Resolver do | |||
|
|||
@limit_page 10 | |||
|
|||
def get_genesis_address(address) do | |||
t1 = Task.async(fn -> TransactionChain.fetch_genesis_address_remotely(address) end) |
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.
Hello, ArchethicWeb should be agnostic to the underlying architecture of the archethic project ( it should only interact with the public api in the Archethic module).
I would suggest to change this call to Archethic.fetch_genesis_address_remotely
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 don't need a Task here, I would call directly the function in this case.
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.
Hello, ArchethicWeb should be agnostic to the underlying architecture of the archethic project ( it should only interact with the public API in the Archethic module).
Ok thanks, I'll fix that! Could you explain to me why it should be agnostic to the underlying architecture of the archethic project, I don't really understand?
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.
ArchethicWeb represents the frontend and Archethic represents the backend logic, in here they are in the same repository but this can change someday in the future, also we try to follow the hexagonal architecture (some call it clean architecture).
Finally if the web only depends on the public api, it means that if we refactor the whole backend tomorrow we will not need to change the web part and separate people / teams can work independently on different parts of the project.
Feel free to ping me if it isn't clear.
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.
Very clear, thanks for the explanation!
I tried using the call Archethic.fetch_genesis_address_remotely
as you suggested however it seems to always return the same address as entered.
here is the code:
def get_genesis_address(address) do
case Archethic.fetch_genesis_address_remotely(address) do
{:ok, genesis_address} ->
{:ok, %{genesis: genesis_address}}
_ ->
{:ok, %{genesis: address}}
end
end
Correcting the code by using TransactionChain.fetch_genesis_address_remotely(address) fixes the issue.
Do you have any idea why or what I might be doing wrong?
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 can look at the definition here: https://github.com/archethic-foundation/archethic-node/blob/develop/lib/archethic.ex#L246
lib/archethic_web/graphql_schema.ex
Outdated
@desc """ | ||
Query the network to find the genesis address of a transaction | ||
""" | ||
field :get_genesis_address, :genesis_address do | ||
arg(:address, non_null(:address)) | ||
|
||
resolve(fn %{address: address}, _ -> | ||
Resolver.get_genesis_address(address) | ||
end) | ||
end |
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.
this part need to be tested, you can have a look at test/archethic_web/graphql_schema_test.exs
Also, I think you could rename it as |
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.
This is a fix to Archethic.fetch_genesis_address_remotly which does not return a correct map when genesis_address
is matched.
see 871f952
lib/archethic_web/graphql_schema.ex
Outdated
@desc """ | ||
Query the network to find the genesis address of a transaction | ||
""" | ||
field :genesis_address, :genesis_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.
Why create another type for the genesis address ?
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.
probably not needed indeed, will update 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.
Why create another type for the genesis address ?
Actually, I think it is needed. This query only returns the genesis address so I have to create a new type to only return the map genesis: address
. Or am I getting this wrong ?
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 to @Neylix I was able to understand what was meant to do. The genesisAddress type was removed.
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.
neat!
Description
This Pr aims to add a
getGenesisAddress
query to graphql to make it easier to find the genesis address of a transaction.Type of change
How Has This Been Tested?
Start a node, open the explorer, find a transaction and query the graphql endpoint to retrieve the genesis address.
Checklist: