@@ -4,18 +4,6 @@ defmodule Explorer.BeaconClient do
44 # See https://eips.ethereum.org/EIPS/eip-4844#parameters
55 @ versioned_hash_version_kzg 0x01
66
7- def get_block_slot! ( block_hash ) do
8- { :ok , beacon_block } = get_beacon_block_header_by_hash ( block_hash )
9-
10- String . to_integer (
11- beacon_block
12- |> Map . get ( "data" )
13- |> Map . get ( "header" )
14- |> Map . get ( "message" )
15- |> Map . get ( "slot" )
16- )
17- end
18-
197 def fetch_blob_by_versioned_hash! ( slot , blob_versioned_hash ) do
208 { :ok , blobs } = get_block_blobs ( slot )
219 data = Map . get ( blobs , "data" )
@@ -35,14 +23,36 @@ defmodule Explorer.BeaconClient do
3523 "0x" <> Base . encode16 ( raw , case: :lower )
3624 end
3725
38- def get_block_blobs ( slot ) do
39- beacon_get ( "/eth/v1/beacon/blob_sidecars/#{ slot } " )
26+ def get_block_slot ( beacon_block ) do
27+ String . to_integer (
28+ beacon_block
29+ |> Map . get ( "data" )
30+ |> Map . get ( "header" )
31+ |> Map . get ( "message" )
32+ |> Map . get ( "slot" )
33+ )
4034 end
4135
42- def get_beacon_block_header_by_hash ( block_hash ) do
36+ def get_block_header_by_hash ( block_hash ) do
4337 beacon_get ( "/eth/v1/beacon/headers/#{ block_hash } " )
4438 end
4539
40+ def get_block_header_by_parent_hash ( parent_block_hash ) do
41+ case beacon_get ( "/eth/v1/beacon/headers?parent_root=#{ parent_block_hash } " ) do
42+ { :ok , header } ->
43+ data = header [ "data" ] |> Enum . at ( 0 )
44+
45+ { :ok , % { header | "data" => data } }
46+
47+ other ->
48+ other
49+ end
50+ end
51+
52+ def get_block_blobs ( slot ) do
53+ beacon_get ( "/eth/v1/beacon/blob_sidecars/#{ slot } " )
54+ end
55+
4656 def beacon_get ( method ) do
4757 headers = [ { "Content-Type" , "application/json" } ]
4858 request = Finch . build ( :get , "#{ @ beacon_url } #{ method } " , headers )
0 commit comments