Credo and formatting appeasement

pull/870/head
Ryan Arthur 6 years ago
parent 05935d825b
commit e34e9f1d02
  1. 54
      apps/block_scout_web/lib/block_scout_web/controllers/block_controller.ex
  2. 1
      apps/block_scout_web/test/block_scout_web/controllers/block_controller_test.exs
  3. 3
      apps/block_scout_web/test/block_scout_web/features/pages/block_page.ex
  4. 3
      apps/explorer/lib/explorer/chain/block.ex

@ -6,15 +6,13 @@ defmodule BlockScoutWeb.BlockController do
alias Explorer.Chain
def index(conn, params) do
Keyword.merge(
[
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional
}
],
paging_options(params)
)
[
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional
}
]
|> Keyword.merge(paging_options(params))
|> handle_render(conn, params)
end
@ -23,31 +21,27 @@ defmodule BlockScoutWeb.BlockController do
end
def reorg(conn, params) do
Keyword.merge(
[
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional
},
block_type: "Reorg"
],
paging_options(params)
)
[
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional
},
block_type: "Reorg"
]
|> Keyword.merge(paging_options(params))
|> handle_render(conn, params)
end
def uncle(conn, params) do
Keyword.merge(
[
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional,
:nephews => :required
},
block_type: "Uncle"
],
paging_options(params)
)
[
necessity_by_association: %{
:transactions => :optional,
[miner: :names] => :optional,
:nephews => :required
},
block_type: "Uncle"
]
|> Keyword.merge(paging_options(params))
|> handle_render(conn, params)
end

@ -115,6 +115,7 @@ defmodule BlockScoutWeb.BlockControllerTest do
4
|> insert_list(:block, consensus: false)
|> Enum.map(& &1.hash)
conn = get(conn, reorg_path(conn, :reorg))
assert Enum.map(conn.assigns.blocks, & &1.hash) == Enum.reverse(reorg_hashes)

@ -42,6 +42,7 @@ defmodule BlockScoutWeb.BlockPage do
end
def visit_page(session, %Block{} = block) do
visit(session, block_path(build_conn(), :show, block))
path = block_path(build_conn(), :show, block)
visit(session, path)
end
end

@ -97,16 +97,17 @@ defmodule Explorer.Chain.Block do
|> unique_constraint(:hash, name: :blocks_pkey)
end
@doc """
Adds to the given block's query a `where` with conditions to filter by the type of block;
`Uncle`, `Reorg`, or `Block`.
"""
def block_type_filter(query, "Block"), do: where(query, [block], block.consensus == true)
def block_type_filter(query, "Reorg") do
query
|> join(:left, [block], uncles in assoc(block, :nephew_relations))
|> where([block, uncles], block.consensus == false and is_nil(uncles.uncle_hash))
end
def block_type_filter(query, "Uncle"), do: where(query, [block], block.consensus == false)
end

Loading…
Cancel
Save