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 neighborhood nodes with Aqua.
aqua
aqua
Let's explain this script line by line. First of all, it brings builtin services (see aqua-lib) in scope by import:
aqua
aqua
Next it defines a function named ts_getter with two parameters: node which is peer id and num_peers which is how many neighbors to check.
That function returns array of obtained timestamps.
aqua
aqua
On the first line it creates stream variable (see CRDT Streams) res:
aqua
aqua
Then execution is transfered on peer with id that was passed in node (see on expression):
aqua
aqua
On node it obtains no more than num_peers neighbour nodes using builtin services:
aqua
aqua
After that for each of the obtained nodes in parallel (see Parallel for) it tries (see try) to push local timestamp to res:
aqua
aqua
Back on node element res[num_peers - 1] is joined (see join expression) thus making all results available:
aqua
aqua
Finally, stream is converted to scalar (see Streams Lifecycle) and returned:
aqua
aqua
See the ts-oracle example for the corresponding Aqua files in the aqua-script directory.
Now that we have our script, let's use Fluence CLI to run it:
- Run
- Result
sh
sh
Here we go. Ten timestamps in micro seconds obtained in parallel:
json
json
And that's it. We now have ten timestamps right from our selected peer's neighbors.
Note that if you try to request too many peers, execution could halt.