From e9505e240f9597b99f1ca9c775f9c3de9cb87815 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Thu, 15 Aug 2019 13:57:24 +0200 Subject: [PATCH] Add Address.is_payable(address) --- src/aeso_ast_infer_types.erl | 3 ++- src/aeso_ast_to_fcode.erl | 2 +- src/aeso_ast_to_icode.erl | 3 +++ src/aeso_fcode_to_fate.erl | 4 ++++ test/contracts/address_chain.aes | 3 +++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 2bd79fa..e640c49 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -504,7 +504,8 @@ global_env() -> IntScope = #scope{ funs = MkDefs([{"to_str", Fun1(Int, String)}]) }, AddressScope = #scope{ funs = MkDefs([{"to_str", Fun1(Address, String)}, {"is_oracle", Fun1(Address, Bool)}, - {"is_contract", Fun1(Address, Bool)}]) }, + {"is_contract", Fun1(Address, Bool)}, + {"is_payable", Fun1(Address, Bool)}]) }, #env{ scopes = #{ [] => TopScope diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 95af46a..91c4dcb 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -197,7 +197,7 @@ builtins() -> {"union", 2}, {"difference", 2}, {"none", none}, {"all", none}]}, {["Bytes"], [{"to_int", 1}, {"to_str", 1}]}, {["Int"], [{"to_str", 1}]}, - {["Address"], [{"to_str", 1}, {"is_oracle", 1}, {"is_contract", 1}]} + {["Address"], [{"to_str", 1}, {"is_oracle", 1}, {"is_contract", 1}, {"is_payable", 1}]} ], maps:from_list([ {NS ++ [Fun], {MkName(NS, Fun), Arity}} || {NS, Funs} <- Scopes, diff --git a/src/aeso_ast_to_icode.erl b/src/aeso_ast_to_icode.erl index febd4c2..184275b 100644 --- a/src/aeso_ast_to_icode.erl +++ b/src/aeso_ast_to_icode.erl @@ -433,6 +433,9 @@ ast_body(?qid_app(["Address", "is_oracle"], [Addr], _, _), Icode) -> ast_body(?qid_app(["Address", "is_contract"], [Addr], _, _), Icode) -> prim_call(?PRIM_CALL_ADDR_IS_CONTRACT, #integer{value = 0}, [ast_body(Addr, Icode)], [word], word); +ast_body(?qid_app(["Address", "is_payable"], [Addr], _, _), Icode) -> + prim_call(?PRIM_CALL_ADDR_IS_PAYABLE, #integer{value = 0}, + [ast_body(Addr, Icode)], [word], word); ast_body(?qid_app(["Bytes", "to_int"], [Bytes], _, _), Icode) -> {typed, _, _, {bytes_t, _, N}} = Bytes, diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index d782dba..e735678 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -109,6 +109,7 @@ Op =:= 'ORACLE_CHECK_QUERY' orelse Op =:= 'IS_ORACLE' orelse Op =:= 'IS_CONTRACT' orelse + Op =:= 'IS_PAYABLE' orelse Op =:= 'CREATOR' orelse false)). @@ -543,6 +544,8 @@ builtin_to_scode(Env, address_is_oracle, [_] = Args) -> call_to_scode(Env, aeb_fate_ops:is_oracle(?a, ?a), Args); builtin_to_scode(Env, address_is_contract, [_] = Args) -> call_to_scode(Env, aeb_fate_ops:is_contract(?a, ?a), Args); +builtin_to_scode(Env, address_is_payable, [_] = Args) -> + call_to_scode(Env, aeb_fate_ops:is_payable(?a, ?a), Args); builtin_to_scode(Env, aens_resolve, [_Name, _Key, _Type] = Args) -> call_to_scode(Env, aeb_fate_ops:aens_resolve(?a, ?a, ?a, ?a), Args); builtin_to_scode(Env, aens_preclaim, [_Sign, _Account, _Hash] = Args) -> @@ -836,6 +839,7 @@ attributes(I) -> {'ORACLE_CHECK_QUERY', A, B, C, D, E} -> Impure(A, [B, C, D, E]); {'IS_ORACLE', A, B} -> Impure(A, [B]); {'IS_CONTRACT', A, B} -> Impure(A, [B]); + {'IS_PAYABLE', A, B} -> Impure(A, [B]); {'CREATOR', A} -> Pure(A, []); {'ADDRESS', A} -> Pure(A, []); {'BALANCE', A} -> Impure(A, []); diff --git a/test/contracts/address_chain.aes b/test/contracts/address_chain.aes index e8edccf..4c55a45 100644 --- a/test/contracts/address_chain.aes +++ b/test/contracts/address_chain.aes @@ -31,3 +31,6 @@ contract AddrChain = entrypoint c_creator() : address = Contract.creator + + entrypoint is_payable(a : address) : bool = + Address.is_payable(a)