mirror of
https://github.com/fluencelabs/examples
synced 2024-12-05 03:30:17 +00:00
add ipfs to function parameters
This commit is contained in:
parent
11c72d8e6b
commit
44cd2f7fc5
@ -1,3 +1,7 @@
|
|||||||
|
import "@fluencelabs/aqua-lib/math.aqua"
|
||||||
|
import "@fluencelabs/aqua-ipfs/ipfs-api.aqua"
|
||||||
|
import "@fluencelabs/aqua-ipfs/ipfs.aqua"
|
||||||
|
|
||||||
data FunctionAddress:
|
data FunctionAddress:
|
||||||
peer_id: string
|
peer_id: string
|
||||||
service_id: string
|
service_id: string
|
||||||
@ -21,6 +25,13 @@ service MyOp2("op"):
|
|||||||
service MultiProviderQuery("service-id"):
|
service MultiProviderQuery("service-id"):
|
||||||
get_block_number(provider: ProviderInfo) -> EVMResult
|
get_block_number(provider: ProviderInfo) -> EVMResult
|
||||||
|
|
||||||
|
service Utilities("service_id"):
|
||||||
|
kv_to_u64(kv: string, k: string) -> u64
|
||||||
|
|
||||||
|
service Console("run-console"):
|
||||||
|
print(msg: string)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func get_block_heights(providers: []ProviderInfo, addrs: []FunctionAddress) -> []EVMResult:
|
func get_block_heights(providers: []ProviderInfo, addrs: []FunctionAddress) -> []EVMResult:
|
||||||
result: *EVMResult
|
result: *EVMResult
|
||||||
@ -63,9 +74,10 @@ func provider_test(providers: []ProviderInfo) -> []string:
|
|||||||
join result[n-1]
|
join result[n-1]
|
||||||
<- result
|
<- result
|
||||||
|
|
||||||
data QuorumService:
|
alias QuorumService: FunctionAddress
|
||||||
peer_id: string
|
-- data QuorumService:
|
||||||
service_id: string
|
-- peer_id: string
|
||||||
|
-- service_id: string
|
||||||
|
|
||||||
data Quorum:
|
data Quorum:
|
||||||
n: u32
|
n: u32
|
||||||
@ -102,10 +114,41 @@ func get_block_height_raw_quorum(providers: []ProviderInfo, addrs: []FunctionAdd
|
|||||||
<- quorum[0]
|
<- quorum[0]
|
||||||
|
|
||||||
|
|
||||||
-- func get_block_height_quorum(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService, t_quorum: i64) -> Oracle, u32:
|
service ConsoleEVMResults("run-console"):
|
||||||
|
print(result :[]EVMResult)
|
||||||
|
|
||||||
|
service ConsoleEVMResult("run-console"):
|
||||||
|
print(result :EVMResult)
|
||||||
|
|
||||||
|
service ConsoleQuorum("run-console"):
|
||||||
|
print(quorum :[]Quorum)
|
||||||
|
|
||||||
func get_block_height_quorum(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService, t_quorum: f64) -> Quorum, bool:
|
func get_block_height_quorum(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService, t_quorum: f64) -> Quorum, bool:
|
||||||
result: *EVMResult
|
result: *EVMResult
|
||||||
result2: *string
|
quorum: *Quorum
|
||||||
|
is_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)
|
||||||
|
join result[n*n2-2]
|
||||||
|
|
||||||
|
on q_addr.peer_id:
|
||||||
|
SimpleQuorum q_addr.service_id
|
||||||
|
quorum <-SimpleQuorum.point_estimate(result, min_points)
|
||||||
|
is_quorum <- SimpleQuorum.is_quorum(quorum[0].freq, quorum[0].n, t_quorum)
|
||||||
|
|
||||||
|
<- quorum[0], is_quorum[0]
|
||||||
|
|
||||||
|
func get_block_height_quorum_with_mapper(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService, u_addr: FunctionAddress, t_quorum: f64) -> Quorum, bool:
|
||||||
|
result: *EVMResult
|
||||||
quorum: *Quorum
|
quorum: *Quorum
|
||||||
is_quorum: *bool
|
is_quorum: *bool
|
||||||
|
|
||||||
@ -120,24 +163,57 @@ func get_block_height_quorum(providers: []ProviderInfo, addrs: []FunctionAddress
|
|||||||
MultiProviderQuery addr.service_id
|
MultiProviderQuery addr.service_id
|
||||||
for provider <- providers:
|
for provider <- providers:
|
||||||
result <- MultiProviderQuery.get_block_number(provider)
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
result2 <<- provider.name
|
-- result2 <<- provider.name
|
||||||
-- join result[n2-1]
|
-- join result[n2-1]
|
||||||
join result[n*n2-1]
|
-- join result[n-1]
|
||||||
|
join result[n*n2-2]
|
||||||
|
|
||||||
on q_addr.peer_id:
|
on q_addr.peer_id:
|
||||||
SimpleQuorum q_addr.service_id
|
SimpleQuorum q_addr.service_id
|
||||||
quorum <-SimpleQuorum.point_estimate(result, min_points)
|
quorum <-SimpleQuorum.point_estimate(result, min_points)
|
||||||
is_quorum <- SimpleQuorum.is_quorum(quorum[0].freq, quorum[0].n, t_quorum)
|
if quorum[0].mode == 0:
|
||||||
|
is_quorum <<- false
|
||||||
|
else:
|
||||||
|
is_quorum <- SimpleQuorum.is_quorum(quorum[0].freq, quorum[0].n, t_quorum)
|
||||||
|
|
||||||
|
deviations: *EVMResult
|
||||||
|
n_dev = 1
|
||||||
|
if quorum[0].freq != quorum[0].n:
|
||||||
|
on u_addr.peer_id:
|
||||||
|
Utilities u_addr.service_id
|
||||||
|
for res <- result:
|
||||||
|
v <- Utilities.kv_to_u64(res.stdout, "block-height")
|
||||||
|
if v != quorum[0].mode:
|
||||||
|
deviations <<- res
|
||||||
|
on %init_peer_id% via u_addr.peer_id:
|
||||||
|
co ConsoleEVMResult.print(res) --< placeholder for future processing of divergent responses
|
||||||
|
Math.add(n_dev, 1)
|
||||||
|
-- ConsoleEVMResults.print(deviations)
|
||||||
<- quorum[0], is_quorum[0]
|
<- quorum[0], is_quorum[0]
|
||||||
|
|
||||||
|
data IpfsObj:
|
||||||
|
cid: string
|
||||||
|
multiaddr: string
|
||||||
|
|
||||||
func get_block_height_quorum_exceptions(providers: []ProviderInfo, addrs: []FunctionAddress, q_addr: QuorumService) -> Quorum, EVMResult:
|
service IpfsCli("service-is"):
|
||||||
|
params_from_cid(multiaddr: string, cid: string) -> []FunctionAddress
|
||||||
|
|
||||||
|
|
||||||
|
func get_block_height_quorum_with_cid(providers: []ProviderInfo, services_cid: IpfsObj, quorum_cid: IpfsObj, utility_cid: IpfsObj, ipfs_service: FunctionAddress, t_quorum: f64) -> Quorum, bool:
|
||||||
|
--func get_block_height_quorum_with_cid(providers: []ProviderInfo, services_cid: IpfsObj, quorum_cid: IpfsObj, utility_cid: IpfsObj, ipfs_service: FunctionAddress, t_quorum: f64) -> []FunctionAddress,[]FunctionAddress,[]FunctionAddress:
|
||||||
result: *EVMResult
|
result: *EVMResult
|
||||||
result2: *string
|
|
||||||
quorum: *Quorum
|
quorum: *Quorum
|
||||||
|
is_quorum: *bool
|
||||||
n <- MyOp.array_length(providers)
|
|
||||||
|
min_points = 3 -- minimum points we want in order to calculate an oracle
|
||||||
|
|
||||||
|
on ipfs_service.peer_id:
|
||||||
|
IpfsCli ipfs_service.service_id
|
||||||
|
addrs <- IpfsCli.params_from_cid(services_cid.multiaddr, services_cid.cid)
|
||||||
|
q_addrs <- IpfsCli.params_from_cid(quorum_cid.multiaddr, quorum_cid.cid)
|
||||||
|
u_addrs <- IpfsCli.params_from_cid(utility_cid.multiaddr, utility_cid.cid)
|
||||||
|
|
||||||
|
n <- MyOp.array_length(providers)
|
||||||
n2 <- MyOp2.array_length(addrs)
|
n2 <- MyOp2.array_length(addrs)
|
||||||
|
|
||||||
if n > 0:
|
if n > 0:
|
||||||
@ -146,14 +222,28 @@ func get_block_height_quorum_exceptions(providers: []ProviderInfo, addrs: []Func
|
|||||||
MultiProviderQuery addr.service_id
|
MultiProviderQuery addr.service_id
|
||||||
for provider <- providers:
|
for provider <- providers:
|
||||||
result <- MultiProviderQuery.get_block_number(provider)
|
result <- MultiProviderQuery.get_block_number(provider)
|
||||||
result2 <<- provider.name
|
join result[n*n2-2]
|
||||||
-- join result[n2-1]
|
|
||||||
join result[n*n2-1]
|
on q_addrs[0].peer_id:
|
||||||
|
SimpleQuorum q_addrs[0].service_id
|
||||||
on q_addr.peer_id:
|
quorum <-SimpleQuorum.point_estimate(result, min_points)
|
||||||
SimpleQuorum q_addr.service_id
|
if quorum[0].mode == 0:
|
||||||
quorum <-SimpleQuorum.point_estimate(result, 3)
|
is_quorum <<- false
|
||||||
|
else:
|
||||||
|
is_quorum <- SimpleQuorum.is_quorum(quorum[0].freq, quorum[0].n, t_quorum)
|
||||||
|
|
||||||
|
deviations: *EVMResult
|
||||||
|
n_dev = 1
|
||||||
|
if quorum[0].freq != quorum[0].n:
|
||||||
|
on u_addrs[0].peer_id:
|
||||||
|
Utilities u_addrs[0].service_id
|
||||||
|
for res <- result:
|
||||||
|
v <- Utilities.kv_to_u64(res.stdout, "block-height")
|
||||||
|
if v != quorum[0].mode:
|
||||||
|
deviations <<- res
|
||||||
|
on %init_peer_id% via u_addrs[0].peer_id:
|
||||||
|
co ConsoleEVMResult.print(res)
|
||||||
|
Math.add(n_dev, 1)
|
||||||
|
<- quorum[0], is_quorum[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<- quorum[0], result[0]
|
|
Loading…
Reference in New Issue
Block a user