Compare commits

..

1 Commits

Author SHA1 Message Date
Dimitar Ivanov
0119f1207f Bump gmserialization to v1.2.0 2025-03-01 15:15:10 +02:00
2 changed files with 21 additions and 21 deletions

View File

@ -27,7 +27,7 @@
, validate_byte_code/3 , validate_byte_code/3
]). ]).
-include_lib("gmbytecode/include/aeb_opcodes.hrl"). -include_lib("gmbytecode/include/gmb_opcodes.hrl").
-include("aeso_utils.hrl"). -include("aeso_utils.hrl").
@ -124,14 +124,14 @@ from_string1(ContractString, Options) ->
SavedFreshNames = maps:get(saved_fresh_names, FCodeEnv, #{}), SavedFreshNames = maps:get(saved_fresh_names, FCodeEnv, #{}),
FateCode = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options), FateCode = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options),
pp_assembler(FateCode, Options), pp_assembler(FateCode, Options),
ByteCode = aeb_fate_code:serialize(FateCode, []), ByteCode = gmb_fate_code:serialize(FateCode, []),
{ok, Version} = version(), {ok, Version} = version(),
Res = #{byte_code => ByteCode, Res = #{byte_code => ByteCode,
compiler_version => Version, compiler_version => Version,
contract_source => ContractString, contract_source => ContractString,
type_info => [], type_info => [],
fate_code => FateCode, fate_code => FateCode,
abi_version => aeb_fate_abi:abi_version(), abi_version => gmb_fate_abi:abi_version(),
payable => maps:get(payable, FCode), payable => maps:get(payable, FCode),
warnings => Warnings warnings => Warnings
}, },
@ -203,7 +203,7 @@ add_extra_call(Contract0, Call, Options) ->
, ast := Ast} = string_to_code(Contract0, Options), , ast := Ast} = string_to_code(Contract0, Options),
FateCode = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, #{}, []), FateCode = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, #{}, []),
%% collect all hashes and compute the first name without hash collision to %% collect all hashes and compute the first name without hash collision to
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)), SymbolHashes = maps:keys(gmb_fate_code:symbols(FateCode)),
CallName = first_none_match(?CALL_NAME, SymbolHashes, CallName = first_none_match(?CALL_NAME, SymbolHashes,
lists:seq($1, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z)), lists:seq($1, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z)),
Contract = insert_call_function(Ast, Contract0, CallName, Call), Contract = insert_call_function(Ast, Contract0, CallName, Call),
@ -220,7 +220,7 @@ encode_value(Contract0, Type, Value, Options) ->
case add_extra_call(Contract0, {value, Type, Value}, Options) of case add_extra_call(Contract0, {value, Type, Value}, Options) of
{ok, CallName, Code} -> {ok, CallName, Code} ->
Body = get_call_body(CallName, Code), Body = get_call_body(CallName, Code),
{ok, aeb_fate_encoding:serialize(aeso_fcode_to_fate:term_to_fate(Body))}; {ok, gmb_fate_encoding:serialize(aeso_fcode_to_fate:term_to_fate(Body))};
Err = {error, _} -> Err = {error, _} ->
Err Err
end. end.
@ -243,7 +243,7 @@ decode_value(Contract0, Type, FateValue, Options) ->
first_none_match(_CallName, _Hashes, []) -> first_none_match(_CallName, _Hashes, []) ->
error(unable_to_find_unique_call_name); error(unable_to_find_unique_call_name);
first_none_match(CallName, Hashes, [Char|Chars]) -> first_none_match(CallName, Hashes, [Char|Chars]) ->
case not lists:member(aeb_fate_code:symbol_identifier(list_to_binary(CallName)), Hashes) of case not lists:member(gmb_fate_code:symbol_identifier(list_to_binary(CallName)), Hashes) of
true -> true ->
CallName; CallName;
false -> false ->
@ -303,7 +303,7 @@ to_sophia_value(ContractString, Fun, ResType, Data) ->
to_sophia_value(_, _, error, Err, _Options) -> to_sophia_value(_, _, error, Err, _Options) ->
{ok, {app, [], {id, [], "error"}, [{string, [], Err}]}}; {ok, {app, [], {id, [], "error"}, [{string, [], Err}]}};
to_sophia_value(_, _, revert, Data, _Options) -> to_sophia_value(_, _, revert, Data, _Options) ->
try aeso_vm_decode:from_fate({id, [], "string"}, aeb_fate_encoding:deserialize(Data)) of try aeso_vm_decode:from_fate({id, [], "string"}, gmb_fate_encoding:deserialize(Data)) of
Err -> Err ->
{ok, {app, [], {id, [], "abort"}, [Err]}} {ok, {app, [], {id, [], "abort"}, [Err]}}
catch _:_ -> catch _:_ ->
@ -328,11 +328,11 @@ to_sophia_value(ContractString, FunName, ok, Data, Options0) ->
fate_data_to_sophia_value(Type, UnfoldedType, FateData) -> fate_data_to_sophia_value(Type, UnfoldedType, FateData) ->
try try
{ok, aeso_vm_decode:from_fate(UnfoldedType, aeb_fate_encoding:deserialize(FateData))} {ok, aeso_vm_decode:from_fate(UnfoldedType, gmb_fate_encoding:deserialize(FateData))}
catch throw:cannot_translate_to_sophia -> catch throw:cannot_translate_to_sophia ->
Type1 = prettypr:format(aeso_pretty:type(Type)), Type1 = prettypr:format(aeso_pretty:type(Type)),
Msg = io_lib:format("Cannot translate FATE value ~p\n of Sophia type ~s", Msg = io_lib:format("Cannot translate FATE value ~p\n of Sophia type ~s",
[aeb_fate_encoding:deserialize(FateData), Type1]), [gmb_fate_encoding:deserialize(FateData), Type1]),
{error, [aeso_errors:new(data_error, Msg)]}; {error, [aeso_errors:new(data_error, Msg)]};
_:_ -> _:_ ->
Type1 = prettypr:format(aeso_pretty:type(Type)), Type1 = prettypr:format(aeso_pretty:type(Type)),
@ -350,7 +350,7 @@ create_calldata(Code, Fun, Args, Options0) ->
Options = [no_code | Options0], Options = [no_code | Options0],
case check_call(Code, Fun, Args, Options) of case check_call(Code, Fun, Args, Options) of
{ok, FunName, FateArgs} -> {ok, FunName, FateArgs} ->
aeb_fate_abi:create_calldata(FunName, FateArgs); gmb_fate_abi:create_calldata(FunName, FateArgs);
{error, _} = Err -> Err {error, _} = Err -> Err
end. end.
@ -377,7 +377,7 @@ decode_calldata(ContractString, FunName, Calldata, Options0) ->
[ unfold_record_types [ unfold_record_types
, unfold_variant_types , unfold_variant_types
, not_unfold_system_alias_types]), , not_unfold_system_alias_types]),
case aeb_fate_abi:decode_calldata(FunName, Calldata) of case gmb_fate_abi:decode_calldata(FunName, Calldata) of
{ok, FateArgs} -> {ok, FateArgs} ->
try try
{tuple_t, [], ArgTypes1} = Type, {tuple_t, [], ArgTypes1} = Type,
@ -424,7 +424,7 @@ pp_sophia_code(C, Opts)-> pp(C, Opts, pp_sophia_code, fun(Code) ->
pp_ast(C, Opts) -> pp(C, Opts, pp_ast, fun aeso_ast:pp/1). pp_ast(C, Opts) -> pp(C, Opts, pp_ast, fun aeso_ast:pp/1).
pp_typed_ast(C, Opts)-> pp(C, Opts, pp_typed_ast, fun aeso_ast:pp_typed/1). pp_typed_ast(C, Opts)-> pp(C, Opts, pp_typed_ast, fun aeso_ast:pp_typed/1).
pp_assembler(C, Opts) -> pp(C, Opts, pp_assembler, fun(Asm) -> io:format("~s", [aeb_fate_asm:pp(Asm)]) end). pp_assembler(C, Opts) -> pp(C, Opts, pp_assembler, fun(Asm) -> io:format("~s", [gmb_fate_asm:pp(Asm)]) end).
pp(Code, Options, Option, PPFun) -> pp(Code, Options, Option, PPFun) ->
case proplists:lookup(Option, Options) of case proplists:lookup(Option, Options) of
@ -442,14 +442,14 @@ pp(Code, Options, Option, PPFun) ->
validate_byte_code(#{ byte_code := ByteCode, payable := Payable }, Source, Options) -> validate_byte_code(#{ byte_code := ByteCode, payable := Payable }, Source, Options) ->
Fail = fun(Err) -> {error, [aeso_errors:new(data_error, Err)]} end, Fail = fun(Err) -> {error, [aeso_errors:new(data_error, Err)]} end,
try try
FCode1 = ?protect(deserialize, aeb_fate_code:strip_init_function(aeb_fate_code:deserialize(ByteCode))), FCode1 = ?protect(deserialize, gmb_fate_code:strip_init_function(gmb_fate_code:deserialize(ByteCode))),
{FCode2, SrcPayable} = {FCode2, SrcPayable} =
?protect(compile, ?protect(compile,
begin begin
{ok, #{ byte_code := SrcByteCode, payable := SrcPayable }} = {ok, #{ byte_code := SrcByteCode, payable := SrcPayable }} =
from_string1(Source, Options), from_string1(Source, Options),
FCode = aeb_fate_code:deserialize(SrcByteCode), FCode = gmb_fate_code:deserialize(SrcByteCode),
{aeb_fate_code:strip_init_function(FCode), SrcPayable} {gmb_fate_code:strip_init_function(FCode), SrcPayable}
end), end),
case compare_fate_code(FCode1, FCode2) of case compare_fate_code(FCode1, FCode2) of
ok when SrcPayable /= Payable -> ok when SrcPayable /= Payable ->
@ -465,10 +465,10 @@ validate_byte_code(#{ byte_code := ByteCode, payable := Payable }, Source, Optio
end. end.
compare_fate_code(FCode1, FCode2) -> compare_fate_code(FCode1, FCode2) ->
Funs1 = aeb_fate_code:functions(FCode1), Funs1 = gmb_fate_code:functions(FCode1),
Funs2 = aeb_fate_code:functions(FCode2), Funs2 = gmb_fate_code:functions(FCode2),
Syms1 = aeb_fate_code:symbols(FCode1), Syms1 = gmb_fate_code:symbols(FCode1),
Syms2 = aeb_fate_code:symbols(FCode2), Syms2 = gmb_fate_code:symbols(FCode2),
FunHashes1 = maps:keys(Funs1), FunHashes1 = maps:keys(Funs1),
FunHashes2 = maps:keys(Funs2), FunHashes2 = maps:keys(Funs2),
case FunHashes1 == FunHashes2 of case FunHashes1 == FunHashes2 of

View File

@ -8,9 +8,9 @@
-export([ from_fate/2 ]). -export([ from_fate/2 ]).
-include_lib("gmbytecode/include/aeb_fate_data.hrl"). -include_lib("gmbytecode/include/gmb_fate_data.hrl").
-spec from_fate(aeso_syntax:type(), aeb_fate_data:fate_type()) -> aeso_syntax:expr(). -spec from_fate(aeso_syntax:type(), gmb_fate_data:fate_type()) -> aeso_syntax:expr().
from_fate({id, _, "address"}, ?FATE_ADDRESS(Bin)) -> {account_pubkey, [], Bin}; from_fate({id, _, "address"}, ?FATE_ADDRESS(Bin)) -> {account_pubkey, [], Bin};
from_fate({id, _, "signature"}, ?FATE_BYTES(Bin)) -> {signature, [], Bin}; from_fate({id, _, "signature"}, ?FATE_BYTES(Bin)) -> {signature, [], Bin};
from_fate({id, _, "hash"}, ?FATE_BYTES(Bin)) -> {bytes, [], Bin}; from_fate({id, _, "hash"}, ?FATE_BYTES(Bin)) -> {bytes, [], Bin};