Quick Start
Every Fluence reference node comes with a set of builtin services that are accessible to Aqua programs. Let's use those readily available services to get the timestamp of a few of our peer-to-peer neighbourhood nodes with Aqua.
Timestamps With Aqua
1
-- timestamp_getter.aqua
2
-- bring the builtin services into scope
3
import "builtin.aqua"
4
​
5
-- create an identity service to join our results
6
service Op2("op"):
7
identity(s: u64)
8
array(a: string, b: u64) -> string
9
​
10
-- function to get ten timestamps from our Kademlia
11
-- neighborhood peers and return as an array of u64 timestamps
12
-- the function arguement node is our peer id
13
func ts_getter(node: string) -> []u64:
14
-- create a streaming variable
15
res: *u64
16
-- execute on the pecified peer
17
on node:
18
-- get the base58 representation of the peer id
19
k <- Op.string_to_b58(node)
20
-- find all (default 20) neighborhood peers from k
21
nodes <- Kademlia.neighborhood(k, nil, nil)
22
-- for each peer in our neighborhood and in parallel
23
for n <- nodes par:
24
on n:
25
-- try and get the peer's timestamp
26
try:
27
res <- Peer.timestamp_ms()
28
-- flatten nine of our joined results
29
Op2.identity(res!9)
30
-- return an array of ten timestamps
31
<- res
Copied!
The Aqua script essentially creates a workflow originating from our client peer to enumerate neighbor peers for our reference node, calls on the builtin timestamp service on each peer in parallel, joins the results stream after we collect ten timestamps and return our u64 array of timestamps back to the client peer.
See the ts-oracle example for the corresponding Aqua files in the aqua-script directory. Now that we have our script, let's compile it with the aqua-cli tool and find our AIR file in the air-scripts directory:
Compile
Result
1
aqua -i aqua-scripts -o air-scripts -a
Copied!
1
# in the air-script dir you should have the following file
2
timestamp_getter.ts_getter.air
Copied!
Once we have our AIR file we can either use a Typescript or command line client. Let's use the command line client flidstsee third tab for installation instructions, if needed:
Run Air scripts
Result
Installing fldist
1
# execute the AIR script from our compile phase with a peer id
2
fldist run_air -p air-scripts/timestamp_getter.ts_getter.air -d '{"node":"12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf"}' --generated
Copied!
1
# here we go: ten timestamps in micro seconds obtained in parallel
2
[
3
[
4
1624928596292,
5
1624928596291,
6
1624928596291,
7
1624928596299,
8
1624928596295,
9
1624928596286,
10
1624928596295,
11
1624928596284,
12
1624928596293,
13
1624928596289
14
]
15
]
Copied!
1
# if you don't have fldist on your machine:
2
npm -g install @fluencelabs/fldist
Copied!
And that's it. We now have ten timestamps right from our selected peer's neighbors.
Last modified 25d ago
Copy link