add more format options to decode_bytearray

I reversed the argument order here, since the Format option is sort of kind of almost optional, but I am not sure if that was a good idea.
This commit is contained in:
Jarvis Carroll 2026-02-24 06:12:00 +00:00
parent a0fbeebcdb
commit ddec3bfa74

View File

@ -71,7 +71,7 @@
contract_call/5,
contract_call/6,
contract_call/10,
decode_bytearray_fate/1, decode_bytearray/2,
decode_bytearray/2,
spend/5, spend/10,
sign_tx/2, sign_tx/3,
sign_message/2, verify_signature/3,
@ -701,8 +701,9 @@ decode_bytearray_fate(EncodedStr) ->
{ok, Object}
end.
-spec decode_bytearray(Type, EncodedStr) -> {ok, Result} | {error, Reason}
when Type :: term(),
-spec decode_bytearray(EncodedStr, Format) -> {ok, Result} | {error, Reason}
when Format :: fate | sophia | {sophia, Type} | {erlang, Type},
Type :: term(),
EncodedStr :: binary() | string(),
Result :: none | term(),
Reason :: term().
@ -713,13 +714,18 @@ decode_bytearray_fate(EncodedStr) ->
%% must be the result type of the same function in the same AACI that was used
%% to create the transaction that EncodedStr came from.
decode_bytearray(Type, EncodedStr) ->
decode_bytearray(EncodedStr, Format) ->
case decode_bytearray_fate(EncodedStr) of
{ok, none} -> {ok, none};
{ok, Object} -> hz_aaci:fate_to_erlang(Type, Object);
{ok, FATE} -> decode_bytearray2(FATE, Format);
{error, Reason} -> {error, Reason}
end.
decode_bytearray2(FATE, fate) -> FATE;
decode_bytearray2(FATE, sophia) -> hz_sophia:fate_to_list(FATE);
decode_bytearray2(FATE, {sophia, Type}) -> hz_sophia:fate_to_list(Type, FATE);
decode_bytearray2(FATE, {erlang, Type}) -> hz_aaci:fate_to_erlang(Type, FATE).
to_binary(S) when is_binary(S) -> S;
to_binary(S) when is_list(S) -> list_to_binary(S).