From 760d2841d1bb5664ce75d9757ca18682901d00eb Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 3 Feb 2020 12:22:34 +0100 Subject: [PATCH 1/4] From Iris (with AENS.update) AENS.resolve is not Pure --- src/aeso_fcode_to_fate.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index ddb15eb..66c2a1a 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -880,7 +880,7 @@ attributes(I) -> {'ORACLE_GET_ANSWER', A, B, C, D, E} -> Pure(A, [B, C, D, E]); {'ORACLE_GET_QUESTION', A, B, C, D, E}-> Pure(A, [B, C, D, E]); {'ORACLE_QUERY_FEE', A, B} -> Pure(A, [B]); - {'AENS_RESOLVE', A, B, C, D} -> Pure(A, [B, C, D]); + {'AENS_RESOLVE', A, B, C, D} -> Impure(A, [B, C, D]); {'AENS_PRECLAIM', A, B, C} -> Impure(none, [A, B, C]); {'AENS_CLAIM', A, B, C, D, E} -> Impure(none, [A, B, C, D, E]); {'AENS_UPDATE', A, B, C, D, E, F} -> Impure(none, [A, B, C, D, E, F]); From db01e237c1893fa237b7d2cc265b79707a014ad0 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 3 Feb 2020 12:24:27 +0100 Subject: [PATCH 2/4] Add Oracle.expiry --- src/aeso_ast_infer_types.erl | 1 + src/aeso_ast_to_fcode.erl | 2 +- src/aeso_fcode_to_fate.erl | 3 +++ test/contracts/channel_on_chain_contract_oracle.aes | 7 +++++-- test/contracts/unapplied_builtins.aes | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index c2d1498..5ee5641 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -459,6 +459,7 @@ global_env() -> OracleScope = #scope { funs = MkDefs( [{"register", SignFun([Address, Fee, TTL], Oracle(Q, R))}, + {"expiry", Fun([Oracle(Q, R)], Fee)}, {"query_fee", Fun([Oracle(Q, R)], Fee)}, {"query", StateFun([Oracle(Q, R), Q, Fee, TTL, TTL], Query(Q, R))}, {"get_question", Fun([Oracle(Q, R), Query(Q, R)], Q)}, diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 3f360d0..bd4c539 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -204,7 +204,7 @@ builtins() -> {["Contract"], [{"address", none}, {"balance", none}, {"creator", none}]}, {["Call"], [{"origin", none}, {"caller", none}, {"value", none}, {"gas_price", none}, {"gas_left", 0}]}, - {["Oracle"], [{"register", 4}, {"query_fee", 1}, {"query", 5}, {"get_question", 2}, + {["Oracle"], [{"register", 4}, {"expiry", 1}, {"query_fee", 1}, {"query", 5}, {"get_question", 2}, {"respond", 4}, {"extend", 3}, {"get_answer", 2}, {"check", 1}, {"check_query", 2}]}, {["AENS"], [{"resolve", 2}, {"preclaim", 3}, {"claim", 5}, {"transfer", 4}, diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 66c2a1a..181c945 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -498,6 +498,8 @@ builtin_to_scode(_Env, call_gas_left, []) -> [aeb_fate_ops:gas(?a)]; builtin_to_scode(Env, oracle_register, [_Sign,_Account,_QFee,_TTL,_QType,_RType] = Args) -> call_to_scode(Env, aeb_fate_ops:oracle_register(?a, ?a, ?a, ?a, ?a, ?a, ?a), Args); +builtin_to_scode(Env, oracle_expiry, [_Oracle] = Args) -> + call_to_scode(Env, aeb_fate_ops:oracle_expiry(?a, ?a), Args); builtin_to_scode(Env, oracle_query_fee, [_Oracle] = Args) -> call_to_scode(Env, aeb_fate_ops:oracle_query_fee(?a, ?a), Args); builtin_to_scode(Env, oracle_query, [_Oracle, _Question, _QFee, _QTTL, _RTTL, _QType, _RType] = Args) -> @@ -880,6 +882,7 @@ attributes(I) -> {'ORACLE_GET_ANSWER', A, B, C, D, E} -> Pure(A, [B, C, D, E]); {'ORACLE_GET_QUESTION', A, B, C, D, E}-> Pure(A, [B, C, D, E]); {'ORACLE_QUERY_FEE', A, B} -> Pure(A, [B]); + {'ORACLE_EXPIRY', A, B} -> Impure(A, [B]); {'AENS_RESOLVE', A, B, C, D} -> Impure(A, [B, C, D]); {'AENS_PRECLAIM', A, B, C} -> Impure(none, [A, B, C]); {'AENS_CLAIM', A, B, C, D, E} -> Impure(none, [A, B, C, D, E]); diff --git a/test/contracts/channel_on_chain_contract_oracle.aes b/test/contracts/channel_on_chain_contract_oracle.aes index d62ab41..de681aa 100644 --- a/test/contracts/channel_on_chain_contract_oracle.aes +++ b/test/contracts/channel_on_chain_contract_oracle.aes @@ -17,7 +17,7 @@ contract ChannelOnChainContractOracle = bets = {} } - public stateful function place_bet(answer: string) = + public stateful function place_bet(answer: string) = switch(Map.lookup(answer, state.bets)) None => put(state{ bets = state.bets{[answer] = Call.caller}}) @@ -25,6 +25,9 @@ contract ChannelOnChainContractOracle = Some(_value) => "bet_already_taken" + public function expiry() = + Oracle.expiry(state.oracle) + public function query_fee() = Oracle.query_fee(state.oracle) @@ -35,7 +38,7 @@ contract ChannelOnChainContractOracle = switch(Oracle.get_answer(state.oracle, q)) None => "no response" - Some(result) => + Some(result) => if(state.question == Oracle.get_question(state.oracle, q)) switch(Map.lookup(result, state.bets)) None => diff --git a/test/contracts/unapplied_builtins.aes b/test/contracts/unapplied_builtins.aes index 6055a87..3d3bb39 100644 --- a/test/contracts/unapplied_builtins.aes +++ b/test/contracts/unapplied_builtins.aes @@ -21,6 +21,7 @@ contract UnappliedBuiltins = function b_abort() = abort function b_require() = require function oracle_query_fee() = Oracle.query_fee + function oracle_expiry() = Oracle.expiry stateful function oracle_query() = Oracle.query : (o, _, _, _, _) => _ function oracle_get_question() = Oracle.get_question : (o, _) => _ function oracle_get_answer() = Oracle.get_answer : (o, _) => _ From c3426f0e65aa91d5f3f9b3fe0ea2f82895cfeca4 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 3 Feb 2020 12:52:00 +0100 Subject: [PATCH 3/4] Add AENS.lookup Also move Pointee-constructors inside AENS namespace. --- src/aeso_ast_infer_types.erl | 18 ++++++++++++------ src/aeso_ast_to_fcode.erl | 21 ++++++++++++--------- src/aeso_fcode_to_fate.erl | 3 +++ test/aeso_compiler_tests.erl | 3 ++- test/contracts/aens_update.aes | 17 +++++++++++++++++ 5 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 test/contracts/aens_update.aes diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 5ee5641..802614c 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -390,6 +390,7 @@ global_env() -> SignFun = fun(Ts, T) -> {type_sig, [stateful|Ann], none, [Signature], Ts, T} end, TTL = {qid, Ann, ["Chain", "ttl"]}, Pointee = {qid, Ann, ["AENS", "pointee"]}, + AENSName = {qid, Ann, ["AENS", "name"]}, Fr = {qid, Ann, ["MCL_BLS12_381", "fr"]}, Fp = {qid, Ann, ["MCL_BLS12_381", "fp"]}, Fp2 = {tuple_t, Ann, [Fp, Fp]}, @@ -410,10 +411,6 @@ global_env() -> %% TTL constructors {"RelativeTTL", Fun1(Int, TTL)}, {"FixedTTL", Fun1(Int, TTL)}, - %% AENS pointee constructors - {"AccountPointee", Fun1(Address, Pointee)}, - {"OraclePointee", Fun1(Address, Pointee)}, - {"ContractPointee", Fun1(Address, Pointee)}, %% Abort {"abort", Fun1(String, A)}, {"require", Fun([Bool, String], Unit)}]) @@ -476,8 +473,17 @@ global_env() -> {"claim", SignFun([Address, String, Int, Int], Unit)}, {"transfer", SignFun([Address, Address, String], Unit)}, {"revoke", SignFun([Address, String], Unit)}, - {"update", SignFun([Address, String, Option(TTL), Option(Int), Option(Map(String, Pointee))], Unit)}]) - , types = MkDefs([{"pointee", 0}]) }, + {"update", SignFun([Address, String, Option(TTL), Option(Int), Option(Map(String, Pointee))], Unit)}, + {"lookup", Fun([String], option_t(Ann, AENSName))}, + %% AENS pointee constructors + {"AccountPt", Fun1(Address, Pointee)}, + {"OraclePt", Fun1(Address, Pointee)}, + {"ContractPt", Fun1(Address, Pointee)}, + {"ChannelPt", Fun1(Address, Pointee)}, + %% Name object constructor + {"Name", Fun([Address, TTL, Map(String, Pointee)], AENSName)} + ]) + , types = MkDefs([{"pointee", 0}, {"name", 0}]) }, MapScope = #scope { funs = MkDefs( diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index bd4c539..d4c1f0d 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -181,13 +181,15 @@ init_env(Options) -> #{ type_env => init_type_env(), fun_env => #{}, builtins => builtins(), - con_env => #{["None"] => #con_tag{ tag = 0, arities = [0, 1] }, - ["Some"] => #con_tag{ tag = 1, arities = [0, 1] }, - ["RelativeTTL"] => #con_tag{ tag = 0, arities = [1, 1] }, - ["FixedTTL"] => #con_tag{ tag = 1, arities = [1, 1] }, - ["AccountPointee"] => #con_tag{ tag = 0, arities = [1, 1, 1] }, - ["OraclePointee"] => #con_tag{ tag = 1, arities = [1, 1, 1] }, - ["ContractPointee"] => #con_tag{ tag = 2, arities = [1, 1, 1] } + con_env => #{["None"] => #con_tag{ tag = 0, arities = [0, 1] }, + ["Some"] => #con_tag{ tag = 1, arities = [0, 1] }, + ["RelativeTTL"] => #con_tag{ tag = 0, arities = [1, 1] }, + ["FixedTTL"] => #con_tag{ tag = 1, arities = [1, 1] }, + ["AENS", "AccountPt"] => #con_tag{ tag = 0, arities = [1, 1, 1, 1] }, + ["AENS", "OraclePt"] => #con_tag{ tag = 1, arities = [1, 1, 1, 1] }, + ["AENS", "ContractPt"] => #con_tag{ tag = 2, arities = [1, 1, 1, 1] }, + ["AENS", "ChannelPt"] => #con_tag{ tag = 3, arities = [1, 1, 1, 1] }, + ["AENS", "Name"] => #con_tag{ tag = 0, arities = [3] } }, options => Options, functions => #{} }. @@ -208,7 +210,7 @@ builtins() -> {"respond", 4}, {"extend", 3}, {"get_answer", 2}, {"check", 1}, {"check_query", 2}]}, {["AENS"], [{"resolve", 2}, {"preclaim", 3}, {"claim", 5}, {"transfer", 4}, - {"revoke", 3}, {"update", 6}]}, + {"revoke", 3}, {"update", 6}, {"lookup", 1}]}, {["Map"], [{"from_list", 1}, {"to_list", 1}, {"lookup", 2}, {"lookup_default", 3}, {"delete", 2}, {"member", 2}, {"size", 1}]}, {["Crypto"], [{"verify_sig", 3}, {"verify_sig_secp256k1", 3}, @@ -253,7 +255,8 @@ init_type_env() -> ["map"] => ?type(K, V, {map, K, V}), ["option"] => ?type(T, {variant, [[], [T]]}), ["Chain", "ttl"] => ?type({variant, [[integer], [integer]]}), - ["AENS", "pointee"] => ?type({variant, [[address], [address], [address]]}), + ["AENS", "pointee"] => ?type({variant, [[address], [address], [address], [address]]}), + ["AENS", "name"] => ?type({variant, [[address, {variant, [[integer], [integer]]}, {map, string, {variant, [[address], [address], [address], [address]]}}]]}), ["MCL_BLS12_381", "fr"] => ?type({bytes, 32}), ["MCL_BLS12_381", "fp"] => ?type({bytes, 48}) }. diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 181c945..70cac15 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -541,6 +541,8 @@ builtin_to_scode(Env, aens_revoke, [_Sign, _Account, _Name] = Args) -> builtin_to_scode(Env, aens_update, [_Sign, _Account, _NameString, _TTL, _ClientTTL, _Pointers] = Args) -> call_to_scode(Env, [aeb_fate_ops:aens_update(?a, ?a, ?a, ?a, ?a, ?a), tuple(0)], Args); +builtin_to_scode(Env, aens_lookup, [_Name] = Args) -> + call_to_scode(Env, aeb_fate_ops:aens_lookup(?a, ?a), Args); builtin_to_scode(_Env, auth_tx_hash, []) -> [aeb_fate_ops:auth_tx_hash(?a)]. @@ -889,6 +891,7 @@ attributes(I) -> {'AENS_UPDATE', A, B, C, D, E, F} -> Impure(none, [A, B, C, D, E, F]); {'AENS_TRANSFER', A, B, C, D} -> Impure(none, [A, B, C, D]); {'AENS_REVOKE', A, B, C} -> Impure(none, [A, B, C]); + {'AENS_LOOKUP', A, B} -> Impure(A, [B]); {'BLS12_381_G1_NEG', A, B} -> Pure(A, [B]); {'BLS12_381_G1_NORM', A, B} -> Pure(A, [B]); {'BLS12_381_G1_VALID', A, B} -> Pure(A, [B]); diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index ea27c67..2e610b0 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -154,6 +154,7 @@ compilable_contracts() -> "bytes_to_x", "bytes_concat", "aens", + "aens_update", "tuple_match", "cyclic_include", "stdlib_include", @@ -170,7 +171,7 @@ compilable_contracts() -> ]. not_yet_compilable(fate) -> []; -not_yet_compilable(aevm) -> ["pairing_crypto"]. +not_yet_compilable(aevm) -> ["pairing_crypto", "aens_update"]. %% Contracts that should produce type errors diff --git a/test/contracts/aens_update.aes b/test/contracts/aens_update.aes new file mode 100644 index 0000000..5d65229 --- /dev/null +++ b/test/contracts/aens_update.aes @@ -0,0 +1,17 @@ +contract AENSUpdate = + stateful entrypoint update_name(owner : address, name : string) = + let p1 : AENS.pointee = AENS.AccountPt(Call.caller) + let p2 : AENS.pointee = AENS.OraclePt(Call.caller) + let p3 : AENS.pointee = AENS.ContractPt(Call.caller) + let p4 : AENS.pointee = AENS.ChannelPt(Call.caller) + AENS.update(owner, name, None, None, + Some({ ["account_pubkey"] = p1, ["oracle_pubkey"] = p2, + ["contract_pubkey"] = p3, ["misc"] = p4 })) + + entrypoint get_ttl(name : string) = + switch(AENS.lookup(name)) + Some(AENS.Name(_, FixedTTL(ttl), _)) => ttl + + entrypoint expiry(o : oracle(int, int)) : int = + Oracle.expiry(o) + From bb79e7dd89c3cd0c05bae33185967c7579a1891c Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 3 Feb 2020 13:32:16 +0100 Subject: [PATCH 4/4] Update aebytecode reference --- rebar.config | 2 +- rebar.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index ba09c46..eb173a0 100644 --- a/rebar.config +++ b/rebar.config @@ -2,7 +2,7 @@ {erl_opts, [debug_info]}. -{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"e4b09d7"}}} +{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"8a9c9de"}}} , {getopt, "1.0.1"} , {eblake2, "1.0.0"} , {jsx, {git, "https://github.com/talentdeficit/jsx.git", diff --git a/rebar.lock b/rebar.lock index 0395056..9b84603 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,7 @@ {"1.1.0", [{<<"aebytecode">>, {git,"https://github.com/aeternity/aebytecode.git", - {ref,"e4b09d7c5c85030636b3b88df7dd9f89f3d1e2cb"}}, + {ref,"8a9c9dec956b1d2322b38490b2759e53a91affab"}}, 0}, {<<"aeserialization">>, {git,"https://github.com/aeternity/aeserialization.git",