11-module (tpnode_reporter ).
2- -export ([prepare /1 ,prepare /4 , blockinfo /1 , band_info /2 , encode_data /2 , ensure_account /0 , register /1 ,
2+ -export ([prepare /1 ,prepare /2 , prepare / 4 , blockinfo /1 , band_info /2 , encode_data /2 , ensure_account /0 , register /1 ,
33 post_tx_and_wait /2 , get_ver /0 , get_iver /1 , attributes /0 , attributes_changed /2 ,
4- set_attributes /2 , ask_nextblock /1 , id2attr /1 , run /0
4+ set_attributes /2 , ask_nextblock /1 , id2attr /1 , run /0 , run / 1
55 ]).
66
77-include (" include/tplog.hrl" ).
@@ -40,6 +40,9 @@ get_iver(Ver) ->
4040 end .
4141
4242run () ->
43+ run (#{}).
44+
45+ run (Opts ) ->
4346 {ok ,_Addr }= tpnode_reporter :ensure_account (),
4447 CS = case application :get_env (tpnode ,chainstate ,undefined ) of
4548 undefined ->
@@ -50,10 +53,8 @@ run() ->
5053 X ->
5154 naddress :decode (X )
5255 end ,
53- if CS == false ->
54- no_chainstate_specified ;
55- true ->
56- case tpnode_reporter :prepare (CS ) of
56+ if is_binary (CS ) ->
57+ case tpnode_reporter :prepare (CS , Opts ) of
5758 nokey ->
5859 logger :error (" Cannot report, key is not registered" );
5960 Tx when is_map (Tx ) ->
@@ -62,7 +63,9 @@ run() ->
6263 {ok , {TxID , Tx }};
6364 ignore ->
6465 ignore
65- end
66+ end ;
67+ true ->
68+ no_chainstate_specified
6669 end .
6770
6871
@@ -229,9 +232,11 @@ encode_data(Data, Attrs) ->
229232 <<FunctionSig /binary ,EData /binary >>.
230233
231234prepare (ToContract ) ->
232- prepare (ToContract , attributes_changed (ToContract ,attributes ())).
235+ prepare (ToContract , #{}).
236+ prepare (ToContract , Opts ) ->
237+ prepare (ToContract , attributes_changed (ToContract ,attributes ()), Opts ).
233238
234- prepare (ToContract , Attributes ) ->
239+ prepare (ToContract , Attributes , Opts ) ->
235240 KeyId = case tpnode_evmrun :evm_run (ToContract ,
236241 <<" node_id(bytes nodekey) returns (uint256)" >>,
237242 [nodekey :get_pub ()],
@@ -245,8 +250,9 @@ prepare(ToContract, Attributes) ->
245250 {Time ,Blk }= tpnode_reporter :ask_nextblock (ToContract ),
246251 Wait = Time - os :system_time (second ),
247252 io :format (" LBH ~p wait ~p blk ~p~n " ,[LBH , Wait , Blk ]),
253+ Nowait = maps :is_key (nowait ,Opts ),
248254
249- if (Wait =< 2 orelse LBH == Blk - 1 ) ->
255+ if (Nowait orelse Wait =< 2 orelse LBH == Blk - 1 ) ->
250256 SCH = case tpnode_evmrun :evm_run (
251257 ToContract ,
252258 <<" last_height(uint256) returns (uint256)" >>, [KeyId ],
0 commit comments