mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
add aqua script
This commit is contained in:
parent
8a1a5fc20f
commit
38ad65fc8f
@ -1,42 +1,159 @@
|
|||||||
-- import "@fluencelabs/aqua-lib/builtin.aqua"
|
data FunctionAddress:
|
||||||
|
peer_id: string
|
||||||
|
service_id: string
|
||||||
|
|
||||||
-- func n_urls(providers:Providers) -> i64:
|
data ProviderInfo:
|
||||||
-- res: *string
|
name: string
|
||||||
-- for provider <- providers.urls:
|
url: string
|
||||||
-- res <<- provider.url
|
|
||||||
-- n <- Op.array_length(res)
|
|
||||||
-- <- n
|
|
||||||
|
|
||||||
data EVMResult:
|
data EVMResult:
|
||||||
|
provider: string
|
||||||
stdout: string
|
stdout: string
|
||||||
stderr: string
|
stderr: string
|
||||||
|
|
||||||
data ProviderInfo:
|
|
||||||
url: string
|
|
||||||
api_key: string
|
|
||||||
name: string
|
|
||||||
|
|
||||||
data Providers:
|
|
||||||
urls: []ProviderInfo
|
|
||||||
|
|
||||||
service MyOp("op"):
|
service MyOp("op"):
|
||||||
identity(x:string) -> string
|
|
||||||
array_length(providers: []ProviderInfo) -> i64
|
array_length(providers: []ProviderInfo) -> i64
|
||||||
|
identity(x: i64) -> f64
|
||||||
|
|
||||||
|
service MyOp2("op"):
|
||||||
|
array_length(providers: []FunctionAddress) -> i64
|
||||||
|
|
||||||
service MultiProviderQuery("service-id"):
|
service MultiProviderQuery("service-id"):
|
||||||
get_balance(provider: ProviderInfo, account: string, block_height: string) -> EVMResult
|
get_block_number(provider: ProviderInfo) -> EVMResult
|
||||||
get_block_number(provider: ProviderInfo) -> EVMResult
|
|
||||||
|
|
||||||
func get_block_heights(providers: Providers, service_id: string, node: string) -> []EVMResult, i64:
|
|
||||||
block_heights: *EVMResult
|
|
||||||
-- n <- n_urls(providers)
|
|
||||||
n <- MyOp.array_length(providers.urls)
|
|
||||||
|
|
||||||
if n > 0:
|
func get_block_heights(providers: []ProviderInfo, addrs: []FunctionAddress) -> []EVMResult:
|
||||||
on node:
|
result: *EVMResult
|
||||||
MultiProviderQuery service_id
|
result2: *string
|
||||||
for provider <- providers.urls par:
|
n <- MyOp.array_length(providers)
|
||||||
block_heights <- MultiProviderQuery.get_block_number(provider)
|
n2 <- MyOp2.array_length(addrs)
|
||||||
join block_heights[n-1]
|
|
||||||
|
|
||||||
<- block_heights, n
|
if n > 0:
|
||||||
|
for addr <- addrs par:
|
||||||
|
on addr.peer_id:
|
||||||
|
MultiProviderQuery addr.service_id
|
||||||
|
for provider <- providers:
|
||||||
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
|
result2 <<- provider.name
|
||||||
|
-- join result[n2-1]
|
||||||
|
join result[n*n2-1]
|
||||||
|
<- result
|
||||||
|
|
||||||
|
|
||||||
|
func get_block_height(providers: []ProviderInfo, addr: FunctionAddress) ->[]EVMResult:
|
||||||
|
result: *EVMResult
|
||||||
|
n <- MyOp.array_length(providers)
|
||||||
|
|
||||||
|
if n > 0:
|
||||||
|
on addr.peer_id:
|
||||||
|
MultiProviderQuery addr.service_id
|
||||||
|
for provider <- providers:
|
||||||
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
|
join result[n]
|
||||||
|
<- result
|
||||||
|
|
||||||
|
|
||||||
|
func provider_test(providers: []ProviderInfo) -> []string:
|
||||||
|
result: *string
|
||||||
|
n <- MyOp.array_length(providers)
|
||||||
|
|
||||||
|
if n > 0:
|
||||||
|
for provider <- providers:
|
||||||
|
result <<- provider.name
|
||||||
|
join result[n-1]
|
||||||
|
<- result
|
||||||
|
|
||||||
|
data QuorumService:
|
||||||
|
peer_id: string
|
||||||
|
service_id: string
|
||||||
|
|
||||||
|
data Oracle:
|
||||||
|
n: u32
|
||||||
|
mode: u64
|
||||||
|
freq: u32
|
||||||
|
err_str: string
|
||||||
|
|
||||||
|
service SimpleQuorum("service-id"):
|
||||||
|
point_estimate(data: []EVMResult, min_points: u32) -> Oracle
|
||||||
|
is_quorum(x:u64, y:u64, threshold:f64) -> bool
|
||||||
|
|
||||||
|
func get_block_height_oracle(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService) -> Oracle:
|
||||||
|
result: *EVMResult
|
||||||
|
result2: *string
|
||||||
|
oracle: *Oracle
|
||||||
|
|
||||||
|
n <- MyOp.array_length(providers)
|
||||||
|
n2 <- MyOp2.array_length(addrs)
|
||||||
|
|
||||||
|
if n > 0:
|
||||||
|
for addr <- addrs par:
|
||||||
|
on addr.peer_id:
|
||||||
|
MultiProviderQuery addr.service_id
|
||||||
|
for provider <- providers:
|
||||||
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
|
result2 <<- provider.name
|
||||||
|
-- join result[n2-1]
|
||||||
|
join result[n*n2-1]
|
||||||
|
|
||||||
|
on q_addr.peer_id:
|
||||||
|
SimpleQuorum q_addr.service_id
|
||||||
|
oracle <-SimpleQuorum.point_estimate(result, 3)
|
||||||
|
|
||||||
|
<- oracle[0]
|
||||||
|
|
||||||
|
|
||||||
|
-- func get_block_height_quorum(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService, t_quorum: i64) -> Oracle, u32:
|
||||||
|
func get_block_height_quorum(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService, t_quorum: f64) -> Oracle, bool:
|
||||||
|
result: *EVMResult
|
||||||
|
result2: *string
|
||||||
|
oracle: *Oracle
|
||||||
|
quorum: *bool
|
||||||
|
|
||||||
|
min_points = 3 -- minimum points we want in order to calculate an oracle
|
||||||
|
|
||||||
|
n <- MyOp.array_length(providers)
|
||||||
|
n2 <- MyOp2.array_length(addrs)
|
||||||
|
|
||||||
|
if n > 0:
|
||||||
|
for addr <- addrs par:
|
||||||
|
on addr.peer_id:
|
||||||
|
MultiProviderQuery addr.service_id
|
||||||
|
for provider <- providers:
|
||||||
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
|
result2 <<- provider.name
|
||||||
|
-- join result[n2-1]
|
||||||
|
join result[n*n2-1]
|
||||||
|
|
||||||
|
on q_addr.peer_id:
|
||||||
|
SimpleQuorum q_addr.service_id
|
||||||
|
oracle <-SimpleQuorum.point_estimate(result, min_points)
|
||||||
|
quorum <- SimpleQuorum.is_quorum(oracle[0].freq, oracle[0].n, t_quorum)
|
||||||
|
|
||||||
|
<- oracle[0], quorum[0]
|
||||||
|
|
||||||
|
|
||||||
|
func get_block_height_quorum_exceptions(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService) -> Oracle, EVMResult:
|
||||||
|
result: *EVMResult
|
||||||
|
result2: *string
|
||||||
|
oracle: *Oracle
|
||||||
|
|
||||||
|
n <- MyOp.array_length(providers)
|
||||||
|
n2 <- MyOp2.array_length(addrs)
|
||||||
|
|
||||||
|
if n > 0:
|
||||||
|
for addr <- addrs par:
|
||||||
|
on addr.peer_id:
|
||||||
|
MultiProviderQuery addr.service_id
|
||||||
|
for provider <- providers:
|
||||||
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
|
result2 <<- provider.name
|
||||||
|
-- join result[n2-1]
|
||||||
|
join result[n*n2-1]
|
||||||
|
|
||||||
|
on q_addr.peer_id:
|
||||||
|
SimpleQuorum q_addr.service_id
|
||||||
|
oracle <-SimpleQuorum.point_estimate(result, 3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<- oracle[0], result[0]
|
Loading…
Reference in New Issue
Block a user