diff --git a/include/gmc.hrl b/include/gmc.hrl index d68e777..261f9cb 100644 --- a/include/gmc.hrl +++ b/include/gmc.hrl @@ -77,13 +77,14 @@ -record(wallet, - {version = 1 :: integer(), + {version = 2 :: integer(), name = "" :: string(), poas = [] :: [#poa{}], keys = [] :: [#key{}], chain_id = <<"groot.devnet">> :: binary(), endpoint = #node{} :: #node{}, - nets = [#net{}] :: [#net{}]}). + nets = [#net{}] :: [#net{}], + txs = #{} :: clutch:key_txs()}). diff --git a/src/clutch.erl b/src/clutch.erl index 777272e..01bf0a8 100644 --- a/src/clutch.erl +++ b/src/clutch.erl @@ -12,17 +12,19 @@ -export([ts/0]). -export([start/2, stop/1]). --export_type([id/0, key/0, poa/0, tx/0, ts/0]). +-export_type([id/0, key/0, poa/0, tx/0, ts/0, key_txs/0]). -include("$zx_include/zx_logger.hrl"). -include("gmc.hrl"). --type id() :: binary(). --type key() :: #key{}. --type poa() :: #poa{}. --type tx() :: #tx{}. --type ts() :: integer(). +-type id() :: binary(). +-type key() :: #key{}. +-type poa() :: #poa{}. +-type tx() :: #tx{}. +-type ts() :: integer(). +-type chain_txs() :: #{ChainID :: binary() := [tx()]}. +-type key_txs() :: #{id() := {{LastCheck :: ts(), mdw | node}, chain_txs()}}. ts() -> diff --git a/src/gmc_con.erl b/src/gmc_con.erl index 6dd215d..275eabf 100644 --- a/src/gmc_con.erl +++ b/src/gmc_con.erl @@ -41,12 +41,11 @@ {version = 1 :: integer(), window = none :: none | wx:wx_object(), tasks = [] :: [#ui{}], - picked = 0 :: non_neg_integer(), + selected = 0 :: non_neg_integer(), wallet = none :: none | #wallet{}, pass = none :: none | binary(), prefs = #{} :: #{module() := term()}, - wallets = [] :: [#wr{}], - in_flight = [] :: [#tx{}]}). + wallets = [] :: [#wr{}]}). -type state() :: #s{}. @@ -897,37 +896,34 @@ do_mnemonic(ID, #s{wallet = #wallet{keys = Keys}}) -> end. -do_deploy(Build, InitArgs, #s{selected = Index, wallet = #wallet{keys = Keys}}) -> - #key{pair = #s{public = PubKey, secret := SecKey}} = lists:nth(Index, Keys), +do_deploy(Build, + InitArgs, + #s{selected = Index, wallet = #wallet{keys = Keys, chain_id = ChainID}}) -> + #key{pair = #{public := PubKey, secret := SecKey}} = lists:nth(Index, Keys), case hz:contract_create_built(PubKey, Build, InitArgs) of - {ok, CreateTX} -> do_deploy2(SecKey, CreateTX); + {ok, CreateTX} -> do_deploy2(SecKey, CreateTX, ChainID); Error -> Error end. -do_deploy2(SecKey, CreateTX) -> - case gmc_con:sign(Request) of - {ok, SignedTX} -> do_deploy3(SignedTX); - Error -> Error - end. - -do_deploy3(SignedTX) -> +do_deploy2(SecKey, CreateTX, ChainID) -> + SignedTX = sign_tx_hash(CreateTX, SecKey, ChainID), case hz:post_tx(SignedTX) of {ok, Data = #{"tx_hash" := TXHash}} -> ok = tell("Contract deploy TX succeded with: ~p", [TXHash]), - do_deploy4(Data); + do_deploy3(Data); {ok, WTF} -> {error, WTF}; Error -> Error end. -do_deploy4(#{"tx_hash" := TXHash}) -> - case hz:tx_info(TZHash) of - {ok, {"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} -> +do_deploy3(#{"tx_hash" := TXHash}) -> + case hz:tx_info(TXHash) of + {ok, #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} -> {contract_id, ConID}; {error, "Tx not mined"} -> {tx_hash, TXHash}; - {ok, Reason = {"call_info" := #{"return_type" := "revert"}}} -> + {ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} -> {error, Reason}; Error -> Error @@ -1179,7 +1175,8 @@ read2(Bin) -> read3(T) -> case element(2, T) of - 1 -> {ok, T}; + 1 -> read3(setelement(2, erlang:append_element(T, #{}), 2)); + 2 -> {ok, T}; _ -> {error, bad_wallet} end. diff --git a/src/gmc_v_devman.erl b/src/gmc_v_devman.erl index 100b904..06b0216 100644 --- a/src/gmc_v_devman.erl +++ b/src/gmc_v_devman.erl @@ -292,7 +292,7 @@ clicked(State = #s{book = {Notebook, Pages}}, Name, Button) -> clicked(State, #p{instances = Is, funs = {_, Funs}, builds = Builds}, {<<"init">>, call}, - Button) -> + _Button) -> Label = wxChoice:getStringSelection(Is), Build = maps:get(Label, Builds), #f{args = Args} = lists:keyfind(<<"init">>, #f.name, Funs), @@ -300,14 +300,22 @@ clicked(State, ok = tell("Label: ~p~nArgs: ~p~nInitArgs: ~p", [Label, Args, InitArgs]), case gmc_con:deploy(Build, InitArgs) of {contract_id, ConID} -> + ok = tell("Got ConID: ~p", [ConID]), + State; {tx_hash, TX_Hash} -> + ok = tell("Got TX_Hash: ~p", [TX_Hash]), + State; {error, Reason} -> - ok = tell("Deploy failed with: ~p", [Reason]) + ok = tell("Deploy failed with: ~p", [Reason]), State -clicked(State, Page, Name) -> - ok = tell("Button: ~p~nPage: ~p", [Name, Page]), + end; +clicked(State, Page, Name, Button) -> + ok = tell("Button: ~p ~p~nPage: ~p", [Button, Name, Page]), State. +get_arg({_, TextCtrl, _}) -> + wxTextCtrl:getValue(TextCtrl). + new_file(State = #s{frame = Frame, j = J, prefs = Prefs}) -> DefaultDir = @@ -409,7 +417,7 @@ find_main([], M, Is) -> fun_interfaces(Window, Buttons, {OldScrollWin, OldIfaces}, - {#{name := Name, functions := Funs}, ConIfaces}, + {#{name := Name, functions := Funs}, _ConIfaces}, J) -> ok = wxScrolledWindow:destroy(OldScrollWin), OldButtonIDs = button_key_list(OldIfaces),