From 81f277127d57e656dfff421647d4857d1137496a Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Fri, 14 Jun 2019 16:08:59 +0200 Subject: [PATCH] Handle signature, hash and map in create_calldata for FATE --- src/aeso_ast_to_fcode.erl | 4 ++++ src/aeso_fcode_to_fate.erl | 14 ++++++++++++-- test/aeso_calldata_tests.erl | 12 +++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 6948b3d..7c1b405 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -37,6 +37,8 @@ -type flit() :: {int, integer()} | {string, binary()} + | {hash, binary()} + | {signature, binary()} | {account_pubkey, binary()} | {contract_pubkey, binary()} | {oracle_pubkey, binary()} @@ -365,6 +367,8 @@ expr_to_fcode(_Env, _Type, {contract_pubkey, _, K}) -> {lit, {contract_pubkey, K expr_to_fcode(_Env, _Type, {oracle_pubkey, _, K}) -> {lit, {oracle_pubkey, K}}; expr_to_fcode(_Env, _Type, {oracle_query_id, _, K}) -> {lit, {oracle_query_id, K}}; +expr_to_fcode(_Env, _Type, {bytes, _, Bin = <<_:32/binary>>}) -> {lit, {hash, Bin}}; +expr_to_fcode(_Env, _Type, {bytes, _, Bin = <<_:64/binary>>}) -> {lit, {signature, Bin}}; expr_to_fcode(_Env, _Type, {bytes, _, Bin}) -> {lit, {string, Bin}}; %% Variables diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 2bd4a00..bfaf1c3 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -233,9 +233,11 @@ lookup_var(#env{vars = Vars}, X) -> %% -- The compiler -- lit_to_fate(L) -> - case L of + case L of {int, N} -> aeb_fate_data:make_integer(N); {string, S} -> aeb_fate_data:make_string(S); + {hash, H} -> aeb_fate_data:make_hash(H); + {signature, S} -> aeb_fate_data:make_signature(S); {bool, B} -> aeb_fate_data:make_boolean(B); {account_pubkey, K} -> aeb_fate_data:make_address(K); {contract_pubkey, K} -> aeb_fate_data:make_contract(K); @@ -257,8 +259,16 @@ term_to_fate({tuple, As}) -> aeb_fate_data:make_tuple(list_to_tuple([ term_to_fate(A) || A<-As])); term_to_fate({con, Ar, I, As}) -> FateAs = [ term_to_fate(A) || A <- As ], - aeb_fate_data:make_variant(Ar, I, list_to_tuple(FateAs)). + aeb_fate_data:make_variant(Ar, I, list_to_tuple(FateAs)); +term_to_fate({builtin, map_empty, []}) -> + aeb_fate_data:make_map(#{}); +term_to_fate({'let', _, {builtin, map_empty, []}, Set}) -> + aeb_fate_data:make_map(map_to_fate(Set)). +map_to_fate({op, map_set, [{var, _}, K, V]}) -> + #{term_to_fate(K) => term_to_fate(V)}; +map_to_fate({op, map_set, [Set, K, V]}) -> + Map = map_to_fate(Set), Map#{term_to_fate(K) => term_to_fate(V)}. to_scode(_Env, {lit, L}) -> [push(?i(lit_to_fate(L)))]; diff --git a/test/aeso_calldata_tests.erl b/test/aeso_calldata_tests.erl index 3b19d3f..83c5586 100644 --- a/test/aeso_calldata_tests.erl +++ b/test/aeso_calldata_tests.erl @@ -57,20 +57,22 @@ compilable_contracts() -> ["ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt", "200000", "1000"]}, {"maps", "fromlist_i", ["[(1, {x = 1, y = 2}), (2, {x = 3, y = 4}), (3, {x = 4, y = 4})]"]}, + {"maps", "get_i", ["1", "{}"]}, + {"maps", "get_i", ["1", "{[1] = {x = 3, y = 4}}"]}, + {"maps", "get_i", ["1", "{[1] = {x = 3, y = 4}, [2] = {x = 4, y = 5}}"]}, + {"maps", "get_i", ["1", "{[1] = {x = 3, y = 4}, [2] = {x = 4, y = 5}, [3] = {x = 5, y = 6}}"]}, {"strings", "str_concat", ["\"test\"","\"me\""]}, {"complex_types", "filter_some", ["[Some(1), Some(2), None]"]}, {"complex_types", "init", ["ct_Ez6MyeTMm17YnTnDdHTSrzMEBKmy7Uz2sXu347bTDPgVH2ifJ"]}, {"__call" "init", []}, - {"bitcoin_auth", "init", - ["#0102030405060708090a0b0c0d0e0f1017181920212223242526272829303132" - "33343536373839401a1b1c1d1e1f202122232425262728293031323334353637"]} + {"bitcoin_auth", "authorize", ["1", "#0102030405060708090a0b0c0d0e0f101718192021222324252627282930313233343536373839401a1b1c1d1e1f202122232425262728293031323334353637"]}, + {"bitcoin_auth", "to_sign", ["#0102030405060708090a0b0c0d0e0f1017181920212223242526272829303132", "2"]} + ]. not_yet_compilable(fate) -> ["oracles", %% Oracle.register "events", - "basic_auth", %% auth_tx_hash instruction - "bitcoin_auth", %% fate_auth_tx_hash_instruction "address_literals", %% oracle_query_id literals "address_chain" %% Oracle.check_query ];