mirror of
https://github.com/fluencelabs/examples
synced 2025-06-15 19:11:21 +00:00
update code to match latest aqua
This commit is contained in:
@ -1,8 +1,5 @@
|
|||||||
alias PeerId : string
|
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||||
alias Base58String : string
|
|
||||||
alias Hash : string
|
|
||||||
|
|
||||||
-- const N_KNEIGHBORS = 19
|
|
||||||
|
|
||||||
data Contact:
|
data Contact:
|
||||||
peer_id: string
|
peer_id: string
|
||||||
@ -11,11 +8,6 @@ data Contact:
|
|||||||
data Info:
|
data Info:
|
||||||
external_addresses: []string
|
external_addresses: []string
|
||||||
|
|
||||||
service Op("op"):
|
|
||||||
noop()
|
|
||||||
string_to_b58(s: string) -> Base58String
|
|
||||||
concat_strings(a: string, b: string) -> string
|
|
||||||
|
|
||||||
service MyOp("op"):
|
service MyOp("op"):
|
||||||
identity(u: u64)
|
identity(u: u64)
|
||||||
identity_string(s:string)
|
identity_string(s:string)
|
||||||
@ -23,18 +15,6 @@ service MyOp("op"):
|
|||||||
service MyOpBool("op"):
|
service MyOpBool("op"):
|
||||||
identity(b: bool)
|
identity(b: bool)
|
||||||
|
|
||||||
service Kademlia("kad"):
|
|
||||||
neighborhood(key: Base58String, already_hashed: ?bool, count: ?u32) -> []PeerId
|
|
||||||
merge(target: Base58String, left: []string, right: []string, count: ?u32) -> []string
|
|
||||||
|
|
||||||
service Peer("peer"):
|
|
||||||
is_connected(peer: PeerId) -> bool
|
|
||||||
connect(id: PeerId, multiaddrs: ?[]string) -> bool
|
|
||||||
get_contact(peer: PeerId) -> Contact
|
|
||||||
identify() -> Info
|
|
||||||
timestamp_ms() -> u64
|
|
||||||
timestamp_sec() -> u64
|
|
||||||
timeout(duration_ms: u64, message: string) -> string
|
|
||||||
|
|
||||||
data Consensus:
|
data Consensus:
|
||||||
n: u32
|
n: u32
|
||||||
@ -51,7 +31,7 @@ data Oracle:
|
|||||||
service TSOracle("service-id"):
|
service TSOracle("service-id"):
|
||||||
ts_frequency(timestamps: []u64, tolerance: u32, threshold: f64, err_value:u64) -> Consensus
|
ts_frequency(timestamps: []u64, tolerance: u32, threshold: f64, err_value:u64) -> Consensus
|
||||||
|
|
||||||
func ts_oracle_with_consensus(tolerance: u32, threshold: f64, err_value:u64, node:string, oracle_service_id:string)-> Consensus, []string:
|
func ts_oracle_with_consensus(tolerance: u32, threshold: f64, err_value:u64, node:string, oracle_service_id:string)-> Consensus, []string, u32:
|
||||||
rtt = 1000 -- in ms
|
rtt = 1000 -- in ms
|
||||||
res: *u64
|
res: *u64
|
||||||
msg = "timeout"
|
msg = "timeout"
|
||||||
@ -68,12 +48,15 @@ func ts_oracle_with_consensus(tolerance: u32, threshold: f64, err_value:u64, nod
|
|||||||
if status! != "success":
|
if status! != "success":
|
||||||
res <<- err_value
|
res <<- err_value
|
||||||
dead_peers <<- n
|
dead_peers <<- n
|
||||||
Op.noop()
|
--Op.noop()
|
||||||
|
|
||||||
join res[19]
|
join res[Op.array_length(nodes) - Op.array_length(dead_peers) -1]
|
||||||
|
|
||||||
TSOracle oracle_service_id
|
TSOracle oracle_service_id
|
||||||
consensus <- TSOracle.ts_frequency(res, tolerance, threshold, err_value)
|
consensus <- TSOracle.ts_frequency(res, tolerance, threshold, err_value)
|
||||||
<- consensus, dead_peers
|
|
||||||
|
<- consensus, dead_peers, Op.array_length(nodes) - Op.array_length(dead_peers)
|
||||||
|
|
||||||
|
|
||||||
func ts_oracle_with_bool(tolerance: u32, threshold: f64, err_value:u64, node:string, oracle_service_id:string)-> []bool, []string:
|
func ts_oracle_with_bool(tolerance: u32, threshold: f64, err_value:u64, node:string, oracle_service_id:string)-> []bool, []string:
|
||||||
res: *bool
|
res: *bool
|
||||||
@ -85,6 +68,6 @@ func ts_oracle_with_bool(tolerance: u32, threshold: f64, err_value:u64, node:str
|
|||||||
for n <- nodes par:
|
for n <- nodes par:
|
||||||
res <- Peer.connect(n, nil)
|
res <- Peer.connect(n, nil)
|
||||||
peers <<- n
|
peers <<- n
|
||||||
Op.noop()
|
|
||||||
join res[19]
|
join res[Op.array_length(nodes) - 1]
|
||||||
<- res, peers
|
<- res, peers
|
Reference in New Issue
Block a user