@@ -25,12 +25,15 @@ defmodule BeaconApi.V1.BeaconController do
2525 def open_api_operation ( :get_finality_checkpoints ) ,
2626 do: ApiSpec . spec ( ) . paths [ "/eth/v1/beacon/states/{state_id}/finality_checkpoints" ] . get
2727
28+ def open_api_operation ( :get_headers_by_block ) ,
29+ do: ApiSpec . spec ( ) . paths [ "/eth/v1/beacon/headers/{block_id}" ] . get
30+
2831 @ spec get_genesis ( Plug.Conn . t ( ) , any ) :: Plug.Conn . t ( )
2932 def get_genesis ( conn , _params ) do
3033 conn
3134 |> json ( % {
3235 "data" => % {
33- "genesis_time" => StoreDb . fetch_genesis_time! ( ) ,
36+ "genesis_time" => StoreDb . fetch_genesis_time! ( ) |> Integer . to_string ( ) ,
3437 "genesis_validators_root" =>
3538 ChainSpec . get_genesis_validators_root ( ) |> Utils . hex_encode ( ) ,
3639 "genesis_fork_version" => ChainSpec . get ( "GENESIS_FORK_VERSION" ) |> Utils . hex_encode ( )
@@ -168,18 +171,52 @@ defmodule BeaconApi.V1.BeaconController do
168171 finalized: finalized ,
169172 data: % {
170173 previous_justified: % {
171- epoch: previous_justified_checkpoint . epoch ,
174+ epoch: previous_justified_checkpoint . epoch |> Integer . to_string ( ) ,
172175 root: Utils . hex_encode ( previous_justified_checkpoint . root )
173176 } ,
174177 current_justified: % {
175- epoch: current_justified_checkpoint . epoch ,
178+ epoch: current_justified_checkpoint . epoch |> Integer . to_string ( ) ,
176179 root: Utils . hex_encode ( current_justified_checkpoint . root )
177180 } ,
178181 finalized: % {
179- epoch: finalized_checkpoint . epoch ,
182+ epoch: finalized_checkpoint . epoch |> Integer . to_string ( ) ,
180183 root: Utils . hex_encode ( finalized_checkpoint . root )
181184 }
182185 }
183186 } )
184187 end
188+
189+ @ spec get_headers_by_block ( Plug.Conn . t ( ) , any ) :: Plug.Conn . t ( )
190+ def get_headers_by_block ( conn , % { block_id: "head" } ) do
191+ { :ok , store } = StoreDb . fetch_store ( )
192+ head_root = store . head_root
193+ % { signed_block: % { message: message , signature: signature } } = Blocks . get_block_info ( head_root )
194+
195+ conn
196+ # TODO: This is a placeholder, a minimum implementation to make assertoor run
197+ |> json ( % {
198+ execution_optimistic: false ,
199+
200+ # This is obviously false for the head, but should be derived
201+ finalized: false ,
202+ data: % {
203+ root: head_root |> Utils . hex_encode ( ) ,
204+
205+ # This needs to be derived
206+ canonical: true ,
207+ header: % {
208+ message: % {
209+ slot: message . slot |> Integer . to_string ( ) ,
210+ proposer_index: message . proposer_index |> Integer . to_string ( ) ,
211+ parent_root: message . parent_root |> Utils . hex_encode ( ) ,
212+ state_root: message . state_root |> Utils . hex_encode ( ) ,
213+ body_root: SszEx . hash_tree_root! ( message . body ) |> Utils . hex_encode ( )
214+ } ,
215+ signature: signature |> Utils . hex_encode ( )
216+ }
217+ }
218+ } )
219+ end
220+
221+ def get_headers_by_block ( conn , _params ) , do: conn |> ErrorController . not_found ( nil )
185222end
0 commit comments