Merge pull request #51 from aeternity/PT-166696064-decode-calldata-fate
Pt 166696064 decode calldata fate
This commit is contained in:
@@ -43,7 +43,7 @@ create_calldata(FunName, Args, ArgTypes0, RetType) ->
|
||||
<<TypeHashInt:?HASH_SIZE/unit:8>> =
|
||||
function_type_hash(list_to_binary(FunName), ArgTypes, RetType),
|
||||
Data = aeb_heap:to_binary({TypeHashInt, list_to_tuple(Args)}),
|
||||
{ok, Data, {tuple, [word, ArgTypes]}, RetType}.
|
||||
{ok, Data}.
|
||||
|
||||
-spec check_calldata(binary(), type_info()) ->
|
||||
{'ok', typerep(), typerep()} | {'error', atom()}.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
-module(aeb_fate_abi).
|
||||
|
||||
-export([ create_calldata/2
|
||||
, decode_calldata/2
|
||||
, get_function_hash_from_calldata/1
|
||||
, get_function_name_from_function_hash/2
|
||||
, get_function_type_from_function_hash/2 ]).
|
||||
@@ -27,6 +28,14 @@ create_calldata(FunName, Args) ->
|
||||
aeb_fate_data:make_tuple({FunctionId,
|
||||
aeb_fate_data:make_tuple(list_to_tuple(Args))}))}.
|
||||
|
||||
-spec decode_calldata(list(), binary()) -> {ok, term()} | {error, term()}.
|
||||
decode_calldata(FunName, Calldata) ->
|
||||
FunctionId = aeb_fate_code:symbol_identifier(list_to_binary(FunName)),
|
||||
case ?FATE_TUPLE_ELEMENTS(aeb_fate_encoding:deserialize(Calldata)) of
|
||||
[FunctionId, FateArgs] -> {ok, ?FATE_TUPLE_ELEMENTS(FateArgs)};
|
||||
_ -> {error, decode_error}
|
||||
end.
|
||||
|
||||
-spec get_function_name_from_function_hash(binary(), aeb_fate_code:fcode()) ->
|
||||
{ok, term()} | {error, term()}.
|
||||
get_function_name_from_function_hash(<<SymbolHash:4/binary, _:28/binary>>, FateCode) ->
|
||||
|
||||
@@ -373,6 +373,7 @@ deserialize2(<<?POS_BITS, Rest/binary>>) ->
|
||||
{?FATE_BITS(Bint), Rest2};
|
||||
deserialize2(<<?LONG_STRING, Rest/binary>>) ->
|
||||
{S, Rest2} = deserialize_one(Rest),
|
||||
true = is_integer(S) andalso S >= 0,
|
||||
Size = S + ?SHORT_STRING_SIZE,
|
||||
String = binary:part(Rest2, 0, Size),
|
||||
Rest3 = binary:part(Rest2, byte_size(Rest2), - (byte_size(Rest2) - Size)),
|
||||
|
||||
Reference in New Issue
Block a user