From f0f86ed36d90d8fec039cc4ed1a9747053a55440 Mon Sep 17 00:00:00 2001 From: Dimitar Ivanov Date: Wed, 13 May 2026 10:04:23 +0300 Subject: [PATCH 1/3] Improve specs --- src/hz.erl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/hz.erl b/src/hz.erl index 0e2271b..0008605 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -801,19 +801,23 @@ contract_source(ID) -> Error -> Error end. -extract(Blobby) -> +extract(<<"ba_", _/binary>> = Blobby) -> case gmser_api_encoder:safe_decode(bytearray, Blobby) of - {ok, TarBaby} -> extract2(TarBaby); - {error, invalid_encoding} -> {ok, Blobby} - end. + {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)}. extract2(TarBaby) -> case erl_tar:extract({binary, TarBaby}, [memory, compressed]) of + {ok, [{_File, Source}]} -> + {ok, unicode:characters_to_list(Source)}; {ok, Bundle} -> {project, Bundle}; Error -> io:format("Dis chit happen: ~tp~n", [Error]), - {ok, TarBaby} + {ok, unicode:characters_to_list(TarBaby)} end. @@ -895,6 +899,11 @@ request(Path) -> hz_man:request(unicode:characters_to_list(Path)). +-spec request(Path, Payload) -> {ok, Value} | {error, Reason} + when Path :: unicode:charlist(), + Payload :: unicode:charlist(), + Value :: map(), + Reason :: hz:chain_error(). request(Path, Payload) -> hz_man:request(unicode:characters_to_list(Path), Payload). -- 2.30.2 From 88aeb39d4aff0f539d40749d324a9053b6eb2d4a Mon Sep 17 00:00:00 2001 From: Dimitar Ivanov Date: Wed, 20 May 2026 17:02:36 +0300 Subject: [PATCH 2/3] Fix a contract create bug --- src/hz.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hz.erl b/src/hz.erl index 0008605..75b9911 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -939,7 +939,7 @@ contract_create(CreatorID, Path, InitArgs) -> Gas = 500000, GasPrice = min_gas_price(), contract_create(CreatorID, Nonce, - Amount, TTL, Gas, GasPrice, + Gas, GasPrice, Amount, TTL, Path, InitArgs); Error -> Error -- 2.30.2 From 2a7079129f34d3a7eed6312ab2479db0b0d4b708 Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Thu, 21 May 2026 17:07:57 +0900 Subject: [PATCH 3/3] Fix typespec Source needs to be defined as a binary. --- src/hz.erl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hz.erl b/src/hz.erl index 75b9911..9200e89 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -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. -- 2.30.2