Adjusting a few calls.
This commit is contained in:
parent
3838a7e3c5
commit
6c172c4783
29
src/hz.erl
29
src/hz.erl
@ -1098,7 +1098,7 @@ contract_create_built(CreatorID, Compiled, InitArgs) ->
|
|||||||
|
|
||||||
|
|
||||||
contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) ->
|
contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) ->
|
||||||
AACI = hz_aaci:prepare_aaci(maps:get(aci, Compiled)),
|
AACI = hz_aaci:prepare(maps:get(aci, Compiled)),
|
||||||
case encode_call_data(AACI, "init", InitArgs) of
|
case encode_call_data(AACI, "init", InitArgs) of
|
||||||
{ok, CallData} ->
|
{ok, CallData} ->
|
||||||
assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
|
assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
|
||||||
@ -1192,7 +1192,7 @@ read_aci(Path) ->
|
|||||||
AACI :: aaci() | {aaci, Label :: term()},
|
AACI :: aaci() | {aaci, Label :: term()},
|
||||||
ConID :: unicode:chardata(),
|
ConID :: unicode:chardata(),
|
||||||
Fun :: string(),
|
Fun :: string(),
|
||||||
Args :: [string()],
|
Args :: [string()] | {erlang, [term()]},
|
||||||
Result :: {ok, CallTX} | {error, Reason},
|
Result :: {ok, CallTX} | {error, Reason},
|
||||||
CallTX :: binary(),
|
CallTX :: binary(),
|
||||||
Reason :: term().
|
Reason :: term().
|
||||||
@ -1227,7 +1227,7 @@ contract_call(CallerID, AACI, ConID, Fun, Args) ->
|
|||||||
AACI :: aaci() | {aaci, Label :: term()},
|
AACI :: aaci() | {aaci, Label :: term()},
|
||||||
ConID :: unicode:chardata(),
|
ConID :: unicode:chardata(),
|
||||||
Fun :: string(),
|
Fun :: string(),
|
||||||
Args :: [string()],
|
Args :: [string()] | {erlang, [term()]},
|
||||||
Result :: {ok, CallTX} | {error, Reason},
|
Result :: {ok, CallTX} | {error, Reason},
|
||||||
CallTX :: binary(),
|
CallTX :: binary(),
|
||||||
Reason :: term().
|
Reason :: term().
|
||||||
@ -1265,7 +1265,7 @@ contract_call(CallerID, Gas, AACI, ConID, Fun, Args) ->
|
|||||||
AACI :: aaci() | {aaci, Label :: term()},
|
AACI :: aaci() | {aaci, Label :: term()},
|
||||||
ConID :: unicode:chardata(),
|
ConID :: unicode:chardata(),
|
||||||
Fun :: string(),
|
Fun :: string(),
|
||||||
Args :: [string()],
|
Args :: [string()] | {erlang, [term()]},
|
||||||
Result :: {ok, CallTX} | {error, Reason},
|
Result :: {ok, CallTX} | {error, Reason},
|
||||||
CallTX :: binary(),
|
CallTX :: binary(),
|
||||||
Reason :: term().
|
Reason :: term().
|
||||||
@ -1437,7 +1437,7 @@ contract_call4(PK, Nonce, Gas, GasPrice, Amount, TTL, CK, CallData) ->
|
|||||||
|
|
||||||
prepare_contract(File) ->
|
prepare_contract(File) ->
|
||||||
case so_compiler:file(File, [{aci, json}]) of
|
case so_compiler:file(File, [{aci, json}]) of
|
||||||
{ok, #{aci := ACI}} -> {ok, hz_aaci:prepare_aaci(ACI)};
|
{ok, #{aci := ACI}} -> {ok, hz_aaci:prepare(ACI)};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -1517,12 +1517,29 @@ encode_call_data({aaci, Label}, Fun, Args) ->
|
|||||||
error -> {error, aaci_not_found}
|
error -> {error, aaci_not_found}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
encode_call_data2(ArgDef, Fun, Args) ->
|
encode_call_data2(ArgDef, Fun, {erlang, Args}) ->
|
||||||
case hz_aaci:erlang_args_to_fate(ArgDef, Args) of
|
case hz_aaci:erlang_args_to_fate(ArgDef, Args) of
|
||||||
{ok, Coerced} -> gmb_fate_abi:create_calldata(Fun, Coerced);
|
{ok, Coerced} -> gmb_fate_abi:create_calldata(Fun, Coerced);
|
||||||
Errors -> Errors
|
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.
|
end.
|
||||||
|
|
||||||
|
convert(Defs, Args) -> convert(Defs, Args, 1, [], []).
|
||||||
|
|
||||||
|
convert([{Name, Def} | Defs], [Arg | Args], Nth, Terms, Errors) ->
|
||||||
|
case hz_sophia:parse_literal(Def, Arg) of
|
||||||
|
{ok, Term} -> convert(Defs, Args, Nth + 1, [Term | Terms], Errors);
|
||||||
|
{error, Reason} -> convert(Defs, Args, Nth + 1, Terms, [{Nth, Name, Reason} | Errors])
|
||||||
|
end;
|
||||||
|
convert([], [], _, Terms, []) ->
|
||||||
|
{ok, lists:reverse(Terms)};
|
||||||
|
convert([], [], _, _, Errors) ->
|
||||||
|
{error, Errors}.
|
||||||
|
|
||||||
|
|
||||||
sign_tx(Unsigned, SecKey) ->
|
sign_tx(Unsigned, SecKey) ->
|
||||||
case network_id() of
|
case network_id() of
|
||||||
|
|||||||
@ -16,8 +16,8 @@
|
|||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
|
|
||||||
% Contract call and serialization interface functions
|
% Contract call and serialization interface functions
|
||||||
-export([prepare_contract/1,
|
-export([prepare_from_file/1,
|
||||||
prepare_aaci/1,
|
prepare/1,
|
||||||
erlang_to_fate/2,
|
erlang_to_fate/2,
|
||||||
fate_to_erlang/2,
|
fate_to_erlang/2,
|
||||||
erlang_args_to_fate/2,
|
erlang_args_to_fate/2,
|
||||||
@ -33,21 +33,22 @@
|
|||||||
|
|
||||||
%%% ACI/AACI
|
%%% ACI/AACI
|
||||||
|
|
||||||
-spec prepare_contract(File) -> {ok, AACI} | {error, Reason}
|
-spec prepare_from_file(Path) -> {ok, AACI} | {error, Reason}
|
||||||
when File :: file:filename(),
|
when Path :: file:filename(),
|
||||||
AACI :: aaci(),
|
AACI :: aaci(),
|
||||||
Reason :: term().
|
Reason :: term().
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Compile a contract and extract the function spec meta for use in future formation
|
%% Compile a contract and extract the function spec meta for use in future formation
|
||||||
%% of calldata
|
%% of calldata
|
||||||
|
|
||||||
prepare_contract(File) ->
|
prepare_from_file(Path) ->
|
||||||
case so_compiler:file(File, [{aci, json}]) of
|
case so_compiler:file(Path, [{aci, json}]) of
|
||||||
{ok, #{aci := ACI}} -> {ok, prepare_aaci(ACI)};
|
{ok, #{aci := ACI}} -> {ok, prepare(ACI)};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
prepare_aaci(ACI) ->
|
|
||||||
|
prepare(ACI) ->
|
||||||
% We want to take the types represented by the ACI, things like N1.T(N2.T),
|
% We want to take the types represented by the ACI, things like N1.T(N2.T),
|
||||||
% and dereference them down to concrete types like
|
% and dereference them down to concrete types like
|
||||||
% {tuple, [integer, string]}. Our type dereferencing algorithms
|
% {tuple, [integer, string]}. Our type dereferencing algorithms
|
||||||
@ -1009,7 +1010,7 @@ coerce_hash_test() ->
|
|||||||
|
|
||||||
aaci_from_string(String) ->
|
aaci_from_string(String) ->
|
||||||
case so_compiler:from_string(String, [{aci, json}]) of
|
case so_compiler:from_string(String, [{aci, json}]) of
|
||||||
{ok, #{aci := ACI}} -> {ok, prepare_aaci(ACI)};
|
{ok, #{aci := ACI}} -> {ok, prepare(ACI)};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
|
||||||
|
-spec parse_literal(String) -> Result
|
||||||
|
when String :: string(),
|
||||||
|
Result :: {ok, gmb_fate_data:fate_type()}
|
||||||
|
| {error, Reason :: term()}.
|
||||||
|
|
||||||
parse_literal(String) ->
|
parse_literal(String) ->
|
||||||
parse_literal(unknown_type(), String).
|
parse_literal(unknown_type(), String).
|
||||||
|
|
||||||
@ -821,7 +827,7 @@ compile_entrypoint_value_and_type(Source, Entrypoint) ->
|
|||||||
FATE = extract_return_value(Code),
|
FATE = extract_return_value(Code),
|
||||||
|
|
||||||
% Generate the AACI, and get the AACI type info for the correct entrypoint.
|
% Generate the AACI, and get the AACI type info for the correct entrypoint.
|
||||||
AACI = hz_aaci:prepare_aaci(ACI),
|
AACI = hz_aaci:prepare(ACI),
|
||||||
{ok, {_, Type}} = hz_aaci:get_function_signature(AACI, "f"),
|
{ok, {_, Type}} = hz_aaci:get_function_signature(AACI, "f"),
|
||||||
|
|
||||||
{FATE, Type}.
|
{FATE, Type}.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user