-
Notifications
You must be signed in to change notification settings - Fork 22
/
ExchangeOracle.aes
37 lines (28 loc) · 1.67 KB
/
ExchangeOracle.aes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@compiler >= 6
contract ExchangeOracle =
record state =
{ exchange_oracle : oracle(string, int)
, oracle_fee : int }
type query_type = string
type answer_type = int
type query_id = oracle_query(query_type, answer_type)
type oracle_id = oracle(query_type, answer_type)
stateful entrypoint init(query_fee: int, ttl: int) : state =
require(query_fee > 0 , "Qfee must be passed as an argument and should be greater than zero")
require(ttl > 0 , "TTL must be passed as an argument and should be greater than zero")
let exchange_oracle': oracle(string, int) = register_oracle(query_fee,ttl)
{ exchange_oracle = exchange_oracle', oracle_fee = query_fee }
stateful function register_oracle(query_fee: int, ttl: int) : oracle_id =
require(query_fee > 0, "The fee is too low")
require(ttl > 0, "The ttl must be greater than zero")
Oracle.register(Contract.address, query_fee, RelativeTTL(ttl))
entrypoint get_oracle() : oracle_id = state.exchange_oracle
stateful entrypoint respond_to_question(query_id: query_id, response: int) =
Oracle.respond(state.exchange_oracle, query_id, response)
stateful entrypoint create_query(question: query_type, query_fee: int, query_ttl: int, relative_ttl: int) : query_id =
require(question != "", "The question can't be empty")
require(query_fee > state.oracle_fee, "The fee is too low")
require(query_ttl > 0 && relative_ttl > 0, "The TTL params must be greater than zero")
Oracle.query(state.exchange_oracle, question, query_fee, RelativeTTL(query_ttl), RelativeTTL(relative_ttl))
entrypoint get_question(query_id: query_id) : string =
Oracle.get_question(state.exchange_oracle, query_id)