examples/aqua-examples/price-oracle/aqua/get_crypto_prices.aqua

64 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

import "@fluencelabs/aqua-lib/builtin.aqua"
2021-07-19 12:08:38 -05:00
data Result:
result: f64
success: bool
error_msg: string
service PriceGetterService:
price_getter(coin: string, currency: string, timestamp_ms: u64) -> Result
service MeanService:
mean(data: []f64) -> Result
service F64Op("op"):
identity(x:f64) -> f64
data Payload:
coin: string
currency: string
data NodeServicePair:
node: string
service_id: string
func get_price(coin: string, currency: string, node: string, pg_sid: string, mean_sid: string) -> Result:
prices: *f64
on node:
k <- Op.string_to_b58(node)
PriceGetterService pg_sid
MeanService mean_sid
ts_ms0 <- Peer.timestamp_ms()
res0 <- PriceGetterService.price_getter(coin, currency, ts_ms0)
-- if price.success:
prices <- F64Op.identity(res0.result)
ts_ms1 <- Peer.timestamp_ms()
res1 <- PriceGetterService.price_getter(coin, currency, ts_ms1)
-- if price.success:
prices <- F64Op.identity(res1.result)
result <- MeanService.mean(prices)
-- else:
-- logError("price_getter: ", price.error_msg)
<- result
2021-07-19 19:08:27 -05:00
func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result:
prices: *f64
for topo <- getter_topo par:
2021-10-20 12:11:53 +03:00
on topo.node:
2021-07-19 19:08:27 -05:00
PriceGetterService topo.service_id
ts_ms <- Peer.timestamp_ms()
res <- PriceGetterService.price_getter(coin, currency, ts_ms)
prices <- F64Op.identity(res.result)
2022-02-08 14:58:32 -06:00
Op.noop()
2021-07-19 19:08:27 -05:00
on mean_topo.node:
2021-10-20 12:11:53 +03:00
F64Op.identity(prices!1)
2021-07-19 19:08:27 -05:00
MeanService mean_topo.service_id
result <- MeanService.mean(prices)
<- result