From fe05f8542d39c4c3ee8e0e05d825291441ee4ddd Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:40:28 +0200 Subject: [PATCH] update join --- .../ts-oracle/aqua/timestamp_getter.aqua | 28 ------------------- aqua-examples/ts-oracle/aqua/ts_getter.aqua | 12 ++++---- 2 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 aqua-examples/ts-oracle/aqua/timestamp_getter.aqua diff --git a/aqua-examples/ts-oracle/aqua/timestamp_getter.aqua b/aqua-examples/ts-oracle/aqua/timestamp_getter.aqua deleted file mode 100644 index b78a1de..0000000 --- a/aqua-examples/ts-oracle/aqua/timestamp_getter.aqua +++ /dev/null @@ -1,28 +0,0 @@ -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, nil, nil) - -- 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 diff --git a/aqua-examples/ts-oracle/aqua/ts_getter.aqua b/aqua-examples/ts-oracle/aqua/ts_getter.aqua index 39603e8..4d545bd 100644 --- a/aqua-examples/ts-oracle/aqua/ts_getter.aqua +++ b/aqua-examples/ts-oracle/aqua/ts_getter.aqua @@ -20,16 +20,16 @@ func ts_getter(node: string) -> []u64: on node: k <- Op.string_to_b58(node) nodes <- Kademlia.neighborhood(k, nil, nil) - for n <- nodes par: - on n: - try: - res <- Peer.timestamp_ms() - Op2.identity(res!9) + if Op.array_length(nodes) > 0: + for n <- nodes par: + on n: + try: + res <- Peer.timestamp_ms() + join res[9] <- res func ts_oracle(node: string, oracle_service_id: string, min_points:u32) -> Oracle: res <- ts_getter(node) - on node: TSOracle oracle_service_id oracle <- TSOracle.point_estimate(res, min_points)