From efe0a64056c7231c8e18b82adbd0f00cd953dfcf Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Fri, 13 Feb 2026 13:50:29 +0900 Subject: [PATCH] Update comments, add fate and sophia tagged args --- src/hz.erl | 71 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/src/hz.erl b/src/hz.erl index fc50119..84d1535 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -892,7 +892,10 @@ result(Received) -> Received. -spec contract_create(CreatorID, Path, InitArgs) -> Result when CreatorID :: unicode:chardata(), Path :: file:filename(), - InitArgs :: [string()], + InitArgs :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, Result :: {ok, CreateTX} | {error, Reason}, CreateTX :: binary(), Reason :: file:posix() | term(). @@ -927,7 +930,10 @@ contract_create(CreatorID, Path, InitArgs) -> Gas :: pos_integer(), GasPrice :: pos_integer(), Path :: file:filename(), - InitArgs :: [string()], + InitArgs :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, Result :: {ok, CreateTX} | {error, Reason}, CreateTX :: binary(), Reason :: term(). @@ -1072,7 +1078,10 @@ contract_create2(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Options, -spec contract_create_built(CreatorID, Compiled, InitArgs) -> Result when CreatorID :: unicode:chardata(), Compiled :: map(), - InitArgs :: [string()], + InitArgs :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, Result :: {ok, CreateTX} | {error, Reason}, CreateTX :: binary(), Reason :: file:posix() | bad_fun_name | aaci_not_found | term(). @@ -1097,12 +1106,31 @@ contract_create_built(CreatorID, Compiled, InitArgs) -> end. +-spec contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) -> Result + when CreatorID :: unicode:chardata(), + Nonce :: pos_integer(), + Amount :: non_neg_integer(), + TTL :: non_neg_integer(), + Gas :: pos_integer(), + GasPrice :: pos_integer(), + Compiled :: map(), + InitArgs :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, + Result :: {ok, CreateTX} | {error, Reason}, + CreateTX :: binary(), + Reason :: file:posix() | bad_fun_name | aaci_not_found | term(). +%% @doc +%% See `contract_create/8' for detailed information on argument types. +%% The `Compiled' argument is the output of contract compilation and replaces the `File' +%% argument in `contract_create/8'. + contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) -> AACI = hz_aaci:prepare(maps:get(aci, Compiled)), case encode_call_data(AACI, "init", InitArgs) of {ok, CallData} -> - assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, - Compiled, CallData); + assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData); Error -> Error end. @@ -1192,7 +1220,10 @@ read_aci(Path) -> AACI :: aaci() | {aaci, Label :: term()}, ConID :: unicode:chardata(), Fun :: string(), - Args :: [string()] | {erlang, [term()]}, + Args :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, Result :: {ok, CallTX} | {error, Reason}, CallTX :: binary(), Reason :: term(). @@ -1227,7 +1258,10 @@ contract_call(CallerID, AACI, ConID, Fun, Args) -> AACI :: aaci() | {aaci, Label :: term()}, ConID :: unicode:chardata(), Fun :: string(), - Args :: [string()] | {erlang, [term()]}, + Args :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, Result :: {ok, CallTX} | {error, Reason}, CallTX :: binary(), Reason :: term(). @@ -1265,7 +1299,10 @@ contract_call(CallerID, Gas, AACI, ConID, Fun, Args) -> AACI :: aaci() | {aaci, Label :: term()}, ConID :: unicode:chardata(), Fun :: string(), - Args :: [string()] | {erlang, [term()]}, + Args :: [string()] + | {erlang, [term()]} + | {fate, [term()]} + | {sophia, [string()]}, Result :: {ok, CallTX} | {error, Reason}, CallTX :: binary(), Reason :: term(). @@ -1503,7 +1540,7 @@ min_gas_price() -> %% This function always returns 200,000 in the current version. min_gas() -> - 200000. + 200_000. encode_call_data({aaci, _ContractName, FunDefs, _TypeDefs}, Fun, Args) -> @@ -1517,16 +1554,22 @@ encode_call_data({aaci, Label}, Fun, Args) -> error -> {error, aaci_not_found} end. +encode_call_data2(ArgDef, Fun, {sophia, Args}) -> + case convert(ArgDef, Args) of + {ok, Converted} -> gmb_fate_abi:create_calldata(Fun, Converted); + Errors -> Errors + end; encode_call_data2(ArgDef, Fun, {erlang, Args}) -> case hz_aaci:erlang_args_to_fate(ArgDef, Args) of {ok, Coerced} -> gmb_fate_abi:create_calldata(Fun, Coerced); Errors -> Errors end; -encode_call_data2(ArgDef, Fun, SophiaArgs) -> - case convert(ArgDef, SophiaArgs) of - {ok, Args} -> gmb_fate_abi:create_calldata(Fun, Args); - Errors -> Errors - end. +encode_call_data2(_, Fun, {fate, Args}) -> + % TODO: This should probably be moved back closer to the initiating call. + % 2026-02-13: Craig + gmb_fate_abi:create_calldata(Fun, Args); +encode_call_data2(ArgDef, Fun, Args) -> + encode_call_data2(ArgDef, Fun, {sophia, Args}). convert(Defs, Args) -> convert(Defs, Args, 1, [], []).