mirror of
https://github.com/fluencelabs/examples
synced 2025-04-25 10:42:16 +00:00
add annotated Aqua example
This commit is contained in:
parent
cac82e8a8a
commit
a3b3050e8b
48
ts-oracle/air-scripts/timestamp_getter.ts_getter.air
Normal file
48
ts-oracle/air-scripts/timestamp_getter.ts_getter.air
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call node ("op" "string_to_b58") [node] k)
|
||||||
|
(call node ("kad" "neighborhood") [k false] nodes)
|
||||||
|
)
|
||||||
|
(fold nodes n
|
||||||
|
(par
|
||||||
|
(seq
|
||||||
|
(xor
|
||||||
|
(call n ("peer" "timestamp_ms") [] $res)
|
||||||
|
(null)
|
||||||
|
)
|
||||||
|
(call node ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(next n)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call node ("op" "identity") [$res.$.[9]!])
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call -relay- ("op" "noop") [])
|
||||||
|
)
|
||||||
|
(xor
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||||
|
)
|
28
ts-oracle/aqua-scripts/timestamp_getter.aqua
Normal file
28
ts-oracle/aqua-scripts/timestamp_getter.aqua
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import "builtin.aqua"
|
||||||
|
-- create and identity service to join our results
|
||||||
|
service Op2("op"):
|
||||||
|
identity(s: u64)
|
||||||
|
array(a: string, b: u64) -> string
|
||||||
|
|
||||||
|
-- function to get ten timestamps from our Kademlia
|
||||||
|
-- neighborhood and return as an array of u64 timestamps
|
||||||
|
-- the function arguement node is our per id
|
||||||
|
func ts_getter(node: string) -> []u64:
|
||||||
|
-- create a streaming variable
|
||||||
|
res: *u64
|
||||||
|
-- execute on the pecified peer
|
||||||
|
on node:
|
||||||
|
-- get the base58 representation of the peer id
|
||||||
|
k <- Op.string_to_b58(node)
|
||||||
|
-- find all (default 20) neighborhood peers from k
|
||||||
|
nodes <- Kademlia.neighborhood(k, false)
|
||||||
|
-- for each peer in our neighborhood and in parallel
|
||||||
|
for n <- nodes par:
|
||||||
|
on n:
|
||||||
|
-- try and get the peer's timestamp
|
||||||
|
try:
|
||||||
|
res <- Peer.timestamp_ms()
|
||||||
|
-- flatten nine of our joined results
|
||||||
|
Op2.identity(res!9)
|
||||||
|
-- return an array of ten timestamps
|
||||||
|
<- res
|
Loading…
x
Reference in New Issue
Block a user