Corrections and improvements

This commit is contained in:
Craig Everett 2025-03-04 22:43:19 +09:00
parent 2d4350fa49
commit fe05ddf9c3
2 changed files with 13 additions and 12 deletions

View File

@ -6,8 +6,8 @@ contract Counter =
stateful entrypoint init() = stateful entrypoint init() =
{value = 1} {value = 1}
stateful entrypoint increment() = stateful entrypoint increment(n : int) =
put({value = state.value + 1}) put({value = state.value + n})
entrypoint value() = entrypoint value() =
state.value state.value

View File

@ -20,7 +20,8 @@ deploy(Source, PubKey, SecKey) ->
end. end.
deploy2(Build, PubKey, SecKey) -> deploy2(Build, PubKey, SecKey) ->
ChainID = <<"groot.testnet">>, % NOTE: This obviously should come from the chain {ok, #{"network_id" := ChainID}} = hz:status(),
NetworkID = list_to_binary(ChainID),
{ok, Height} = hz:top_height(), {ok, Height} = hz:top_height(),
{ok, Nonce} = hz:next_nonce(PubKey), {ok, Nonce} = hz:next_nonce(PubKey),
TTL = Height + 10000, TTL = Height + 10000,
@ -31,8 +32,8 @@ deploy2(Build, PubKey, SecKey) ->
case hz:contract_create_built(PubKey, case hz:contract_create_built(PubKey,
Nonce, Amount, TTL, Gas, GasPrice, Nonce, Amount, TTL, Gas, GasPrice,
Build, InitArgs) of Build, InitArgs) of
{ok, CreateTX} -> deploy3(SecKey, CreateTX, ChainID); {ok, CreateTX} -> deploy3(SecKey, CreateTX, NetworkID);
Error -> gmc_v_devman:trouble(Error) Error -> gd_v_devman:trouble(Error)
end. end.
deploy3(SecKey, CreateTX, ChainID) -> deploy3(SecKey, CreateTX, ChainID) ->
@ -42,21 +43,21 @@ deploy3(SecKey, CreateTX, ChainID) ->
ok = io:format("The transaction hash is: ~p", [TXHash]), ok = io:format("The transaction hash is: ~p", [TXHash]),
deploy4(Data); deploy4(Data);
{ok, WTF} -> {ok, WTF} ->
gmc_v_devman:trouble({error, WTF}); gd_v_devman:trouble({error, WTF});
Error -> Error ->
gmc_v_devman:trouble(Error) gd_v_devman:trouble(Error)
end. end.
deploy4(#{"tx_hash" := TXHash}) -> deploy4(#{"tx_hash" := TXHash}) ->
case hz:tx_info(TXHash) of case hz:tx_info(TXHash) of
{ok, #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} -> {ok, #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
gmc_v_devman:open_contract(ConID); gd_v_devman:open_contract(ConID);
{error, "Tx not mined"} -> {error, "Tx not mined"} ->
gmc_v_devman:trouble({tx_hash, TXHash}); gd_v_devman:trouble({tx_hash, TXHash});
{ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} -> {ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} ->
gmc_v_devman:trouble({error, Reason}); gd_v_devman:trouble({error, Reason});
Error -> Error ->
gmc_v_devman:trouble(Error) gd_v_devman:trouble(Error)
end. end.