diff --git a/src/gd_v_call.erl b/src/gd_v_call.erl index fe1548d..53b273f 100644 --- a/src/gd_v_call.erl +++ b/src/gd_v_call.erl @@ -27,6 +27,7 @@ fundef = none :: none | fun_def(), build = none :: none | map(), args = [] :: [#w{}], + kp = #w{} :: #w{}, ttl = #w{} :: #w{}, gasprice = #w{} :: #w{}, gas = #w{} :: #w{}, @@ -119,11 +120,11 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) -> ok = wxFrame:connect(Frame, command_button_clicked), true = wxFrame:show(Frame), State = - #s{wx = Wx, frame = Frame, j = J, prefs = Prefs, - con_id = ConID, build = Build, - args = Args, keypicker = KeyPicker, - ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT, - action = Action, copy = Copy}, + #s{wx = Wx, frame = Frame, j = J, prefs = Prefs, + con_id = ConID, build = Build, + args = Args, kp = KeyPicker, + ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT, + action = Action, copy = Copy}, {Frame, State}. @@ -276,12 +277,31 @@ engage(State = #s{con_id = ConID, build = Build, fundef = {Name, Type}}, ChainID end. -params(#s{ttl = #w{wx = TTL}, - gasprice = #w{wx = GasPrice}, - gas = #w{wx = Gas}, - amount = #w{wx = Amount}, - }) -> +params(State = #s{kp = #w{wx = KeyPicker}}) -> + ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)), + PK = unicode:characters_to_binary(ID), + case hz:next_nonce(PK) of + {ok, Nonce} -> params2(State, PK, Nonce); + Error -> handle_troubling(State, Error) + end. +params2(State, PK, Nonce) -> + Params = extract(State), +params2(#s{ttl = #w{wx = TTL_T}, + gasprice = #w{wx = GasPriceT}, + gas = #w{wx = GasT}, + amount = #w{wx = AmountT}}, + PK, + Nonce) -> + TTL = wxTextCtrl:getValue(TTL_T), + GasPrice = wxTextCtrl:getValue(GasPriceT), + +extract(State) -> extract(State, {none, none, none, none}). + +extract(State = #s{ttl = W}, {none, none, none, none}) -> +extract(State = #s{gasprice = W}, {TTL, none, none, none}) -> +extract(State = #s{gas = W}, {TTL, GP, none, none}) -> +extract(State = #s{amount = W}, {TTL, GP, Gas, none}) -> args(#s{args = ArgFields}) -> @@ -312,10 +332,11 @@ do_call2(State, SignedTX) -> Error -> handle_troubling(State, Error) end. + do_dry_run(State, ConID, TX) -> case hz:dry_run(TX) of - {ok, Result} -> gd_v_devman:dryrun_result(ConID, Result); - Other -> gd_v_devmam:trouble({error, ConID, Other}) + {ok, Result} -> update_info(State#s{tx_info = Result}); + Other -> handle_troubling(State, {error, ConID, Other}) end. @@ -332,7 +353,7 @@ check_tx(State = #s{tx_data = #{"tx_hash" := TXHash} = TXData, tx_info = none}) Error -> handle_troubling(State, Error) end; -check_tx(State = #s{tx_info = TXInfo}) -> +check_tx(State) -> ok = tell("Nothing to check"), State.