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

node list GraphQL Api : add fields + Add GraphQL Api to fetch transactions list on type #51

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions lib/archethic_web/graphql_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ defmodule ArchEthicWeb.GraphQLSchema do
{:ok, Resolver.nodes()}
end)
end

@desc """
Query the network to list the transaction on the type
"""
field :network_transactions, list_of(:transaction) do
arg(:type, :string)
arg(:page, :integer)

resolve(fn args, _ ->
type = Map.get(args, :type)
page = Map.get(args, :page, 1)
{:ok, Resolver.network_transactions(String.to_atom(type), page)}
Copy link

Choose a reason for hiding this comment

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

You should avoid to use String.to_atom as it may create a overflow of the atom list in the Erlang VM. It's a security issue, and a way to bring down nodes for attackers.

But you can either create a function to parse stringified type to atomized type, or use String.to_existing_atom

Copy link

Choose a reason for hiding this comment

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

You should avoid to use String.to_atom as it may create a overflow of the atom table in the Erlang VM. It's a security issue, and a way to bring down nodes for attackers.

But you can create a function to parse stringified type to atomized type. This approach will enable a validation for the existing type and will sanitize the input.

Those checks can be done in the resolver itself.

end)
end
end

subscription do
Expand Down
2 changes: 2 additions & 0 deletions lib/archethic_web/graphql_schema/p2p_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ defmodule ArchEthicWeb.GraphQLSchema.P2PType do
field(:geo_patch, :string)
field(:network_patch, :string)
field(:average_availability, :float)
field(:enrollment_date, :timestamp)
field(:authorization_date, :timestamp)
end
end
5 changes: 5 additions & 0 deletions lib/archethic_web/graphql_schema/resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ defmodule ArchEthicWeb.GraphQLSchema.Resolver do
}
)
end

def network_transactions(type, page) do
TransactionChain.list_transactions_by_type(type, [])
|> paginate_transactions(page)
end
end