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
feat: query channel reserve at a hash #1106
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,22 @@ defmodule AeMdwWeb.ChannelController do | |
end | ||
|
||
@spec channel(Conn.t(), map()) :: Conn.t() | ||
def channel(%Conn{assigns: %{state: state}} = conn, %{"id" => id}) do | ||
def channel(%Conn{assigns: %{state: state}} = conn, %{"id" => id} = params) do | ||
block_hash = params["block_hash"] | ||
|
||
with {:ok, channel_pk} <- Validate.id(id, [:channel]), | ||
{:ok, channel} <- Channels.fetch_channel(state, channel_pk) do | ||
true <- valid_optional_block_hash?(block_hash), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the first decoding that we do, we can use its value by returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{:ok, channel} <- Channels.fetch_channel(state, channel_pk, block_hash) do | ||
json(conn, channel) | ||
end | ||
end | ||
|
||
defp valid_optional_block_hash?(nil), do: true | ||
|
||
defp valid_optional_block_hash?(block_hash) do | ||
case Validate.id(block_hash) do | ||
{:ok, _hash} -> true | ||
{:error, _reason} -> false | ||
end | ||
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.
Perhaps we can send the decoded block_hash binary to avoid decoding it twice
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.
It was avoiding an additional parameter since the type is also needed and it's a few microseconds operation but did the optimization though.