General polish #28

Merged
dimitar.p.ivanov merged 4 commits from improve_specs into master 2026-05-22 16:54:18 +09:00
Showing only changes of commit 4530fd2e93 - Show all commits
+8 -10
View File
@@ -788,9 +788,9 @@ contract_code(ID) ->
Result :: {ok, Source}
| {project, Bundle}
| {error, Reason},
Source :: string(),
Source :: binary(),
Bundle :: [{FilePath :: string(), Contents :: binary()}],
Reason :: chain_error() | string().
Reason :: chain_error() | string().
%% @doc
%% Retrieve the code of a contract as represented on chain.
@@ -801,23 +801,21 @@ contract_source(ID) ->
Error -> Error
end.
extract(<<"ba_", _/binary>> = Blobby) ->
extract(Blobby) ->
case gmser_api_encoder:safe_decode(bytearray, Blobby) of
{ok, TarBaby} -> extract2(TarBaby);
{error, invalid_encoding} -> {ok, unicode:characters_to_list(Blobby)}
end;
extract(Blobby) when is_binary(Blobby) ->
{ok, unicode:characters_to_list(Blobby)}.
{ok, TarBaby} -> extract2(TarBaby);
{error, invalid_encoding} -> {ok, Blobby}
end.
extract2(TarBaby) ->
case erl_tar:extract({binary, TarBaby}, [memory, compressed]) of
{ok, [{_File, Source}]} ->
{ok, unicode:characters_to_list(Source)};
{ok, Source};
{ok, Bundle} ->
{project, Bundle};
Error ->
io:format("Dis chit happen: ~tp~n", [Error]),
{ok, unicode:characters_to_list(TarBaby)}
{ok, TarBaby}
end.
Outdated
Review

There is no guarantee that anything committed in the source element is valid unicode, so we have to leave the casting from binary to list up to the caller. That's why the original didn't even care to match on "ba_" as a prefix -- if we can't decode then we're talking to an alien node interface to begin with, and just return the return.

There is no guarantee that anything committed in the source element is valid unicode, so we have to leave the casting from binary to list up to the caller. That's why the original didn't even care to match on "ba_" as a prefix -- if we can't decode then we're talking to an alien node interface to begin with, and just return the return.
Outdated
Review

@dimitar.p.ivanov mentions in a call that this satisfies Dialyzer -- so I'll look into that and see why.

@dimitar.p.ivanov mentions in a call that this satisfies Dialyzer -- so I'll look into that and see why.