General polish #28
+8
-10
@@ -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.
|
||||
|
||||
|
|
||||
|
||||
|
||||
Reference in New Issue
Block a user
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.
@dimitar.p.ivanov mentions in a call that this satisfies Dialyzer -- so I'll look into that and see why.