WIP
This commit is contained in:
+59
-48
@@ -91,20 +91,23 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
|||||||
|
|
||||||
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Signature Key")}]),
|
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Signature Key")}]),
|
||||||
KeyPicker = wxChoice:new(Frame, ?wxID_ANY, [{choices, Keys}]),
|
KeyPicker = wxChoice:new(Frame, ?wxID_ANY, [{choices, Keys}]),
|
||||||
|
ok = wxChoice:setSelection(KeyPicker, Selected),
|
||||||
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
|
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
|
||||||
|
|
||||||
{ArgSz, Args} = call_arg_sizer(Frame, J, FunSpec),
|
{ArgSz, Args, Dimensions} = call_arg_sizer(Frame, J, FunSpec),
|
||||||
{ParamSz, TTL_T, GasPriceT, GasT, AmountT} = call_param_sizer(Frame, J),
|
{ParamSz, Params} = call_param_sizer(Frame, J),
|
||||||
|
|
||||||
Action = #w{wx = ActionBn} = gd_lib:button(Frame, ActionLabel),
|
Action = #w{wx = ActionBn} = gd_lib:button(Frame, ActionLabel),
|
||||||
|
|
||||||
TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]),
|
TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]),
|
||||||
TX_Hash = #w{wx = HashTxt} = gd_lib:mono_text(TX_Sz, tx_hash),
|
TX_Data = #w{wx = HashT} = gd_lib:mono_text(TX_Sz, tx_hash),
|
||||||
|
TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz, tx_hash),
|
||||||
|
TX_Info = #w{wx = HashT} = gd_lib:mono_text(TX_Sz, tx_hash),
|
||||||
Line = wxStaticLine:new(TX_Sz, [{style, ?wxLI_HORIZONTAL}]),
|
Line = wxStaticLine:new(TX_Sz, [{style, ?wxLI_HORIZONTAL}]),
|
||||||
Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz, out),
|
Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz, out),
|
||||||
Copy = #w{wx = CopyBn} = gd_lib:button(Frame, J("Copy")),
|
Copy = #w{wx = CopyBn} = gd_lib:button(Frame, J("Copy")),
|
||||||
|
|
||||||
_ = wxStaticBoxSizer:add(TX_Sz, HashTxt, zxw:flags({wide, 5})),
|
_ = wxStaticBoxSizer:add(TX_Sz, HashT, zxw:flags({wide, 5})),
|
||||||
_ = wxStaticBoxSizer:add(TX_Sz, Line, zxw:flags({wide, 5})),
|
_ = wxStaticBoxSizer:add(TX_Sz, Line, zxw:flags({wide, 5})),
|
||||||
_ = wxStaticBoxSizer:add(TX_Sz, OutTxt, zxw:flags({wide, 5})),
|
_ = wxStaticBoxSizer:add(TX_Sz, OutTxt, zxw:flags({wide, 5})),
|
||||||
_ = wxStaticBoxSizer:add(TX_Sz, CopyBn, zxw:flags({wide, 5})),
|
_ = wxStaticBoxSizer:add(TX_Sz, CopyBn, zxw:flags({wide, 5})),
|
||||||
@@ -124,9 +127,10 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
|||||||
State =
|
State =
|
||||||
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||||
con_id = ConID, build = Build,
|
con_id = ConID, build = Build,
|
||||||
args = Args, kp = KeyPicker,
|
args = Args, kp = KeyPicker, params = Params,
|
||||||
ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT,
|
action = Action,
|
||||||
action = Action, copy = Copy},
|
tx_data = TX_Data, tx_hash = TX_Hash, tx_info = TX_Info,
|
||||||
|
out = Out, copy = Copy},
|
||||||
{Frame, State}.
|
{Frame, State}.
|
||||||
|
|
||||||
|
|
||||||
@@ -183,27 +187,32 @@ call_param_sizer(Frame, J) ->
|
|||||||
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
||||||
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
||||||
TTL_L = wxStaticText:new(Frame, ?wxID_ANY, "TTL"),
|
TTL_L = wxStaticText:new(Frame, ?wxID_ANY, "TTL"),
|
||||||
TTL_Tx = wxTextCtrl:new(Frame, ?wxID_ANY),
|
TTL_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||||
ok = wxTextCtrl:setValue(TTL_Tx, integer_to_list(DefTTL)),
|
ok = wxTextCtrl:setValue(TTL_T, integer_to_list(DefTTL)),
|
||||||
GasP_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas Price")),
|
GasP_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas Price")),
|
||||||
GasP_Tx = wxTextCtrl:new(Frame, ?wxID_ANY),
|
GasP_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||||
ok = wxTextCtrl:setValue(GasP_Tx, integer_to_list(DefGasP)),
|
ok = wxTextCtrl:setValue(GasP_T, integer_to_list(DefGasP)),
|
||||||
Gas_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas")),
|
Gas_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas")),
|
||||||
Gas_Tx = wxTextCtrl:new(Frame, ?wxID_ANY),
|
Gas_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||||
ok = wxTextCtrl:setValue(Gas_Tx, integer_to_list(DefGas)),
|
ok = wxTextCtrl:setValue(Gas_T, integer_to_list(DefGas)),
|
||||||
Amount_L = wxStaticText:new(Frame, ?wxID_ANY, J("TX Amount")),
|
Amount_L = wxStaticText:new(Frame, ?wxID_ANY, J("TX Amount")),
|
||||||
Amount_Tx = wxTextCtrl:new(Frame, ?wxID_ANY),
|
Amount_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||||
ok = wxTextCtrl:setValue(Amount_Tx, integer_to_list(DefAmount)),
|
ok = wxTextCtrl:setValue(Amount_T, integer_to_list(DefAmount)),
|
||||||
_ = wxFlexGridSizer:add(GridSz, TTL_L, zxw:flags({base, 5})),
|
_ = wxFlexGridSizer:add(GridSz, TTL_L, zxw:flags({base, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, TTL_Tx, zxw:flags({wide, 5})),
|
_ = wxFlexGridSizer:add(GridSz, TTL_T, zxw:flags({wide, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})),
|
_ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, GasP_Tx, zxw:flags({wide, 5})),
|
_ = wxFlexGridSizer:add(GridSz, GasP_T, zxw:flags({wide, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, Gas_L, zxw:flags({base, 5})),
|
_ = wxFlexGridSizer:add(GridSz, Gas_L, zxw:flags({base, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, Gas_Tx, zxw:flags({wide, 5})),
|
_ = wxFlexGridSizer:add(GridSz, Gas_T, zxw:flags({wide, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, Amount_L, zxw:flags({base, 5})),
|
_ = wxFlexGridSizer:add(GridSz, Amount_L, zxw:flags({base, 5})),
|
||||||
_ = wxFlexGridSizer:add(GridSz, Amount_Tx, zxw:flags({wide, 5})),
|
_ = wxFlexGridSizer:add(GridSz, Amount_T, zxw:flags({wide, 5})),
|
||||||
_ = wxSizer:add(ParamSz, GridSz, zxw:flags(wide)),
|
_ = wxSizer:add(ParamSz, GridSz, zxw:flags(wide)),
|
||||||
{ParamSz, TTL_Tx, GasP_Tx, Gas_Tx, Amount_Tx}.
|
Params =
|
||||||
|
[{ "TTL", fun gte_0/1, TTL_T},
|
||||||
|
{J("Gas Price"), fun gt_0/1, GasP_T},
|
||||||
|
{J("Gas") , fun gt_0/1, Gas_T},
|
||||||
|
{J("TX Amount"), fun gt_0/1, Amount_T}],
|
||||||
|
{ParamSz, Params}.
|
||||||
|
|
||||||
|
|
||||||
handle_call(Unexpected, From, State) ->
|
handle_call(Unexpected, From, State) ->
|
||||||
@@ -251,34 +260,41 @@ handle_troubling(State = #s{frame = Frame}, Info) ->
|
|||||||
|
|
||||||
engage(State) ->
|
engage(State) ->
|
||||||
case gd_con:chain_id() of
|
case gd_con:chain_id() of
|
||||||
{ok, ChainID} -> engage(State, ChainID);
|
{ok, ChainID} -> engage2(State, ChainID);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
engage(State = #s{fundef = {"init", init}, build = Build}, ChainID) ->
|
engage2(State, ChainID) ->
|
||||||
{CallerID, Nonce, TTL, GasPrice, Gas, Amount} = params(State),
|
case params(State) of
|
||||||
Args = args(State),
|
{ok, Params} -> engage3(State, ChainID, Params);
|
||||||
case hz:contract_create_built(CallerID,
|
Error -> handle_troubling(State, Error)
|
||||||
Nonce, Amount, TTL, Gas, GasPrice,
|
end.
|
||||||
Build, InitArgs) of
|
|
||||||
|
engage3(State, ChainID, Params) ->
|
||||||
|
case args(State) of
|
||||||
|
{ok, Args} -> engage4(State, ChainID, Params, {sophia, Args});
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
engage4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
||||||
|
{CallerID, Nonce, TTL, GP, Gas, Amount} = Params,
|
||||||
|
case hz:contract_create_built(CallerID, Nonce, Gas, GP, Amount, TTL, Build, Args) of
|
||||||
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end;
|
end;
|
||||||
engage(State = #s{con_id = ConID, build = Build, fundef = {Name, Type}}, ChainID) ->
|
engage4(State = #s{con_id = ConID, build = Build, fundef = {Name, Type}}, ChainID, Params, Args) ->
|
||||||
AACI = maps:get(aaci, AACI),
|
{CallerID, Nonce, TTL, GP, Gas, Amount} = Params,
|
||||||
{PK, Nonce, TTL, GasP, Gas, Amount} = params(State),
|
AACI = maps:get(aaci, Build),
|
||||||
Args = args(State),
|
case hz:contract_call(CallerID, Nonce, Gas, GP, Amount, TTL, AACI, ConID, Name, Args) of
|
||||||
case hz:contract_call(PK, Nonce, Gas, GasP, Amount, TTL, AACI, ConID, Name, Args) of
|
|
||||||
{ok, UnsignedTX} ->
|
{ok, UnsignedTX} ->
|
||||||
case Type of
|
case Type of
|
||||||
call -> do_call(State, ChainID, PK, UnsignedTX);
|
call -> do_call(State, ChainID, CallerID, UnsignedTX);
|
||||||
dryr -> do_dry_run(State, ConID, UnsignedTX)
|
dryr -> do_dry_run(State, ConID, UnsignedTX)
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
handle_troubling(State, Error)
|
handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
params(State = #s{kp = #w{wx = KeyPicker}}) ->
|
params(State = #s{kp = #w{wx = KeyPicker}}) ->
|
||||||
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
|
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
|
||||||
PK = unicode:characters_to_binary(ID),
|
PK = unicode:characters_to_binary(ID),
|
||||||
@@ -287,20 +303,10 @@ params(State = #s{kp = #w{wx = KeyPicker}}) ->
|
|||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
params2(#s{ttl = #w{wx = TTL_T},
|
params2(#s{params = Params}, PK, Nonce) ->
|
||||||
gasprice = #w{wx = GasPriceT},
|
case lists:foldl(fun extract/2, {ok, []}, Params) of
|
||||||
gas = #w{wx = GasT},
|
{ok, [TTL, GP, Gas, Amount]} -> {ok, {PK, Nonce, TTL, GP, Gas, Amount}};
|
||||||
amount = #w{wx = AmountT}},
|
Error -> Error
|
||||||
PK,
|
|
||||||
Nonce) ->
|
|
||||||
ToExtract =
|
|
||||||
[{ttl, fun gte_0/1, TTL_T},
|
|
||||||
{gasprice, fun gt_0/1, GasPriceT},
|
|
||||||
{gas, fun gt_0/1, GasT},
|
|
||||||
{amount, fun gt_0/1, AmountT}],
|
|
||||||
case lists:foldl(fun extract/2, {ok, []}, ToCheck) of
|
|
||||||
{ok, [TTL, GasPrice, Gas, Amount]} ->
|
|
||||||
{error, Out} ->
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
extract({Name, Check, Widget}, {Status, Out}) ->
|
extract({Name, Check, Widget}, {Status, Out}) ->
|
||||||
@@ -310,7 +316,12 @@ extract({Name, Check, Widget}, {Status, Out}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
% TODO: Put some basic checking in here, like for blank strings, at least.
|
||||||
|
% It should be possible to perform type/parse checks over this since we have
|
||||||
|
% access to the AACI. But not today.
|
||||||
args(#s{args = ArgFields}) ->
|
args(#s{args = ArgFields}) ->
|
||||||
|
Values = [wxTextCtrl:getValue(W) || #w{wx = W} <- ArgFields],
|
||||||
|
{ok, Values}.
|
||||||
|
|
||||||
|
|
||||||
deploy(State, ChainID, CallerID, CreateTX) ->
|
deploy(State, ChainID, CallerID, CreateTX) ->
|
||||||
|
|||||||
Reference in New Issue
Block a user