Handle oracle operation in FATE
Keep oracle type information on fcode level Introduce typereps as values Handle oracle registration Handle oracle query object and oracle_query op Handle oracle get question Handle oracle query fee Handle oracle get answer Handle oracle respond Handle oracle extend
This commit is contained in:
parent
fc82b1646c
commit
301e6ff501
@ -2,7 +2,7 @@
|
||||
|
||||
{erl_opts, [debug_info]}.
|
||||
|
||||
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref, "506f9ca"}}}
|
||||
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"e321882"}}}
|
||||
, {getopt, "1.0.1"}
|
||||
, {jsx, {git, "https://github.com/talentdeficit/jsx.git",
|
||||
{tag, "2.8.0"}}}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{"1.1.0",
|
||||
[{<<"aebytecode">>,
|
||||
{git,"https://github.com/aeternity/aebytecode.git",
|
||||
{ref,"506f9ca72ea5df5fb2abd3aaddcbf9d58423e556"}},
|
||||
{ref,"e321882b9830eea5ce5ab8801e8b19fd350a4e00"}},
|
||||
0},
|
||||
{<<"aeserialization">>,
|
||||
{git,"https://github.com/aeternity/aeserialization.git",
|
||||
|
@ -43,7 +43,8 @@
|
||||
| {contract_pubkey, binary()}
|
||||
| {oracle_pubkey, binary()}
|
||||
| {oracle_query_id, binary()}
|
||||
| {bool, false | true}.
|
||||
| {bool, false | true}
|
||||
| {typerep, ftype()}.
|
||||
|
||||
-type fexpr() :: {lit, flit()}
|
||||
| nil
|
||||
@ -92,7 +93,7 @@
|
||||
| hash
|
||||
| signature
|
||||
| contract
|
||||
| oracle
|
||||
| {oracle, ftype(), ftype()} %% Query type, Response type
|
||||
| oracle_query
|
||||
| name
|
||||
| channel
|
||||
@ -212,7 +213,7 @@ init_type_env() ->
|
||||
["address"] => ?type(address),
|
||||
["hash"] => ?type(hash),
|
||||
["signature"] => ?type(signature),
|
||||
["oracle"] => ?type(_, _, oracle),
|
||||
["oracle"] => ?type(Q, R, {oracle, Q, R}),
|
||||
["oracle_query"] => ?type(_, _, oracle_query), %% TODO: not in Fate
|
||||
["list"] => ?type(T, {list, T}),
|
||||
["map"] => ?type(K, V, {map, K, V}),
|
||||
@ -472,10 +473,14 @@ expr_to_fcode(Env, _Type, {app, _Ann, {Op, _}, [A]}) when is_atom(Op) ->
|
||||
end;
|
||||
|
||||
%% Function calls
|
||||
expr_to_fcode(Env, _Type, {app, _Ann, Fun = {typed, _, _, {fun_t, _, NamedArgsT, _, _}}, Args}) ->
|
||||
expr_to_fcode(Env, Type, {app, _Ann, Fun = {typed, _, _, {fun_t, _, NamedArgsT, _, _}}, Args}) ->
|
||||
Args1 = get_named_args(NamedArgsT, Args),
|
||||
FArgs = [expr_to_fcode(Env, Arg) || Arg <- Args1],
|
||||
case expr_to_fcode(Env, Fun) of
|
||||
{builtin_u, oracle_register = B, _} ->
|
||||
{oracle, QType, RType} = type_to_fcode(Env, Type),
|
||||
TypeArgs = [{lit, {typerep, QType}}, {lit, {typerep, RType}}],
|
||||
builtin_to_fcode(B, FArgs ++ TypeArgs);
|
||||
{builtin_u, B, _Ar} -> builtin_to_fcode(B, FArgs);
|
||||
{def_u, F, _Ar} -> {def, F, FArgs};
|
||||
{remote_u, Ct, RFun, _Ar} -> {remote, Ct, RFun, FArgs};
|
||||
|
@ -164,7 +164,7 @@ type_to_scode(address) -> address;
|
||||
type_to_scode(hash) -> hash;
|
||||
type_to_scode(signature) -> signature;
|
||||
type_to_scode(contract) -> contract;
|
||||
type_to_scode(oracle) -> oracle;
|
||||
type_to_scode({oracle, _, _}) -> oracle;
|
||||
type_to_scode(oracle_query) -> oracle_query;
|
||||
type_to_scode(name) -> name;
|
||||
type_to_scode(channel) -> channel;
|
||||
@ -242,7 +242,8 @@ lit_to_fate(L) ->
|
||||
{account_pubkey, K} -> aeb_fate_data:make_address(K);
|
||||
{contract_pubkey, K} -> aeb_fate_data:make_contract(K);
|
||||
{oracle_pubkey, K} -> aeb_fate_data:make_oracle(K);
|
||||
{oracle_query_id, _} -> ?TODO(fate_oracle_query_id_value)
|
||||
{typerep, T} -> aeb_fate_data:make_typerep(type_to_scode(T));
|
||||
{oracle_query_id, H} -> aeb_fate_data:make_oracle_query(H)
|
||||
end.
|
||||
|
||||
term_to_fate({lit, L}) ->
|
||||
@ -504,20 +505,22 @@ builtin_to_scode(_Env, call_gas_price, []) ->
|
||||
[aeb_fate_ops:gasprice(?a)];
|
||||
builtin_to_scode(_Env, call_gas_left, []) ->
|
||||
[aeb_fate_ops:gas(?a)];
|
||||
builtin_to_scode(_Env, oracle_register, [_, _, _, _] = _Args) ->
|
||||
?TODO(fate_oracle_register_instruction);
|
||||
builtin_to_scode(_Env, oracle_query_fee, [_] = _Args) ->
|
||||
?TODO(fate_oracle_query_fee_instruction);
|
||||
builtin_to_scode(_Env, oracle_query, [_, _, _, _, _] = _Args) ->
|
||||
?TODO(fate_oracle_query_instruction);
|
||||
builtin_to_scode(_Env, oracle_get_question, [_, _] = _Args) ->
|
||||
?TODO(fate_oracle_get_question_instruction);
|
||||
builtin_to_scode(_Env, oracle_respond, [_, _, _, _] = _Args) ->
|
||||
?TODO(fate_oracle_respond_instruction);
|
||||
builtin_to_scode(_Env, oracle_extend, [_, _, _] = _Args) ->
|
||||
?TODO(fate_oracle_extend_instruction);
|
||||
builtin_to_scode(_Env, oracle_get_answer, [_, _] = _Args) ->
|
||||
?TODO(fate_oracle_get_answer_instruction);
|
||||
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_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] = Args) ->
|
||||
call_to_scode(Env, aeb_fate_ops:oracle_query(?a, ?a, ?a, ?a, ?a, ?a), Args);
|
||||
builtin_to_scode(Env, oracle_get_question, [_Oracle, _QueryId] = Args) ->
|
||||
call_to_scode(Env, aeb_fate_ops:oracle_get_question(?a, ?a, ?a), Args);
|
||||
builtin_to_scode(Env, oracle_respond, [_Sign, _Oracle, _QueryId, _Response] = Args) ->
|
||||
call_to_scode(Env, [aeb_fate_ops:oracle_respond(?a, ?a, ?a, ?a),
|
||||
tuple(0)], Args);
|
||||
builtin_to_scode(Env, oracle_extend, [_Sign, _Oracle, _TTL] = Args) ->
|
||||
call_to_scode(Env, [aeb_fate_ops:oracle_extend(?a, ?a, ?a),
|
||||
tuple(0)], Args);
|
||||
builtin_to_scode(Env, oracle_get_answer, [_Oracle, _QueryId] = Args) ->
|
||||
call_to_scode(Env, aeb_fate_ops:oracle_get_answer(?a, ?a, ?a), Args);
|
||||
builtin_to_scode(_Env, aens_resolve, [_, _] = _Args) ->
|
||||
?TODO(fate_aens_resolve_instruction);
|
||||
builtin_to_scode(_Env, aens_preclaim, [_, _, _] = _Args) ->
|
||||
@ -823,13 +826,13 @@ attributes(I) ->
|
||||
'DEACTIVATE' -> Impure(none, []);
|
||||
{'SPEND', A, B} -> Impure(none, [A, B]);
|
||||
|
||||
{'ORACLE_REGISTER', A, B, C, D, E, F} -> Impure(A, [B, C, D, E, F]);
|
||||
'ORACLE_QUERY' -> Impure(?a, []); %% TODO
|
||||
'ORACLE_RESPOND' -> Impure(?a, []); %% TODO
|
||||
'ORACLE_EXTEND' -> Impure(?a, []); %% TODO
|
||||
'ORACLE_GET_ANSWER' -> Impure(?a, []); %% TODO
|
||||
'ORACLE_GET_QUESTION' -> Impure(?a, []); %% TODO
|
||||
'ORACLE_QUERY_FEE' -> Impure(?a, []); %% TODO
|
||||
{'ORACLE_REGISTER', A, B, C, D, E, F, G} -> Impure(A, [B, C, D, E, F, G]);
|
||||
{'ORACLE_QUERY', A, B, C, D, E, F} -> Impure(A, [B, C, D, E, F]);
|
||||
{'ORACLE_RESPOND', A, B, C, D} -> Impure(none, [A, B, C, D]);
|
||||
{'ORACLE_EXTEND', A, B, C} -> Impure(none, [A, B, C]);
|
||||
{'ORACLE_GET_ANSWER', A, B, C} -> Impure(A, [B, C]);
|
||||
{'ORACLE_GET_QUESTION', A, B, C} -> Impure(A, [B, C]);
|
||||
{'ORACLE_QUERY_FEE', A, B} -> Impure(A, [B]);
|
||||
'AENS_RESOLVE' -> Impure(?a, []); %% TODO
|
||||
'AENS_PRECLAIM' -> Impure(?a, []); %% TODO
|
||||
'AENS_CLAIM' -> Impure(?a, []); %% TODO
|
||||
|
@ -118,8 +118,7 @@ compilable_contracts() ->
|
||||
].
|
||||
|
||||
not_yet_compilable(fate) ->
|
||||
["oracles", %% Oracle.register
|
||||
"events", %% events
|
||||
["events", %% events
|
||||
"address_literals", %% oracle_query_id literals
|
||||
"address_chain" %% Oracle.check_query
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user