From a660b662fd4056d1f1396dae0cb1416ba2819259 Mon Sep 17 00:00:00 2001 From: Sebastian Abondano Date: Wed, 31 Oct 2018 16:12:36 -0400 Subject: [PATCH] Adds hash to GraphQL block object Why: * For GraphQL API consumers to be able to fetch the hash for a given block. Sample usage: ``` query ($number: Int!) { block(number: $number) { hash } } ``` * Issue link: n/a This change addresses the need by: * Editing the block object in `BlockScoutWeb.Schema.Types` to include a hash field of type `:full_hash`. --- apps/block_scout_web/lib/block_scout_web/schema/types.ex | 1 + .../test/block_scout_web/schema/query/block_test.exs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/apps/block_scout_web/lib/block_scout_web/schema/types.ex b/apps/block_scout_web/lib/block_scout_web/schema/types.ex index 66da7a55d4..14d2cb3c43 100644 --- a/apps/block_scout_web/lib/block_scout_web/schema/types.ex +++ b/apps/block_scout_web/lib/block_scout_web/schema/types.ex @@ -12,6 +12,7 @@ defmodule BlockScoutWeb.Schema.Types do structure that they form is called a "blockchain". """ object :block do + field(:hash, :full_hash) field(:consensus, :boolean) field(:difficulty, :decimal) field(:gas_limit, :decimal) diff --git a/apps/block_scout_web/test/block_scout_web/schema/query/block_test.exs b/apps/block_scout_web/test/block_scout_web/schema/query/block_test.exs index a635614f27..432c5ebf2a 100644 --- a/apps/block_scout_web/test/block_scout_web/schema/query/block_test.exs +++ b/apps/block_scout_web/test/block_scout_web/schema/query/block_test.exs @@ -8,6 +8,7 @@ defmodule BlockScoutWeb.Schema.Query.BlockTest do query = """ query ($number: Int!) { block(number: $number) { + hash consensus difficulty gas_limit @@ -31,6 +32,7 @@ defmodule BlockScoutWeb.Schema.Query.BlockTest do assert json_response(conn, 200) == %{ "data" => %{ "block" => %{ + "hash" => to_string(block.hash), "consensus" => block.consensus, "difficulty" => to_string(block.difficulty), "gas_limit" => to_string(block.gas_limit),