From 9840b225462ab2ad00c22a8ee71f2373fa389944 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Tue, 18 Jun 2019 12:22:46 +0200 Subject: [PATCH] Add decoding function --- src/aeb_fate_abi.erl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/aeb_fate_abi.erl b/src/aeb_fate_abi.erl index 99f6af8..55fb5fc 100644 --- a/src/aeb_fate_abi.erl +++ b/src/aeb_fate_abi.erl @@ -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(<>, FateCode) ->