@@ -119,12 +119,12 @@ h(Method, [<<"playground">>|Path], Req) ->
119119h (Method , [<<" api" >>|Path ], Req ) ->
120120 h (Method , Path , Req );
121121
122- h (<<" GET" >>, [<<" node" >>, <<" status" >>], _Req ) ->
122+ h (<<" GET" >>, [<<" node" >>, <<" status" >>], Req ) ->
123123 Chain = chainsettings :get_val (mychain ),
124124 #{hash := Hash ,
125125 header := Header1 }= Blk = blockchain :last_meta (),
126126 Temp = maps :get (temporary ,Blk ,false ),
127- BinPacker = packer (_Req ),
127+ BinPacker = packer (Req ),
128128 Header = maps :map (
129129 fun (roots , V ) ->
130130 [ if is_binary (RV ) ->
@@ -173,6 +173,41 @@ h(<<"GET">>, [<<"node">>, <<"status">>], _Req) ->
173173 []
174174 end ,
175175 {Ver , _BuildTime }= tpnode :ver (),
176+ BRLB = begin
177+ QS = cowboy_req :parse_qs (Req ),
178+ case proplists :get_value (<<" brlb" >>, QS ) of
179+ undefined -> undefined ;
180+ _ ->
181+ try
182+ #{hash := BVHas ,
183+ header := #{chain := BVCh ,
184+ height := BVHei ,
185+ parent := BVPar ,
186+ roots := BVRoots }
187+ }= BVB = gen_server :call (blockchain_reader ,last_block ),
188+ maps :merge (
189+ #{hash => BinPacker (BVHas ),
190+ header => #{
191+ chain => BVCh ,
192+ height => BVHei ,
193+ parent => BinPacker (BVPar ),
194+ roots => [ if is_binary (RV ) ->
195+ [N , BinPacker (RV )];
196+ true ->
197+ [N , RV ]
198+ end || {N ,RV } <- BVRoots ]
199+ }
200+ },
201+ maps :with ([temporary ],BVB )
202+ )
203+ catch Ec1 :Ee1 :S1 ->
204+ ? LOG_ERROR (" blockchain_reader last_block error: ~p :~p~n~p " ,
205+ [Ec1 , Ee1 , hd (S1 )]),
206+ #{ error => true }
207+ end
208+ end
209+ end ,
210+
176211 answer (
177212 #{ result => <<" ok" >>,
178213 status => #{
@@ -193,6 +228,7 @@ h(<<"GET">>, [<<"node">>, <<"status">>], _Req) ->
193228 gen_server :call (blockvote , status )
194229 catch _ :_ -> #{ error => true }
195230 end ,
231+ blockchain_reader_lastblock => BRLB ,
196232 xchain_inbound => try
197233 gen_server :call (xchain_dispatcher , peers )
198234 catch _ :_ -> #{ error => true }
@@ -226,8 +262,15 @@ h(<<"GET">>, [<<"node">>, <<"chainstate">>], _Req) ->
226262 });
227263
228264h (<<" POST" >>, [<<" node" >>, <<" runsync" >>], _Req ) ->
229- blockchain_sync ! runsync ,
230- answer (#{ result => <<" ok" >> });
265+ R = list_to_binary (
266+ [ io_lib :format (" ~p~n " ,
267+ [ gen_server :call (blockchain_sync , {runsync_h , any }) ]
268+ ) ]
269+ ),
270+ answer (#{
271+ result => <<" ok" >>,
272+ candidates => R
273+ });
231274
232275h (<<" POST" >>, [<<" node" >>, <<" new_peer" >>], Req ) ->
233276 {RemoteIP , _Port }= cowboy_req :peer (Req ),
@@ -936,6 +979,58 @@ h(<<"GET">>, [<<"settings">>|Path], Req) ->
936979 #{jsx => [ strict , {error_handler , EHF } ]}
937980 );
938981
982+
983+ h (<<" POST" >>, [<<" debug" >>, <<" runsync" >>|N ], _Req ) ->
984+ Q = case N of
985+ [NN ] ->
986+ {runsync_h , binary_to_integer (NN )};
987+ [NN ,TT ] ->
988+ {runsync_h , {binary_to_integer (NN ),binary_to_integer (TT )}};
989+ [] ->
990+ {runsync_h , any }
991+ end ,
992+ try
993+ R = case gen_server :call (blockchain_sync , Q ) of
994+ {ok , RR } when is_list (RR )->
995+ lists :foldl (
996+ fun ({{PubKey ,Service , _ }, Map },A ) ->
997+ Node = case chainsettings :is_net_node (PubKey ) of
998+ {ok , NNN } -> NNN ;
999+ _ -> PubKey
1000+ end ,
1001+ [ [ [Node , Service ], Map ] | A ];
1002+ ({Key ,Map },A ) ->
1003+ [[list_to_binary ( [ io_lib :format (" ~p " , [ [Key ] ]) ]),
1004+ list_to_binary ( [ io_lib :format (" ~p " , [ [Map ] ]) ]) ]|A ];
1005+ (Other ,A ) ->
1006+ [list_to_binary ( [ io_lib :format (" ( (~p ) )" , [ [Other ] ]) ])|A ]
1007+ end , [], RR );
1008+ {ok , RR } ->
1009+ list_to_binary ( [ io_lib :format (" d:~p " , [ RR ]) ]);
1010+ Other ->
1011+ list_to_binary ( [ io_lib :format (" o:~p " , [ Other ]) ])
1012+ end ,
1013+ answer (#{
1014+ result => <<" ok" >>,
1015+ res => R
1016+ })
1017+ catch Ec :Ee :S ->
1018+ err (
1019+ 10008 ,
1020+ iolist_to_binary (io_lib :format (" Error: ~p :~p at ~p " , [Ec ,Ee ,S ])),
1021+ #{},
1022+ #{http_code => 500 }
1023+ )
1024+ end ;
1025+
1026+ h (<<" POST" >>, [<<" debug" >>, <<" last_sync_res" >>], _Req ) ->
1027+ R0 = gen_server :call (blockchain_sync , last_res ),
1028+ R = list_to_binary ( [ io_lib :format (" ~p " , [ R0 ]) ]),
1029+ answer (#{
1030+ result => <<" ok" >>,
1031+ res => R
1032+ });
1033+
9391034h (<<" POST" >>, [<<" debug" >>,<<" bcupdater_reloadset" >>], Req ) ->
9401035 BinPacker = packer (Req ),
9411036 EHF = fun ([{Type , Str }|Tokens ],{parser , State , Handler , Stack }, Conf ) ->
0 commit comments