Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename type_defs to typedefs in ACI to increase compatibility #421

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
```
- Return a mapping from variables to FATE registers in the compilation output.
### Changed
- Type definitions serialised to ACI as `typedefs` field instead of `type_defs` to increase compatibility.
### Removed
### Fixed

Expand Down
4 changes: 2 additions & 2 deletions docs/aeso_aci.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ generates the following JSON structure representing the contract interface:
}
]
},
"type_defs": [
"typedefs": [
{
"name": "answers",
"typedef": {
Expand Down Expand Up @@ -138,7 +138,7 @@ be included inside another contract.
state =>
#{record =>
[#{name => <<"a">>,type => <<"Answers.answers">>}]},
type_defs =>
typedefs =>
[#{name => <<"answers">>,
typedef => #{<<"map">> => [<<"string">>,<<"int">>]},
vars => []}]}}]}
Expand Down
8 changes: 4 additions & 4 deletions src/aeso_aci.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ encode_contract(Contract = {Head, _, {con, _, Name}, _, _}) when ?IS_CONTRACT_HE
{Es, Tdefs1} = lists:partition(FilterT(<<"event">>), Tdefs0),
{Ss, Tdefs} = lists:partition(FilterT(<<"state">>), Tdefs1),

C1 = C0#{type_defs => Tdefs},
C1 = C0#{typedefs => Tdefs},

C2 = case Es of
[] -> C1;
Expand All @@ -111,7 +111,7 @@ encode_contract(Contract = {Head, _, {con, _, Name}, _, _}) when ?IS_CONTRACT_HE
encode_contract(Namespace = {namespace, _, {con, _, Name}, _}) ->
Tdefs = [ encode_typedef(T) || T <- sort_decls(contract_types(Namespace)) ],
#{namespace => #{name => encode_name(Name),
type_defs => Tdefs}}.
typedefs => Tdefs}}.

%% Encode a function definition. Currently we are only interested in
%% the interface and type.
Expand Down Expand Up @@ -234,7 +234,7 @@ do_render_aci_json(Json) ->
decode_contract(#{contract := #{name := Name,
kind := Kind,
payable := Payable,
type_defs := Ts0,
typedefs := Ts0,
functions := Fs} = C}) ->
MkTDef = fun(N, T) -> #{name => N, vars => [], typedef => T} end,
Ts = [ MkTDef(<<"state">>, maps:get(state, C)) || maps:is_key(state, C) ] ++
Expand All @@ -246,7 +246,7 @@ decode_contract(#{contract := #{name := Name,
end,
io_lib:format("~s", [Name])," =\n",
decode_tdefs(Ts), decode_funcs(Fs)];
decode_contract(#{namespace := #{name := Name, type_defs := Ts}}) when Ts /= [] ->
decode_contract(#{namespace := #{name := Name, typedefs := Ts}}) when Ts /= [] ->
["namespace ", io_lib:format("~s", [Name])," =\n",
decode_tdefs(Ts)];
decode_contract(_) -> [].
Expand Down
6 changes: 3 additions & 3 deletions test/aeso_aci_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_cases(1) ->
" payable stateful entrypoint a(i : int) = i+1\n">>,
MapACI = #{contract =>
#{name => <<"C">>,
type_defs => [],
typedefs => [],
payable => true,
kind => contract_main,
functions =>
Expand All @@ -43,7 +43,7 @@ test_cases(2) ->
MapACI = #{contract =>
#{name => <<"C">>, payable => false,
kind => contract_main,
type_defs =>
typedefs =>
[#{name => <<"allan">>,
typedef => <<"int">>,
vars => []}],
Expand Down Expand Up @@ -76,7 +76,7 @@ test_cases(3) ->
name => <<"C">>, payable => false, kind => contract_main,
event => #{variant => [#{<<"SingleEventDefined">> => []}]},
state => <<"unit">>,
type_defs =>
typedefs =>
[#{name => <<"bert">>,
typedef =>
#{variant =>
Expand Down