Pt 166233685 fate oracles (#52)
* Introduce typereps * Use typereps for registering oracles * Add TTL to oracle register * Introduce oracle query object and ORACLE_QUERY operation * Stub the remaining oracle instructions * Adapt oracle respond and extend * Document oracle ops * Add unit tests for all oracle instructions
This commit is contained in:
@@ -112,8 +112,21 @@
|
||||
-define(OTYPE_SIGNATURE, 2).
|
||||
-define(OTYPE_CONTRACT, 3).
|
||||
-define(OTYPE_ORACLE, 4).
|
||||
-define(OTYPE_NAME, 5).
|
||||
-define(OTYPE_CHANNEL, 6).
|
||||
-define(OTYPE_ORACLE_Q, 5).
|
||||
-define(OTYPE_NAME, 6).
|
||||
-define(OTYPE_CHANNEL, 7).
|
||||
|
||||
-define(IS_TYPE_TAG(X), (X =:= ?TYPE_INTEGER orelse
|
||||
X =:= ?TYPE_BOOLEAN orelse
|
||||
X =:= ?TYPE_ANY orelse
|
||||
X =:= ?TYPE_VAR orelse
|
||||
X =:= ?TYPE_LIST orelse
|
||||
X =:= ?TYPE_TUPLE orelse
|
||||
X =:= ?TYPE_OBJECT orelse
|
||||
X =:= ?TYPE_BITS orelse
|
||||
X =:= ?TYPE_MAP orelse
|
||||
X =:= ?TYPE_STRING orelse
|
||||
X =:= ?TYPE_VARIANT)).
|
||||
|
||||
%% --------------------------------------------------
|
||||
%% Serialize
|
||||
@@ -150,6 +163,8 @@ serialize(?FATE_CONTRACT(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_CONTRACT, (aeser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_ORACLE(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_ORACLE, (aeser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_ORACLE_Q(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_ORACLE_Q, (aeser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_NAME(Address)) when is_binary(Address) ->
|
||||
<<?OBJECT, ?OTYPE_NAME, (aeser_rlp:encode(Address))/binary>>;
|
||||
serialize(?FATE_CHANNEL(Address)) when is_binary(Address) ->
|
||||
@@ -200,7 +215,9 @@ serialize(?FATE_VARIANT(Arities, Tag, Values)) ->
|
||||
(serialize(?FATE_TUPLE(Values)))/binary
|
||||
>>
|
||||
end
|
||||
end.
|
||||
end;
|
||||
serialize(?FATE_TYPEREP(T)) ->
|
||||
iolist_to_binary(serialize_type(T)).
|
||||
|
||||
|
||||
%% -----------------------------------------------------
|
||||
@@ -221,6 +238,7 @@ serialize_type(hash) -> [?TYPE_OBJECT, ?OTYPE_HASH];
|
||||
serialize_type(signature) -> [?TYPE_OBJECT, ?OTYPE_SIGNATURE];
|
||||
serialize_type(contract) -> [?TYPE_OBJECT, ?OTYPE_CONTRACT];
|
||||
serialize_type(oracle) -> [?TYPE_OBJECT, ?OTYPE_ORACLE];
|
||||
serialize_type(oracle_query)-> [?TYPE_OBJECT, ?OTYPE_ORACLE_Q];
|
||||
serialize_type(name) -> [?TYPE_OBJECT, ?OTYPE_NAME];
|
||||
serialize_type(channel) -> [?TYPE_OBJECT, ?OTYPE_CHANNEL];
|
||||
serialize_type(bits) -> [?TYPE_BITS];
|
||||
@@ -252,6 +270,7 @@ deserialize_type(<<?TYPE_OBJECT, ObjectType, Rest/binary>>) ->
|
||||
?OTYPE_SIGNATURE -> {signature, Rest};
|
||||
?OTYPE_CONTRACT -> {contract, Rest};
|
||||
?OTYPE_ORACLE -> {oracle, Rest};
|
||||
?OTYPE_ORACLE_Q -> {oracle_query, Rest};
|
||||
?OTYPE_NAME -> {name, Rest};
|
||||
?OTYPE_CHANNEL -> {channel, Rest}
|
||||
end;
|
||||
@@ -371,6 +390,7 @@ deserialize2(<<?OBJECT, ObjectType, Rest/binary>>) ->
|
||||
?OTYPE_SIGNATURE -> ?FATE_SIGNATURE(A);
|
||||
?OTYPE_CONTRACT -> ?FATE_CONTRACT(A);
|
||||
?OTYPE_ORACLE -> ?FATE_ORACLE(A);
|
||||
?OTYPE_ORACLE_Q -> ?FATE_ORACLE_Q(A);
|
||||
?OTYPE_NAME -> ?FATE_NAME(A);
|
||||
?OTYPE_CHANNEL -> ?FATE_CHANNEL(A)
|
||||
end,
|
||||
@@ -424,7 +444,10 @@ deserialize2(<<?VARIANT, Rest/binary>>) ->
|
||||
true ->
|
||||
{?FATE_VARIANT(Arities, Tag, T), Rest3}
|
||||
end
|
||||
end.
|
||||
end;
|
||||
deserialize2(<<TypeTag, _/binary>> = Bin) when ?IS_TYPE_TAG(TypeTag) ->
|
||||
{Type, Rest} = deserialize_type(Bin),
|
||||
{?FATE_TYPEREP(Type), Rest}.
|
||||
|
||||
insert_kv([]) -> [];
|
||||
insert_kv([K, V | R]) -> [{K, V} | insert_kv(R)].
|
||||
|
||||
Reference in New Issue
Block a user