mirror of
https://github.com/fluencelabs/examples
synced 2024-12-04 19:20:17 +00:00
update Readme, examples
This commit is contained in:
parent
65d8c6d8ed
commit
90a25bedfe
@ -1,113 +1,828 @@
|
||||
# Title
|
||||
# Greeting Service
|
||||
|
||||
This example illustrates how to use a greeting service as a consumer of output(s) from an upstream service.
|
||||
In this example we illustrate the implementation and composition of two services into a decentralized application with Aqua. Specifically, we use a hosted greeting, aka *hello world*, service as a consumer of the output of another hosted service with Aqua. For the purpose of this example let's call our upstream service *echo-service*, which simply echos inputs. *Echo-service* can be viewed as a placeholder for, say, a database or formatting service.
|
||||
|
||||
|
||||
Echo-Service
|
||||
peer service-id client-seed name
|
||||
12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
|
||||
fb5f7126-e1ee-4ecf-81e7-20804cb7203b
|
||||
CXFpzXPC2WUpoME3jBX7F53dorK15bcux9Wmt52Geprn
|
||||
## Requirements
|
||||
|
||||
12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
893a6fb8-43b9-4b11-8786-93300bd68bc8
|
||||
CUwsEyKop4rR8mwfGiu8qPZHCzAjKnA7LQGd1VFHAVgM
|
||||
To run the example in its entirety, you need to install a few tools. See [Setting Up](https://doc.fluence.dev/docs/tutorials_tutorials/recipes_setting_up) for details. For more developer resources see the [Developer Docs](https://doc.fluence.dev/docs/), [Aqua Book](https://doc.fluence.dev/aqua-book/) and the [Marine Examples](./../../marine-examples).
|
||||
|
||||
## Service Development And Deployment
|
||||
|
||||
Services are logical constructs comprised of Wasm Interface Types (IT) modules executing on the [Marine](https://github.com/fluencelabs/marine) runtime available on each [Fluence node](https://github.com/fluencelabs/fluence). At this time, Rust is not only the preferred but also the only option to write Wasm modules. For the examples at hand, we need to develop and deploy two services: a greeting service and an echo service where the echo service returns the inputs for the greeting service.
|
||||
|
||||
Our [greeting service](./greeting/src/main.rs) is very simple: it takes a name value to return and a boolean value to determine whether our greeting to `name` is *Hi* or *Bye*. As shown below, the code is basic Rust with plus the `marine macro`, which makes sure our code is valid Wasm IT code that can be compiled to our desired `wasmer32-wasi` compile target.
|
||||
|
||||
```rust
|
||||
// greeting-service/src/main.rs
|
||||
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[marine]
|
||||
pub fn greeting(name: String, greeter: bool) -> String {
|
||||
match greeter {
|
||||
true => format!("Hi, {}", name),
|
||||
false => format!("Bye, {}", name),
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The echo-service, see below, takes a vector of strings, maps each string to the Echo struct and returns the resulting vector of structs.
|
||||
|
||||
```rust
|
||||
// echo-service/src/main.rs
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
|
||||
module_manifest!();
|
||||
|
||||
#[marine]
|
||||
pub struct Echo {
|
||||
pub echo: String,
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn echo(inputs: Vec<String>) -> Vec<Echo> {
|
||||
inputs
|
||||
.iter()
|
||||
.map(|s| Echo {
|
||||
echo: s.to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
```
|
||||
|
||||
We can compile our code with the provided build script:
|
||||
|
||||
```text
|
||||
% ./scripts/build_all.sh
|
||||
```
|
||||
|
||||
The build script compiles each of the specified services with the marine compiler and generates two Wasm modules, which are placed in the `artifacts` directory. Before we deploy the service, we can inspect and test each module with the Marine REPL and the `configs/Config.toml` file which contains the metadata with respect to module location, name, etc.
|
||||
|
||||
```text
|
||||
% mrepl configs/Config.toml
|
||||
Welcome to the Marine REPL (version 0.8.0)
|
||||
Minimal supported versions
|
||||
sdk: 0.6.0
|
||||
interface-types: 0.20.0
|
||||
|
||||
app service was created with service id = d5974dab-d7dc-4168-9b47-1d9a647a6fa8
|
||||
elapsed time 82.823341ms
|
||||
|
||||
1> interface <-- list all public interfaces
|
||||
Loaded modules interface:
|
||||
data Echo:
|
||||
echo: string
|
||||
|
||||
echo_service: <-- echo service namespace
|
||||
fn echo(inputs: []string) -> []Echo
|
||||
greeting: <-- greeting service namespace
|
||||
fn greeting(name: string, greeter: bool) -> string
|
||||
|
||||
> call echo_service echo [["jim", "john", "jill"]]
|
||||
result: Array([Object({"echo": String("jim")}), Object({"echo": String("john")}), Object({"echo": String("jill")})])
|
||||
elapsed time: 150.194µs
|
||||
|
||||
3> call greeting greeting ["boo", true]
|
||||
result: String("Hi, boo")
|
||||
elapsed time: 128.356µs
|
||||
|
||||
4> call greeting greeting ["yah", false]
|
||||
result: String("Bye, yah")
|
||||
elapsed time: 49.64µs
|
||||
```
|
||||
|
||||
Looks like all is working as planned and we're ready to deploy our services to the Fluence testnet. To deploy a service, we need the peer id of our desired host node, which we can get with `fldist env`:
|
||||
|
||||
```text
|
||||
% fldist env
|
||||
/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e
|
||||
/dns4/kras-00.fluence.dev/tcp/19001/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51
|
||||
/dns4/kras-01.fluence.dev/tcp/19001/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA
|
||||
/dns4/kras-02.fluence.dev/tcp/19001/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf
|
||||
/dns4/kras-03.fluence.dev/tcp/19001/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
<snip>
|
||||
/dns4/kras-09.fluence.dev/tcp/19001/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm
|
||||
```
|
||||
|
||||
Any one of the peers will do and we can deploy our services with the `fldist` tool by providing the peer id of the host node and the location of the Wasm module(s) and configuration file defining the service.
|
||||
|
||||
```text
|
||||
# deploy greeting service
|
||||
fldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE new_service --ms artifacts/greeting.wasm:configs/greeting_cfg.json --name greeting-demo
|
||||
service id: 9436af06-86ab-4df3-ba2a-ad29e37043c2
|
||||
service created successfully
|
||||
```
|
||||
|
||||
and
|
||||
|
||||
```text
|
||||
# deploy echo service
|
||||
fldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE new_service --ms artifacts/echo_service.wasm:configs/echo_service_cfg.json --name echo-demo
|
||||
service id: ff3f3aa0-daeb-4555-b596-0f653df2ace9
|
||||
service created successfully
|
||||
```
|
||||
|
||||
Note the return of the service id for each services deployed as we need the peer and service id to compose our services into decentralized apps.
|
||||
|
||||
## Building A Decentralized Greeting Application With Aqua
|
||||
|
||||
|
||||
Greeting-Service
|
||||
peer service-id client-seed name
|
||||
12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
5a03906b-3217-40a2-93fb-7e83be735408
|
||||
4X9p5vRWqS9rxgPop9C3p6fn1TpHGxRxTe9dga1NN77R
|
||||
We're ready to build our application with Aqua as our composition medium from the greeting and echo service. Creating Aqua scripts requires the specifications of each service's public API. Marine offers us a convenient way to export Aqua-compatible interface definitions:
|
||||
|
||||
```aqua
|
||||
% marine aqua artifacts/greeting.wasm
|
||||
service Greeting:
|
||||
greeting(name: string, greeter: bool) -> string
|
||||
%
|
||||
% marine aqua artifacts/echo_service.wasm
|
||||
data Echo:
|
||||
echo: string
|
||||
|
||||
12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
|
||||
5cf520ff-dd65-47d7-a51a-2bf08dfe2ede
|
||||
2nypBDAGsxgft4TrQgBupJ3smoaRbkiYjC2MqTzSBRw1
|
||||
service EchoService:
|
||||
echo(inputs: []string) -> []Echo
|
||||
```
|
||||
|
||||
Of course, we can pipe the `marina aqua` interfaces into an aqua file of your choice, e.g. `marine aqua artifacts/greeting.wasm >> aqua-scripts/my_aqua.aqua`, to get things started. Before we dive into the Aqua development, let's compile the already created Aqua program `aqua-scripts\echo_greeter.aqua` with `aqua-cli`:
|
||||
|
||||
```text
|
||||
% aqua-cli -i aqua-scripts -o aqua-compiled -a
|
||||
```
|
||||
|
||||
Utilities-Service
|
||||
peer service-id client-seed name
|
||||
12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
|
||||
abeaf9ef-c5c0-46ef-92eb-de605eb86ffd
|
||||
BvVwn1X36j5UGttGRdxQfJ1zFqMsAivLzXY6sdkbv2mx
|
||||
Since we compile with the `-a` flag, we generate aqua intermediate representation (AIR) files which are located in the `air-scripts` directory. Further below, we'll see how to generate ready-to use Typescript stubs generated by the Aqua compiler.
|
||||
|
||||
12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
e23c2a8b-c3f2-4067-8e92-803691fdf5b7
|
||||
7SDxZerQxQCFjivromanTurV3UNj7Up4cdh9ZxXWwX5e
|
||||
To make things copacetic for the remainder of this section, we'll be using services already deployed to the Fluence testnet:
|
||||
|
||||
```text
|
||||
echo-services: [("12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "fb5f7126-e1ee-4ecf-81e7-20804cb7203b"), ("12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "893a6fb8-43b9-4b11-8786-93300bd68bc8")]
|
||||
|
||||
greeting-services: [("12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "5a03906b-3217-40a2-93fb-7e83be735408"), ("12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "5cf520ff-dd65-47d7-a51a-2bf08dfe2ede")]
|
||||
```
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.echo_greeting_seq.air -d '{"names":["1", "2", "3"],"echo_service_id":"893a6fb8-43b9-4b11-8786-93300bd68bc8", "greeting_service_id":"5a03906b-3217-40a2-93fb-7e83be735408", "greet": false, "node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE"}' --generated
|
||||
Below is the first attempt at using Aqua to compose our two-services into the desired application workflow: the execution of a greeting service for each output provided by the upstream service.
|
||||
|
||||
```aqua
|
||||
-- aqua-scripts/echo_greeter.aqua
|
||||
|
||||
-- interface struct from echo-service.wsasm
|
||||
data EchoResult:
|
||||
echo: string
|
||||
|
||||
-- interface function from echo-service.wsasm
|
||||
service EchoService:
|
||||
echo: []string -> []EchoResult
|
||||
|
||||
-- interface function from greeting.wsasm
|
||||
service GreetingService("service-id"):
|
||||
greeting: string, bool -> string
|
||||
|
||||
-- Identity function we'll use for join
|
||||
service OpString("op"):
|
||||
identity(s: string) -> string
|
||||
|
||||
-- call echo service and and sequentially call greeting service on each name
|
||||
-- one service, on one node for all processing needs
|
||||
func echo_greeting_seq(names: []string, greet: bool, node: string, echo_service_id: string, greeting_service_id: string) -> []string:
|
||||
res: *string <- 1
|
||||
on node: <- 2
|
||||
EchoService echo_service_id <- 3
|
||||
GreetingService greeting_service_id <- 4
|
||||
echo_names <- EchoService.echo(names) <- 5
|
||||
<- echo_names
|
||||
for result <- echo_names: <- 6
|
||||
res <- GreetingService.greeting(result.echo, greet) <- 7
|
||||
<- res <- 8
|
||||
```
|
||||
|
||||
The first section of the Aqua file are the public interfaces exposed from the underlying Wasm services, which we obtained earlier from the marine cli. Our composition of the services into our application happens with the `echo_greeting_seq` function. Before we run through the function body, let's have a look at the function signature:
|
||||
|
||||
```aqua
|
||||
-- this function encapsulates our workflow logic
|
||||
func echo_greeting_seq(names: []string, greet: bool, node: string, echo_service_id: string,greeting_service_id: string) -> []string:
|
||||
```
|
||||
|
||||
Recall that
|
||||
* the echo service takes an array of strings and
|
||||
* the greeting service takes a string and a boolean
|
||||
|
||||
Our first two argument slots take care of that. Aside from the actual Wasm function inputs, we also need to provide information with respect to the location and identity of the services we want to utilize. In this instance, we provide service ids for both the echo and greeting service, respectively, and one peer id. This indicates that both services are hosted on the same node, which is possible but not necessary or even desirable.
|
||||
|
||||
In the function body:
|
||||
|
||||
1. Declare a streaming variable to accept greeting function returns
|
||||
2. Specify the node on which we want to execute the following function body
|
||||
3. Declare the echo-service binding to the specified service id
|
||||
4. Declare the greeting-service binding to the specified service id
|
||||
5. Call the echo service with names array taken as a function input
|
||||
6. Fold over the results (echo_names)
|
||||
7. Call the Greeting service with a name and the greet parameters in sequence
|
||||
8. Return the results array
|
||||
|
||||
Let's run the compiled Aqua code with the `fldist` cli toolL
|
||||
|
||||
```text
|
||||
fldist run_air \
|
||||
-p aqua-compiled/echo_greeter.echo_greeting_seq.air \
|
||||
-d '{"names":["jim", "john", "james"], \
|
||||
"greet": true, \
|
||||
"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", \ "greeting_service_id":"5a03906b-3217-40a2-93fb-7e83be735408", \
|
||||
"echo_service_id": "893a6fb8-43b9-4b11-8786-93300bd68bc8"}' \
|
||||
--generated
|
||||
```
|
||||
|
||||
`fldist` provides a client peer and deploys the compiled Aqua script, with the `-p` flag, and input data, with the `-d` flag, in form of a json string to the peer-to-peer network for execution and returns expected result:
|
||||
|
||||
```text
|
||||
[
|
||||
[
|
||||
"Bye, 1",
|
||||
"Bye, 2",
|
||||
"Bye, 3"
|
||||
"Hi, jim",
|
||||
"Hi, john",
|
||||
"Hi, james"
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
Of course, services need not be deployed to the same node and with some minor adjustments to our Aqua function signature and body, we can accommodate multi-host scenarios rather easily. We also added the `NodeServicePair` structure to make the function signature more compact:
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.echo_greeting_par.air -d '{"names": ["n1", "n2", "n3"], "greet": true, "echo_service":{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}, "greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"5a03906b-3217-40a2-93fb-7e83be735408"},{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede"}]}' --generated
|
||||
[
|
||||
[]
|
||||
]
|
||||
```aqua
|
||||
-- aqua-scripts/echo_greeter.aqua
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.greeting.air -d '{"name":"boo", "node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "greeting_service_id":"5a03906b-3217-40a2-93fb-7e83be735408", "greet":true}' --generated
|
||||
[
|
||||
"Hi, boo"
|
||||
]
|
||||
-- struct for node, service tuple
|
||||
data NodeServicePair:
|
||||
node: string
|
||||
service_id: string
|
||||
|
||||
-- revised Aqua function to accommodate (node, service) separation
|
||||
func echo_greeting_seq_2(names: []string, greet: bool, echo_topo: NodeServicePair, greeting_topo: NodeServicePair) -> []string:
|
||||
res: *string
|
||||
on echo_topo.node:
|
||||
EchoService echo_topo.service_id
|
||||
echo_names <- EchoService.echo(names)
|
||||
|
||||
on greeting_topo.node:
|
||||
GreetingService greeting_topo.service_id
|
||||
for result <- echo_names:
|
||||
res <- GreetingService.greeting(result.echo, greet)
|
||||
<- res
|
||||
```
|
||||
|
||||
Since we want to compose services deployed on different nodes, we express this requirement by specifying the (node, service) tuples via `on echo_topo.node` and `on greeting-topo.node` in sequence. That is, the workflow first calls the echo-service followed by three sequential calls on the greeting service.
|
||||
|
||||
Again, we can execute our workflow with the `fldist` tool:
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.echo_greeting_par.air -d '{"names": ["n1", "n2", "n3"], "greet": true, "echo_service":{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}, "greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"5a03906b-3217-40a2-93fb-7e83be735408"},{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede"}]}' --generated
|
||||
```text
|
||||
fldist run_air \
|
||||
-p aqua-compiled/echo_greeter.echo_greeting_seq_2.air \
|
||||
-d '{"names":["jim", "john", "james"], \
|
||||
"greet": true, \
|
||||
"greeting_topo":{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", \
|
||||
"service_id":"5a03906b-3217-40a2-93fb-7e83be735408"}, \
|
||||
"echo_topo": {"node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id": "fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}}' \
|
||||
--generated
|
||||
```
|
||||
|
||||
Regardless of the difference in service hosts, we of course get the expected result:
|
||||
|
||||
```text
|
||||
[
|
||||
[
|
||||
"Hi, n1",
|
||||
"Hi, n2",
|
||||
"Hi, n3",
|
||||
"Hi, n3"
|
||||
"Hi, jim",
|
||||
"Hi, john",
|
||||
"Hi, james"
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
Both workflow examples we've seen are executing service calls in sequence. Let's kick it up a notch and process echo service outputs in parallel. Of course, we need to have the necessary greeting services deployed on different peers otherwise parallel processing defaults to sequential processing. Also, to continue to keep things compact, we introduce the `EchoServiceInput` struct.
|
||||
|
||||
```aqua
|
||||
|
||||
data EchoServiceInput:
|
||||
node: string
|
||||
service_id: string
|
||||
names: []string
|
||||
|
||||
func echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
|
||||
res: *string
|
||||
on echo_service.node:
|
||||
EchoService echo_service.service_id
|
||||
echo_results <- EchoService.echo(echo_service.names)
|
||||
|
||||
for result <- echo_results:
|
||||
for greeting_service <- greeting_services:
|
||||
GreetingService greeting_service.service_id
|
||||
par on greeting_service.node:
|
||||
res <- GreetingService.greeting(result.echo, greet)
|
||||
OpString.identity(res!5)
|
||||
<- res
|
||||
```
|
||||
|
||||
In this implementation version, we call the echo-service, justas before, and introduce parallelization when we reach the greeting service fold. That is, each greeting service arm is run in parallel and for each *result*, we execute k greeting services, as specified in greeting_services array, in parallel. Note that as a consequence of the parallelization we need to introduce a `join` on *res* as the result streaming into *res* happens on the specified node and therefore without being visible to the other streaming activities. We accomplish this with the `OpString.identity(res!5)` function where the argument needs to be a literal at this point.
|
||||
|
||||
|
||||
Our updated `fldist` reads:
|
||||
|
||||
```text
|
||||
fldist run_air \
|
||||
-p aqua-compiled/echo_greeter.echo_greeting_par.air \
|
||||
-d '{"echo_service":{"names":["jim", "john", "james"],\
|
||||
"node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id": "fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}, \
|
||||
"greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", \
|
||||
"service_id":"5a03906b-3217-40a2-93fb-7e83be735408"}, \
|
||||
{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede"}], \
|
||||
"greet": true}' \
|
||||
--generated
|
||||
```
|
||||
|
||||
And our result is:
|
||||
|
||||
```text
|
||||
|
||||
[
|
||||
"Hi, jim",
|
||||
"Hi, jim",
|
||||
"Hi, john",
|
||||
"Hi, john",
|
||||
"Hi, james",
|
||||
"Hi, james"
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
Since we got three input names and two greeting services, we expect, and got, six results where the parallelization is on each echo-service result. Of course, we can change the parallelization to cover the echo-service results array for each provided service:
|
||||
|
||||
Our updated Auqa composition function now reads:
|
||||
|
||||
```aqua
|
||||
func echo_greeting_par_inverse(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
|
||||
res: *string
|
||||
on echo_service.node:
|
||||
EchoService echo_service.service_id
|
||||
echo_results <- EchoService.echo(echo_service.names)
|
||||
|
||||
for greeting_service <- greeting_services:
|
||||
GreetingService greeting_service.service_id
|
||||
par on greeting_service.node:
|
||||
for result <- echo_results:
|
||||
res <- GreetingService.greeting(result.echo, greet)
|
||||
OpString.identity(res!3)
|
||||
<- res
|
||||
```
|
||||
|
||||
And running the workflow with the updated data:
|
||||
|
||||
|
||||
fldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE run_air -p aqua-compiled/utilities.splitter.air -d '{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"e23c2a8b-c3f2-4067-8e92-803691fdf5b7", "array":[1,2,3,4,5,6,7,8,9], "chunk_size": 3 }' --generated
|
||||
```text
|
||||
fldist run_air \
|
||||
-p aqua-compiled/echo_greeter.echo_greeting_par_inverse.air \
|
||||
-d '{"echo_service":{"names":["jim", "john", "james"], \
|
||||
"node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id": "fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}, \
|
||||
"greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", \
|
||||
"service_id":"5a03906b-3217-40a2-93fb-7e83be735408"}, \
|
||||
{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede"}], \
|
||||
"greet": true}' \
|
||||
--generated
|
||||
```
|
||||
|
||||
gives us the updated result:
|
||||
|
||||
|
||||
```text
|
||||
[
|
||||
[
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5,
|
||||
6
|
||||
],
|
||||
[
|
||||
7,
|
||||
8,
|
||||
9
|
||||
]
|
||||
"Hi, jim",
|
||||
"Hi, john",
|
||||
"Hi, james",
|
||||
"Hi, jim",
|
||||
"Hi, john",
|
||||
"Hi, james"
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
With minor modifications to our Aqua functions, we can make those parallelizations a little more useful by suppling the *greet* parameter for each service. Let's add a `GreetingServiceInput` struct and update the function signatures and bodies:
|
||||
|
||||
``aqua
|
||||
data GreetingServiceInput:
|
||||
node: string
|
||||
service_id: string
|
||||
greet: bool
|
||||
|
||||
|
||||
func echo_greeting_par_greet(echo_service: EchoServiceInput, greeting_services: []GreetingServiceInput) -> []string:
|
||||
res: *string
|
||||
on echo_service.node:
|
||||
EchoService echo_service.service_id
|
||||
echo_results <- EchoService.echo(echo_service.names)
|
||||
|
||||
for result <- echo_results:
|
||||
for greeting_service <- greeting_services:
|
||||
GreetingService greeting_service.service_id
|
||||
par on greeting_service.node:
|
||||
res <- GreetingService.greeting(result.echo, greeting_service.greet). <-- update
|
||||
OpString.identity(res!5)
|
||||
<- res
|
||||
|
||||
func echo_greeting_par_inverse_greet(greet: bool, echo_service: EchoServiceInput, greeting_services: []GreetingServiceInput) -> []string:
|
||||
res: *string
|
||||
on echo_service.node:
|
||||
EchoService echo_service.service_id
|
||||
echo_results <- EchoService.echo(echo_service.names)
|
||||
|
||||
for greeting_service <- greeting_services:
|
||||
GreetingService greeting_service.service_id
|
||||
par on greeting_service.node:
|
||||
for result <- echo_results:
|
||||
res <- GreetingService.greeting(result.echo, greeting_service.greet) <-- update
|
||||
OpString.identity(res!3)
|
||||
<- res
|
||||
```
|
||||
|
||||
Run the workflow with the updated json string:
|
||||
|
||||
|
||||
```test
|
||||
fldist run_air
|
||||
-p aqua-compiled/echo_greeter.echo_greeting_par_greet.air \
|
||||
-d '{"echo_service":{"names":["jim", "john", "james"], \
|
||||
"node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id": "fb5f7126-e1ee-4ecf-81e7-20804cb7203b"},\
|
||||
"greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", \
|
||||
"service_id":"5a03906b-3217-40a2-93fb-7e83be735408", \
|
||||
"greet":true}, \
|
||||
{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede", \
|
||||
"greet":false}]}' \
|
||||
--generated
|
||||
```
|
||||
|
||||
Which gives us:
|
||||
|
||||
```text
|
||||
[
|
||||
[
|
||||
"Hi, jim",
|
||||
"Bye, jim",
|
||||
"Hi, john",
|
||||
"Bye, john",
|
||||
"Hi, james",
|
||||
"Bye, james"
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
And for the inverted loop version:
|
||||
|
||||
ldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE run_air -p aqua-compiled/utilities.increment_u64.air -d '{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"e23c2a8b-c3f2-4067-8e92-803691fdf5b7", "value":10, "step":3, "incr": true}' --generated
|
||||
```test
|
||||
fldist run_air \
|
||||
-p aqua-compiled/echo_greeter.echo_greeting_par_inverse_greet.air \
|
||||
-d '{"echo_service":{"names":["jim", "john", "james"],\
|
||||
"node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id": "fb5f7126-e1ee-4ecf-81e7-20804cb7203b"},\
|
||||
"greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",\
|
||||
"service_id":"5a03906b-3217-40a2-93fb-7e83be735408", \
|
||||
"greet":true},\
|
||||
{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", \
|
||||
"service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede", \
|
||||
"greet":false}]}' \
|
||||
--generated
|
||||
```
|
||||
|
||||
We get:
|
||||
|
||||
```test
|
||||
[
|
||||
{
|
||||
"err_msg": "",
|
||||
"value": 13
|
||||
}
|
||||
[
|
||||
"Hi, jim",
|
||||
"Hi, john",
|
||||
"Hi, james",
|
||||
"Bye, jim",
|
||||
"Bye, john",
|
||||
"Bye, james"
|
||||
]
|
||||
]
|
||||
mbp16~/localdev/examples-fork/echo-greeter/utilities(main↑1|✚3…) % fldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE run_air -p aqua-compiled/utilities.increment_u64.air -d '{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"e23c2a8b-c3f2-4067-8e92-803691fdf5b7", "value":10, "step":3, "incr": false}' --generated
|
||||
[
|
||||
{
|
||||
"err_msg": "",
|
||||
"value": 7
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
In this section, we explored how we can use Aqua to program hosted services into applications. Along the way, we investigated sequential and parallel workflows and discovered that changes in processing or workflow logic are taken care of at the Aqua level not requiring any changes to the deployed services. Throughout our experimentation with Aqua and deployed services, we used the `fldist` tool as our local cli client peer. In the next section, we introduce the develppment and use of a Typescript client peer.
|
||||
|
||||
|
||||
### Developing And Working With A Typescript Client
|
||||
|
||||
In the previous section we used `fldist` cli as our local peer client to run the execution of our compiled Aqua scripts on the network. Alternatively, Aqua code can be compiled to Typescript utilizing the Fluence [JS-SDK](https://github.com/fluencelabs/fluence-js).
|
||||
|
||||
Let's install the required packages:
|
||||
|
||||
```text
|
||||
% cd client-peer
|
||||
% npm install
|
||||
```
|
||||
|
||||
And compile our Aqua file to a Typescript stub:
|
||||
|
||||
```text
|
||||
% npm run compile-aqua
|
||||
|
||||
> echo-greeter-example@0.1.0 compile-aqua /Users/bebo/localdev/examples-rework/aqua-examples/echo-greeter/client-peer
|
||||
> aqua-cli -i ../aqua-scripts -o src/
|
||||
|
||||
java -jar /Users/bebo/localdev/examples-rework/aqua-examples/echo-greeter/client-peer/node_modules/@fluencelabs/aqua-cli/aqua-cli.jar -m node_modules -i ../aqua-scripts -o src/
|
||||
[info] Aqua Compiler 0.1.9-163
|
||||
[info] Result /Users/bebo/localdev/examples-rework/aqua-examples/echo-greeter/client-peer/src/echo_greeter.ts: compilation OK (6 functions)
|
||||
```
|
||||
|
||||
The ensuing, auto-generated file is called `echo_greeter.ts` and was copied to the `src` directory. Let's have a look:
|
||||
|
||||
```typescript
|
||||
// src/echo-greeter.ts
|
||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
||||
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_par_greet(client: FluenceClient, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {greet:boolean;node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
// <snip>
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_par_greet');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
// <snip>
|
||||
```
|
||||
|
||||
The Aqua compiler auto-generated the Typescript functions corresponding to each of the Aqua functions we implemented. All we have to do is use them!
|
||||
|
||||
Let's look at the simple `src/index.ts` implementation using each of the workflow functions:
|
||||
|
||||
|
||||
```typescript
|
||||
// src/index.ts
|
||||
|
||||
import { createClient, setLogLevel, FluenceClient } from "@fluencelabs/fluence";
|
||||
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
|
||||
import {
|
||||
echo_greeting_seq,
|
||||
echo_greeting_seq_2,
|
||||
echo_greeting_par,
|
||||
echo_greeting_par_inverse,
|
||||
echo_greeting_par_greet,
|
||||
echo_greeting_par_inverse_greet,
|
||||
} from "./echo_greeter";
|
||||
|
||||
interface NodeServicePair {
|
||||
node: string;
|
||||
service_id: string;
|
||||
}
|
||||
|
||||
interface EchoService {
|
||||
node: string;
|
||||
service_id: string;
|
||||
names: Array<string>;
|
||||
}
|
||||
|
||||
interface GreetingService {
|
||||
node: string;
|
||||
service_id: string;
|
||||
greet: boolean;
|
||||
}
|
||||
|
||||
let greeting_topos: Array<NodeServicePair> = [
|
||||
{
|
||||
node: "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
service_id: "5cf520ff-dd65-47d7-a51a-2bf08dfe2ede",
|
||||
},
|
||||
{
|
||||
node: "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
service_id: "5a03906b-3217-40a2-93fb-7e83be735408",
|
||||
},
|
||||
];
|
||||
|
||||
let echo_topos: Array<NodeServicePair> = [
|
||||
{
|
||||
node: "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
service_id: "fb5f7126-e1ee-4ecf-81e7-20804cb7203b",
|
||||
},
|
||||
{
|
||||
node: "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
service_id: "893a6fb8-43b9-4b11-8786-93300bd68bc8",
|
||||
},
|
||||
];
|
||||
|
||||
let echo_service: EchoService = {
|
||||
node: echo_topos[0].node,
|
||||
service_id: echo_topos[0].service_id,
|
||||
names: ["Jim", "John", "Jake"],
|
||||
};
|
||||
|
||||
let greeting_services: Array<GreetingService> = [
|
||||
{
|
||||
node: greeting_topos[0].node,
|
||||
service_id: greeting_topos[0].service_id,
|
||||
greet: true,
|
||||
},
|
||||
{
|
||||
node: greeting_topos[1].node,
|
||||
service_id: greeting_topos[1].service_id,
|
||||
greet: false,
|
||||
},
|
||||
];
|
||||
|
||||
let names: Array<string> = ["Jim", "John", "Jake"];
|
||||
|
||||
async function main() {
|
||||
// console.log("hello");
|
||||
// setLogLevel('DEBUG');
|
||||
|
||||
const fluence = await createClient(krasnodar[2]);
|
||||
console.log(
|
||||
"created a fluence client %s with relay %s",
|
||||
fluence.selfPeerId,
|
||||
fluence.relayPeerId
|
||||
);
|
||||
|
||||
let network_result = await echo_greeting_seq(
|
||||
fluence,
|
||||
names,
|
||||
true,
|
||||
echo_topos[0].node,
|
||||
echo_topos[0].service_id,
|
||||
greeting_topos[0].service_id
|
||||
);
|
||||
console.log("seq result : ", network_result);
|
||||
|
||||
|
||||
network_result = await echo_greeting_seq_2(
|
||||
fluence,
|
||||
names,
|
||||
true,
|
||||
echo_topos[0],
|
||||
greeting_topos[0]
|
||||
);
|
||||
console.log("seq result with improved signature : ", network_result);
|
||||
|
||||
// echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
|
||||
network_result = await echo_greeting_par(
|
||||
fluence,
|
||||
true,
|
||||
echo_service,
|
||||
greeting_topos
|
||||
);
|
||||
console.log("par result : ", network_result);
|
||||
|
||||
network_result = await echo_greeting_par_inverse(
|
||||
fluence,
|
||||
true,
|
||||
echo_service,
|
||||
greeting_services
|
||||
);
|
||||
console.log("par inverse result : ", network_result);
|
||||
|
||||
network_result = await echo_greeting_par_greet(
|
||||
fluence,
|
||||
echo_service,
|
||||
greeting_services
|
||||
);
|
||||
console.log("par result with greet variation : ", network_result);
|
||||
|
||||
network_result = await echo_greeting_par_inverse_greet(
|
||||
fluence,
|
||||
echo_service,
|
||||
greeting_services
|
||||
);
|
||||
console.log("par inverse result with greet variation : ", network_result);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
The client implementation
|
||||
|
||||
* Imports the necessary js-sdk
|
||||
* Imports the Fluence test network information
|
||||
* Imports the Aqua auto-generated workflow functions
|
||||
* Declares the node and service data and corresponding structs
|
||||
* Creates a client handler for our selected testnet and relay node
|
||||
* Runs and logs each of the workflow functions
|
||||
|
||||
|
||||
Let's run our client peer:
|
||||
|
||||
```text
|
||||
npm run start
|
||||
```
|
||||
|
||||
Which gives us the same results as before:
|
||||
|
||||
```text
|
||||
|
||||
created a fluence client 12D3KooWJa3k63oTRhyMAaW4LzGjHTVyThNoxM4i8yxFAZQqN7Q4 with relay 12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA
|
||||
seq result : [ 'Hi, Jim', 'Hi, John', 'Hi, Jake' ]
|
||||
seq result with improved signature : [ 'Hi, Jim', 'Hi, John', 'Hi, Jake' ]
|
||||
par result : [
|
||||
'Hi, Jim',
|
||||
'Hi, Jim',
|
||||
'Hi, John',
|
||||
'Hi, John',
|
||||
'Hi, Jake',
|
||||
'Hi, Jake'
|
||||
]
|
||||
par inverse result : [
|
||||
'Hi, Jim',
|
||||
'Hi, John',
|
||||
'Hi, Jake',
|
||||
'Hi, Jim',
|
||||
'Hi, John',
|
||||
'Hi, Jake'
|
||||
]
|
||||
par result with greet variation : [
|
||||
'Hi, Jim',
|
||||
'Bye, Jim',
|
||||
'Hi, John',
|
||||
'Bye, John',
|
||||
'Hi, Jake',
|
||||
'Bye, Jake'
|
||||
]
|
||||
par inverse result with greet variation : [
|
||||
'Hi, Jim',
|
||||
'Hi, John',
|
||||
'Hi, Jake',
|
||||
'Bye, Jim',
|
||||
'Bye, John',
|
||||
'Bye, Jake'
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call node (echo_service "echo") [names] res)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
@ -9,60 +9,63 @@
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [names] echo_results)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(fold echo_results result
|
||||
(par
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(xor
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
(xor
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[2]!])
|
||||
(next greeting_service)
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
(next result)
|
||||
)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[5]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
@ -0,0 +1,68 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greeting_service.$.greet!] $res)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[5]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
@ -0,0 +1,71 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[3]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
@ -0,0 +1,68 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greeting_service.$.greet!] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[3]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
@ -19,11 +19,14 @@
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_service_id") [] greeting_service_id)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call node (echo_service_id "echo") [names] echo_names)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call node (echo_service_id "echo") [names] echo_names)
|
||||
)
|
||||
(fold echo_names result
|
||||
(seq
|
||||
(call node (greeting_service_id "greeting") [result.$.echo! greet] $res)
|
||||
@ -32,23 +35,17 @@
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
@ -0,0 +1,57 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_topo") [] echo_topo)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_topo") [] greeting_topo)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_topo.$.node! (echo_topo.$.service_id! "echo") [names] echo_names)
|
||||
)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(fold echo_names result
|
||||
(seq
|
||||
(call greeting_topo.$.node! (greeting_topo.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
@ -1,43 +0,0 @@
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "name") [] name)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_service_id") [] greeting_service_id)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call node (greeting_service_id "greeting") [name greet] res)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
@ -1,300 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.1.6-146
|
||||
*
|
||||
*/
|
||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
||||
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
|
||||
|
||||
|
||||
|
||||
export async function echo(client: FluenceClient, names: string[], node: string, echo_service: string, config?: {ttl?: number}): Promise<{echo:string}[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<{echo:string}[]>((resolve, reject) => {
|
||||
request = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withTTL(config?.ttl || 5000)
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call node (echo_service "echo") [names] res)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'names', () => {return names;});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo');
|
||||
})
|
||||
.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_seq(client: FluenceClient, names: string[], greet: boolean, node: string, echo_service_id: string, greeting_service_id: string, config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
request = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withTTL(config?.ttl || 5000)
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service_id") [] echo_service_id)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_service_id") [] greeting_service_id)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call node (echo_service_id "echo") [names] echo_names)
|
||||
(fold echo_names result
|
||||
(seq
|
||||
(call node ("service-id" "greeting") [result.$.echo! greet] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'names', () => {return names;});
|
||||
h.on('getDataSrv', 'greet', () => {return greet;});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.on('getDataSrv', 'echo_service_id', () => {return echo_service_id;});
|
||||
h.on('getDataSrv', 'greeting_service_id', () => {return greeting_service_id;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_seq');
|
||||
})
|
||||
.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_par(client: FluenceClient, names: string[], greet: boolean, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
request = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withTTL(config?.ttl || 5000)
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(xor
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [names] echo_results)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "identity") [])
|
||||
)
|
||||
(fold echo_results result
|
||||
(par
|
||||
(fold greeting_services greeting_service
|
||||
(par
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(xor
|
||||
(seq
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(call greeting_service.$.node! ("op" "identity") [$res.$.[19]!])
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "identity") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'names', () => {return names;});
|
||||
h.on('getDataSrv', 'greet', () => {return greet;});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_par');
|
||||
})
|
||||
.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
178
aqua-examples/echo-greeter/client-peer/dist/aqua-compiled/echo_greeter.js
vendored
Normal file
178
aqua-examples/echo-greeter/client-peer/dist/aqua-compiled/echo_greeter.js
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.echo_greeting_par = exports.echo_greeting_seq_2 = exports.echo_greeting_seq = void 0;
|
||||
var api_unstable_1 = require("@fluencelabs/fluence/dist/api.unstable");
|
||||
function echo_greeting_seq(client, names, greet, node, echo_service_id, greeting_service_id, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service_id\") [] echo_service_id)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_service_id\") [] greeting_service_id)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call node (echo_service_id \"echo\") [names] echo_names)\n )\n (fold echo_names result\n (seq\n (call node (greeting_service_id \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'node', function () { return node; });
|
||||
h.on('getDataSrv', 'echo_service_id', function () { return echo_service_id; });
|
||||
h.on('getDataSrv', 'greeting_service_id', function () { return greeting_service_id; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq = echo_greeting_seq;
|
||||
function echo_greeting_seq_2(client, names, greet, echo_topo, greeting_topo, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_topo\") [] echo_topo)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_topo\") [] greeting_topo)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_topo.$.node! (echo_topo.$.service_id! \"echo\") [names] echo_names)\n )\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n )\n )\n (xor\n (fold echo_names result\n (seq\n (call greeting_topo.$.node! (greeting_topo.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_topo', function () { return echo_topo; });
|
||||
h.on('getDataSrv', 'greeting_topo', function () { return greeting_topo; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq_2');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq_2 = echo_greeting_seq_2;
|
||||
function echo_greeting_par(client, greet, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold echo_results result\n (seq\n (fold greeting_services greeting_service\n (seq\n (seq\n (xor\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n (next result)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[2]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par = echo_greeting_par;
|
178
aqua-examples/echo-greeter/client-peer/dist/aqua/echo_greeter.js
vendored
Normal file
178
aqua-examples/echo-greeter/client-peer/dist/aqua/echo_greeter.js
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.echo_greeting_par = exports.echo_greeting_seq_2 = exports.echo_greeting_seq = void 0;
|
||||
var api_unstable_1 = require("@fluencelabs/fluence/dist/api.unstable");
|
||||
function echo_greeting_seq(client, names, greet, node, echo_service_id, greeting_service_id, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service_id\") [] echo_service_id)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_service_id\") [] greeting_service_id)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call node (echo_service_id \"echo\") [names] echo_names)\n )\n (fold echo_names result\n (seq\n (call node (greeting_service_id \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'node', function () { return node; });
|
||||
h.on('getDataSrv', 'echo_service_id', function () { return echo_service_id; });
|
||||
h.on('getDataSrv', 'greeting_service_id', function () { return greeting_service_id; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq = echo_greeting_seq;
|
||||
function echo_greeting_seq_2(client, names, greet, echo_topo, greeting_topo, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_topo\") [] echo_topo)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_topo\") [] greeting_topo)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_topo.$.node! (echo_topo.$.service_id! \"echo\") [names] echo_names)\n )\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n )\n )\n (xor\n (fold echo_names result\n (seq\n (call greeting_topo.$.node! (greeting_topo.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_topo', function () { return echo_topo; });
|
||||
h.on('getDataSrv', 'greeting_topo', function () { return greeting_topo; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq_2');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq_2 = echo_greeting_seq_2;
|
||||
function echo_greeting_par(client, greet, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold echo_results result\n (seq\n (fold greeting_services greeting_service\n (seq\n (seq\n (xor\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n (next result)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[2]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par = echo_greeting_par;
|
84
aqua-examples/echo-greeter/client-peer/dist/client-peer/src/index.js
vendored
Normal file
84
aqua-examples/echo-greeter/client-peer/dist/client-peer/src/index.js
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fluence_1 = require("@fluencelabs/fluence");
|
||||
var fluence_network_environment_1 = require("@fluencelabs/fluence-network-environment");
|
||||
var greeting_services = [{ "node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id": "fb5f7126-e1ee-4ecf-81e7-20804cb7203b" }, { "node": "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id": "893a6fb8-43b9-4b11-8786-93300bd68bc8" }];
|
||||
var echo_services = [{ "node": "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id": "5cf520ff-dd65-47d7-a51a-2bf08dfe2ede" }, { "node": "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id": "5a03906b-3217-40a2-93fb-7e83be735408" }];
|
||||
var names = ["Jim", "John", "Jake"];
|
||||
// let greeting_service =
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var fluence;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fluence_1.createClient(fluence_network_environment_1.krasnodar[2])];
|
||||
case 1:
|
||||
fluence = _a.sent();
|
||||
console.log("created a fluence client %s with relay %s", fluence.selfPeerId, fluence.relayPeerId);
|
||||
//func echo_greeting_seq(names: []string, greet: bool, node: string, echo_service_id: string, greeting_service_id: string) -> []string:
|
||||
// const network_result = await echo_greeting_seq(fluence, names, true, echo_services[0].node, echo_services[0].service_id, greeting_services[0].service_id);
|
||||
// console.log("seq result: ", network_result);
|
||||
// const network_result_par = await get_price_par(fluence, "ethereum", "usd", getter_topo, mean_topo);
|
||||
// console.log("par result: ", network_result_par);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
main()
|
||||
.then(function () { return process.exit(0); })
|
||||
.catch(function (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
178
aqua-examples/echo-greeter/client-peer/dist/echo_greeter.js
vendored
Normal file
178
aqua-examples/echo-greeter/client-peer/dist/echo_greeter.js
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.echo_greeting_par = exports.echo_greeting_seq_2 = exports.echo_greeting_seq = void 0;
|
||||
var api_unstable_1 = require("@fluencelabs/fluence/dist/api.unstable");
|
||||
function echo_greeting_seq(client, names, greet, node, echo_service_id, greeting_service_id, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service_id\") [] echo_service_id)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_service_id\") [] greeting_service_id)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call node (echo_service_id \"echo\") [names] echo_names)\n )\n (fold echo_names result\n (seq\n (call node (greeting_service_id \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'node', function () { return node; });
|
||||
h.on('getDataSrv', 'echo_service_id', function () { return echo_service_id; });
|
||||
h.on('getDataSrv', 'greeting_service_id', function () { return greeting_service_id; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq = echo_greeting_seq;
|
||||
function echo_greeting_seq_2(client, names, greet, echo_topo, greeting_topo, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_topo\") [] echo_topo)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_topo\") [] greeting_topo)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_topo.$.node! (echo_topo.$.service_id! \"echo\") [names] echo_names)\n )\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n )\n )\n (xor\n (fold echo_names result\n (seq\n (call greeting_topo.$.node! (greeting_topo.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_topo', function () { return echo_topo; });
|
||||
h.on('getDataSrv', 'greeting_topo', function () { return greeting_topo; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq_2');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq_2 = echo_greeting_seq_2;
|
||||
function echo_greeting_par(client, greet, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold echo_results result\n (seq\n (fold greeting_services greeting_service\n (seq\n (seq\n (xor\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n (next result)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[2]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par = echo_greeting_par;
|
311
aqua-examples/echo-greeter/client-peer/dist/src/echo_greeter.js
vendored
Normal file
311
aqua-examples/echo-greeter/client-peer/dist/src/echo_greeter.js
vendored
Normal file
@ -0,0 +1,311 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.echo_greeting_par_inverse_greet = exports.echo_greeting_seq_2 = exports.echo_greeting_seq = exports.echo_greeting_par_inverse = exports.echo_greeting_par = exports.echo_greeting_par_greet = void 0;
|
||||
var api_unstable_1 = require("@fluencelabs/fluence/dist/api.unstable");
|
||||
function echo_greeting_par_greet(client, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold echo_results result\n (seq\n (fold greeting_services greeting_service\n (seq\n (seq\n (par\n (seq\n (seq\n (xor\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greeting_service.$.greet!] $res)\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (call %init_peer_id% (\"op\" \"noop\") [])\n )\n (null)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n (next result)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[5]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par_greet');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par_greet = echo_greeting_par_greet;
|
||||
function echo_greeting_par(client, greet, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold echo_results result\n (seq\n (fold greeting_services greeting_service\n (seq\n (seq\n (par\n (seq\n (seq\n (xor\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (call %init_peer_id% (\"op\" \"noop\") [])\n )\n (null)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n (next result)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[5]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par = echo_greeting_par;
|
||||
function echo_greeting_par_inverse(client, greet, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold greeting_services greeting_service\n (seq\n (seq\n (par\n (seq\n (seq\n (xor\n (fold echo_results result\n (seq\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (call %init_peer_id% (\"op\" \"noop\") [])\n )\n (null)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[3]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par_inverse');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par_inverse = echo_greeting_par_inverse;
|
||||
function echo_greeting_seq(client, names, greet, node, echo_service_id, greeting_service_id, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"node\") [] node)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_service_id\") [] echo_service_id)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_service_id\") [] greeting_service_id)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call node (echo_service_id \"echo\") [names] echo_names)\n )\n (fold echo_names result\n (seq\n (call node (greeting_service_id \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'node', function () { return node; });
|
||||
h.on('getDataSrv', 'echo_service_id', function () { return echo_service_id; });
|
||||
h.on('getDataSrv', 'greeting_service_id', function () { return greeting_service_id; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq = echo_greeting_seq;
|
||||
function echo_greeting_seq_2(client, names, greet, echo_topo, greeting_topo, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"names\") [] names)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greet\") [] greet)\n )\n (call %init_peer_id% (\"getDataSrv\" \"echo_topo\") [] echo_topo)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_topo\") [] greeting_topo)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_topo.$.node! (echo_topo.$.service_id! \"echo\") [names] echo_names)\n )\n (seq\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n )\n )\n (xor\n (fold echo_names result\n (seq\n (call greeting_topo.$.node! (greeting_topo.$.service_id! \"greeting\") [result.$.echo! greet] $res)\n (next result)\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'names', function () { return names; });
|
||||
h.on('getDataSrv', 'greet', function () { return greet; });
|
||||
h.on('getDataSrv', 'echo_topo', function () { return echo_topo; });
|
||||
h.on('getDataSrv', 'greeting_topo', function () { return greeting_topo; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_seq_2');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_seq_2 = echo_greeting_seq_2;
|
||||
function echo_greeting_par_inverse_greet(client, echo_service, greeting_services, config) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var request, promise;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
promise = new Promise(function (resolve, reject) {
|
||||
var r = new api_unstable_1.RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript("\n(xor\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (seq\n (call %init_peer_id% (\"getDataSrv\" \"-relay-\") [] -relay-)\n (call %init_peer_id% (\"getDataSrv\" \"echo_service\") [] echo_service)\n )\n (call %init_peer_id% (\"getDataSrv\" \"greeting_services\") [] greeting_services)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (xor\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call echo_service.$.node! (echo_service.$.service_id! \"echo\") [echo_service.$.names!] echo_results)\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 1])\n )\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (fold greeting_services greeting_service\n (seq\n (seq\n (par\n (seq\n (seq\n (xor\n (fold echo_results result\n (seq\n (call greeting_service.$.node! (greeting_service.$.service_id! \"greeting\") [result.$.echo! greeting_service.$.greet!] $res)\n (next result)\n )\n )\n (seq\n (call -relay- (\"op\" \"noop\") [])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 2])\n )\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (call %init_peer_id% (\"op\" \"noop\") [])\n )\n (null)\n )\n (call -relay- (\"op\" \"noop\") [])\n )\n (next greeting_service)\n )\n )\n )\n (call %init_peer_id% (\"op\" \"identity\") [$res.$.[3]!])\n )\n (xor\n (call %init_peer_id% (\"callbackSrv\" \"response\") [$res])\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 3])\n )\n )\n (call %init_peer_id% (\"errorHandlingSrv\" \"error\") [%last_error% 4])\n)\n\n ")
|
||||
.configHandler(function (h) {
|
||||
h.on('getDataSrv', '-relay-', function () {
|
||||
return client.relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'echo_service', function () { return echo_service; });
|
||||
h.on('getDataSrv', 'greeting_services', function () { return greeting_services; });
|
||||
h.onEvent('callbackSrv', 'response', function (args) {
|
||||
var res = args[0];
|
||||
resolve(res);
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', function (args) {
|
||||
// assuming error is the single argument
|
||||
var err = args[0];
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(function () {
|
||||
reject('Request timed out for echo_greeting_par_inverse_greet');
|
||||
});
|
||||
if (config === null || config === void 0 ? void 0 : config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
return [4 /*yield*/, client.initiateFlow(request)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, promise];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.echo_greeting_par_inverse_greet = echo_greeting_par_inverse_greet;
|
140
aqua-examples/echo-greeter/client-peer/dist/src/index.js
vendored
Normal file
140
aqua-examples/echo-greeter/client-peer/dist/src/index.js
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fluence_1 = require("@fluencelabs/fluence");
|
||||
var fluence_network_environment_1 = require("@fluencelabs/fluence-network-environment");
|
||||
var echo_greeter_1 = require("./echo_greeter");
|
||||
var greeting_topos = [
|
||||
{
|
||||
node: "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
service_id: "5cf520ff-dd65-47d7-a51a-2bf08dfe2ede",
|
||||
},
|
||||
{
|
||||
node: "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
service_id: "5a03906b-3217-40a2-93fb-7e83be735408",
|
||||
},
|
||||
];
|
||||
var echo_topos = [
|
||||
{
|
||||
node: "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
service_id: "fb5f7126-e1ee-4ecf-81e7-20804cb7203b",
|
||||
},
|
||||
{
|
||||
node: "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
service_id: "893a6fb8-43b9-4b11-8786-93300bd68bc8",
|
||||
},
|
||||
];
|
||||
var echo_service = {
|
||||
node: echo_topos[0].node,
|
||||
service_id: echo_topos[0].service_id,
|
||||
names: ["Jim", "John", "Jake"],
|
||||
};
|
||||
var greeting_services = [
|
||||
{
|
||||
node: greeting_topos[0].node,
|
||||
service_id: greeting_topos[0].service_id,
|
||||
greet: true,
|
||||
},
|
||||
{
|
||||
node: greeting_topos[1].node,
|
||||
service_id: greeting_topos[1].service_id,
|
||||
greet: false,
|
||||
},
|
||||
];
|
||||
var names = ["Jim", "John", "Jake"];
|
||||
// let greeting_service =
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var fluence, network_result;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fluence_1.createClient(fluence_network_environment_1.krasnodar[2])];
|
||||
case 1:
|
||||
fluence = _a.sent();
|
||||
console.log("created a fluence client %s with relay %s", fluence.selfPeerId, fluence.relayPeerId);
|
||||
return [4 /*yield*/, echo_greeter_1.echo_greeting_seq(fluence, names, true, echo_topos[0].node, echo_topos[0].service_id, greeting_topos[0].service_id)];
|
||||
case 2:
|
||||
network_result = _a.sent();
|
||||
console.log("seq result : ", network_result);
|
||||
return [4 /*yield*/, echo_greeter_1.echo_greeting_seq_2(fluence, names, true, echo_topos[0], greeting_topos[0])];
|
||||
case 3:
|
||||
network_result = _a.sent();
|
||||
console.log("seq result with improved signature : ", network_result);
|
||||
return [4 /*yield*/, echo_greeter_1.echo_greeting_par(fluence, true, echo_service, greeting_topos)];
|
||||
case 4:
|
||||
// echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
|
||||
network_result = _a.sent();
|
||||
console.log("par result : ", network_result);
|
||||
return [4 /*yield*/, echo_greeter_1.echo_greeting_par_inverse(fluence, true, echo_service, greeting_services)];
|
||||
case 5:
|
||||
network_result = _a.sent();
|
||||
console.log("par inverse result : ", network_result);
|
||||
return [4 /*yield*/, echo_greeter_1.echo_greeting_par_greet(fluence, echo_service, greeting_services)];
|
||||
case 6:
|
||||
network_result = _a.sent();
|
||||
console.log("par result with greet variation : ", network_result);
|
||||
return [4 /*yield*/, echo_greeter_1.echo_greeting_par_inverse_greet(fluence, echo_service, greeting_services)];
|
||||
case 7:
|
||||
network_result = _a.sent();
|
||||
console.log("par inverse result with greet variation : ", network_result);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
main()
|
||||
.then(function () { return process.exit(0); })
|
||||
.catch(function (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
3060
aqua-examples/echo-greeter/client-peer/package-lock.json
generated
Normal file
3060
aqua-examples/echo-greeter/client-peer/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
aqua-examples/echo-greeter/client-peer/package.json
Normal file
49
aqua-examples/echo-greeter/client-peer/package.json
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "echo-greeter-example",
|
||||
"version": "0.1.0",
|
||||
"description": "Fluence Echo Greeter Example",
|
||||
"main": "./dist/src/index.js",
|
||||
"typings": "./dist/src/index.d.ts",
|
||||
"files": [
|
||||
"dist/*"
|
||||
],
|
||||
"bic": [
|
||||
"client-peer/*",
|
||||
"*.aqua",
|
||||
"package-lock.json"
|
||||
],
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-lib": "^0.1.9",
|
||||
"@fluencelabs/fluence": "^0.9.53",
|
||||
"@fluencelabs/fluence-network-environment": "^1.0.10",
|
||||
"it-all": "^1.0.5"
|
||||
},
|
||||
"scripts": {
|
||||
"compile-aqua": "aqua-cli -i ../aqua-scripts -o src/",
|
||||
"prebuild": "npm run compile-aqua",
|
||||
"build": "tsc",
|
||||
"prestart:local": "npm run build",
|
||||
"start:local": "node dist/src/index.js local",
|
||||
"prestart:remote": "npm run build",
|
||||
"start:remote": "node dist/src/index.js krasnodar",
|
||||
"start": "npm run start:remote"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/fluencelabs/examples/aqua-examples/echo-greeter"
|
||||
},
|
||||
"keywords": [
|
||||
"aqua",
|
||||
"fluence"
|
||||
],
|
||||
"author": "Fluence Labs",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "git+https://github.com/fluencelabs/examples/issues"
|
||||
},
|
||||
"homepage": "git+https://github.com/fluencelabs/examples/aqua-examples/echo-greeter#readme",
|
||||
"devDependencies": {
|
||||
"@fluencelabs/aqua-cli": "0.1.9-163",
|
||||
"typescript": "^3.9.5"
|
||||
}
|
||||
}
|
657
aqua-examples/echo-greeter/client-peer/src/echo_greeter.ts
Normal file
657
aqua-examples/echo-greeter/client-peer/src/echo_greeter.ts
Normal file
@ -0,0 +1,657 @@
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.1.9-163
|
||||
*
|
||||
*/
|
||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
||||
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_par_greet(client: FluenceClient, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {greet:boolean;node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greeting_service.$.greet!] $res)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[5]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_par_greet');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_par(client: FluenceClient, greet: boolean, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[5]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', () => {return greet;});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_par');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_par_inverse(client: FluenceClient, greet: boolean, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[3]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'greet', () => {return greet;});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_par_inverse');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_seq(client: FluenceClient, names: string[], greet: boolean, node: string, echo_service_id: string, greeting_service_id: string, config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "node") [] node)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service_id") [] echo_service_id)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_service_id") [] greeting_service_id)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call node (echo_service_id "echo") [names] echo_names)
|
||||
)
|
||||
(fold echo_names result
|
||||
(seq
|
||||
(call node (greeting_service_id "greeting") [result.$.echo! greet] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'names', () => {return names;});
|
||||
h.on('getDataSrv', 'greet', () => {return greet;});
|
||||
h.on('getDataSrv', 'node', () => {return node;});
|
||||
h.on('getDataSrv', 'echo_service_id', () => {return echo_service_id;});
|
||||
h.on('getDataSrv', 'greeting_service_id', () => {return greeting_service_id;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_seq');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_seq_2(client: FluenceClient, names: string[], greet: boolean, echo_topo: {node:string;service_id:string}, greeting_topo: {node:string;service_id:string}, config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "names") [] names)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greet") [] greet)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_topo") [] echo_topo)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_topo") [] greeting_topo)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_topo.$.node! (echo_topo.$.service_id! "echo") [names] echo_names)
|
||||
)
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(fold echo_names result
|
||||
(seq
|
||||
(call greeting_topo.$.node! (greeting_topo.$.service_id! "greeting") [result.$.echo! greet] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'names', () => {return names;});
|
||||
h.on('getDataSrv', 'greet', () => {return greet;});
|
||||
h.on('getDataSrv', 'echo_topo', () => {return echo_topo;});
|
||||
h.on('getDataSrv', 'greeting_topo', () => {return greeting_topo;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_seq_2');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function echo_greeting_par_inverse_greet(client: FluenceClient, echo_service: {names:string[];node:string;service_id:string}, greeting_services: {greet:boolean;node:string;service_id:string}[], config?: {ttl?: number}): Promise<string[]> {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<string[]>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "echo_service") [] echo_service)
|
||||
)
|
||||
(call %init_peer_id% ("getDataSrv" "greeting_services") [] greeting_services)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call echo_service.$.node! (echo_service.$.service_id! "echo") [echo_service.$.names!] echo_results)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(fold greeting_services greeting_service
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(xor
|
||||
(fold echo_results result
|
||||
(seq
|
||||
(call greeting_service.$.node! (greeting_service.$.service_id! "greeting") [result.$.echo! greeting_service.$.greet!] $res)
|
||||
(next result)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(call %init_peer_id% ("op" "noop") [])
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(next greeting_service)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("op" "identity") [$res.$.[3]!])
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [$res])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
|
||||
)
|
||||
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return client.relayPeerId!;
|
||||
});
|
||||
h.on('getDataSrv', 'echo_service', () => {return echo_service;});
|
||||
h.on('getDataSrv', 'greeting_services', () => {return greeting_services;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
const [res] = args;
|
||||
resolve(res);
|
||||
});
|
||||
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
// assuming error is the single argument
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for echo_greeting_par_inverse_greet');
|
||||
})
|
||||
if(config?.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
request = r.build();
|
||||
});
|
||||
await client.initiateFlow(request!);
|
||||
return promise;
|
||||
}
|
||||
|
158
aqua-examples/echo-greeter/client-peer/src/index.ts
Normal file
158
aqua-examples/echo-greeter/client-peer/src/index.ts
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createClient, setLogLevel, FluenceClient } from "@fluencelabs/fluence";
|
||||
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
|
||||
import {
|
||||
echo_greeting_seq,
|
||||
echo_greeting_seq_2,
|
||||
echo_greeting_par,
|
||||
echo_greeting_par_inverse,
|
||||
echo_greeting_par_greet,
|
||||
echo_greeting_par_inverse_greet,
|
||||
} from "./echo_greeter";
|
||||
|
||||
interface NodeServicePair {
|
||||
node: string;
|
||||
service_id: string;
|
||||
}
|
||||
|
||||
interface EchoService {
|
||||
node: string;
|
||||
service_id: string;
|
||||
names: Array<string>;
|
||||
}
|
||||
|
||||
interface GreetingService {
|
||||
node: string;
|
||||
service_id: string;
|
||||
greet: boolean;
|
||||
}
|
||||
|
||||
let greeting_topos: Array<NodeServicePair> = [
|
||||
{
|
||||
node: "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
service_id: "5cf520ff-dd65-47d7-a51a-2bf08dfe2ede",
|
||||
},
|
||||
{
|
||||
node: "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
service_id: "5a03906b-3217-40a2-93fb-7e83be735408",
|
||||
},
|
||||
];
|
||||
let echo_topos: Array<NodeServicePair> = [
|
||||
{
|
||||
node: "12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt",
|
||||
service_id: "fb5f7126-e1ee-4ecf-81e7-20804cb7203b",
|
||||
},
|
||||
{
|
||||
node: "12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE",
|
||||
service_id: "893a6fb8-43b9-4b11-8786-93300bd68bc8",
|
||||
},
|
||||
];
|
||||
let echo_service: EchoService = {
|
||||
node: echo_topos[0].node,
|
||||
service_id: echo_topos[0].service_id,
|
||||
names: ["Jim", "John", "Jake"],
|
||||
};
|
||||
let greeting_services: Array<GreetingService> = [
|
||||
{
|
||||
node: greeting_topos[0].node,
|
||||
service_id: greeting_topos[0].service_id,
|
||||
greet: true,
|
||||
},
|
||||
{
|
||||
node: greeting_topos[1].node,
|
||||
service_id: greeting_topos[1].service_id,
|
||||
greet: false,
|
||||
},
|
||||
];
|
||||
|
||||
let names: Array<string> = ["Jim", "John", "Jake"];
|
||||
|
||||
// let greeting_service =
|
||||
|
||||
async function main() {
|
||||
// console.log("hello");
|
||||
// setLogLevel('DEBUG');
|
||||
|
||||
const fluence = await createClient(krasnodar[2]);
|
||||
console.log(
|
||||
"created a fluence client %s with relay %s",
|
||||
fluence.selfPeerId,
|
||||
fluence.relayPeerId
|
||||
);
|
||||
|
||||
let network_result = await echo_greeting_seq(
|
||||
fluence,
|
||||
names,
|
||||
true,
|
||||
echo_topos[0].node,
|
||||
echo_topos[0].service_id,
|
||||
greeting_topos[0].service_id
|
||||
);
|
||||
console.log("seq result : ", network_result);
|
||||
|
||||
|
||||
network_result = await echo_greeting_seq_2(
|
||||
fluence,
|
||||
names,
|
||||
true,
|
||||
echo_topos[0],
|
||||
greeting_topos[0]
|
||||
);
|
||||
console.log("seq result with improved signature : ", network_result);
|
||||
|
||||
// echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
|
||||
network_result = await echo_greeting_par(
|
||||
fluence,
|
||||
true,
|
||||
echo_service,
|
||||
greeting_topos
|
||||
);
|
||||
console.log("par result : ", network_result);
|
||||
|
||||
network_result = await echo_greeting_par_inverse(
|
||||
fluence,
|
||||
true,
|
||||
echo_service,
|
||||
greeting_services
|
||||
);
|
||||
console.log("par inverse result : ", network_result);
|
||||
|
||||
network_result = await echo_greeting_par_greet(
|
||||
fluence,
|
||||
echo_service,
|
||||
greeting_services
|
||||
);
|
||||
console.log("par result with greet variation : ", network_result);
|
||||
|
||||
network_result = await echo_greeting_par_inverse_greet(
|
||||
fluence,
|
||||
echo_service,
|
||||
greeting_services
|
||||
);
|
||||
console.log("par inverse result with greet variation : ", network_result);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
62
aqua-examples/echo-greeter/client-peer/tsconfig.json
Normal file
62
aqua-examples/echo-greeter/client-peer/tsconfig.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
"rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
112
aqua-examples/echo-greeter/data/service_info.txt
Normal file
112
aqua-examples/echo-greeter/data/service_info.txt
Normal file
@ -0,0 +1,112 @@
|
||||
Echo-Service
|
||||
peer service-id client-seed name
|
||||
12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
|
||||
fb5f7126-e1ee-4ecf-81e7-20804cb7203b
|
||||
CXFpzXPC2WUpoME3jBX7F53dorK15bcux9Wmt52Geprn
|
||||
|
||||
12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
893a6fb8-43b9-4b11-8786-93300bd68bc8
|
||||
CUwsEyKop4rR8mwfGiu8qPZHCzAjKnA7LQGd1VFHAVgM
|
||||
|
||||
|
||||
Greeting-Service
|
||||
peer service-id client-seed name
|
||||
12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
5a03906b-3217-40a2-93fb-7e83be735408
|
||||
4X9p5vRWqS9rxgPop9C3p6fn1TpHGxRxTe9dga1NN77R
|
||||
|
||||
|
||||
12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
|
||||
5cf520ff-dd65-47d7-a51a-2bf08dfe2ede
|
||||
2nypBDAGsxgft4TrQgBupJ3smoaRbkiYjC2MqTzSBRw1
|
||||
|
||||
|
||||
|
||||
Utilities-Service
|
||||
peer service-id client-seed name
|
||||
12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt
|
||||
abeaf9ef-c5c0-46ef-92eb-de605eb86ffd
|
||||
BvVwn1X36j5UGttGRdxQfJ1zFqMsAivLzXY6sdkbv2mx
|
||||
|
||||
12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE
|
||||
e23c2a8b-c3f2-4067-8e92-803691fdf5b7
|
||||
7SDxZerQxQCFjivromanTurV3UNj7Up4cdh9ZxXWwX5e
|
||||
|
||||
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.echo_greeting_seq.air -d '{"names":["1", "2", "3"],"echo_service_id":"893a6fb8-43b9-4b11-8786-93300bd68bc8", "greeting_service_id":"5a03906b-3217-40a2-93fb-7e83be735408", "greet": false, "node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE"}' --generated
|
||||
[
|
||||
[
|
||||
"Bye, 1",
|
||||
"Bye, 2",
|
||||
"Bye, 3"
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.echo_greeting_par.air -d '{"names": ["n1", "n2", "n3"], "greet": true, "echo_service":{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}, "greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"5a03906b-3217-40a2-93fb-7e83be735408"},{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede"}]}' --generated
|
||||
[
|
||||
[]
|
||||
]
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.greeting.air -d '{"name":"boo", "node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "greeting_service_id":"5a03906b-3217-40a2-93fb-7e83be735408", "greet":true}' --generated
|
||||
[
|
||||
"Hi, boo"
|
||||
]
|
||||
|
||||
func echo_greeting_seq(names: []string, greet: bool, node: string, echo_service_id: string,greeting_service_id: string) -> []string:
|
||||
fldist run_air -p aqua-compiled/echo_greeter.greeting_seq.air -d '{"names":["jim", "john", "james"],"greet": "true", "node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "greeting_service_id":"5a03906b-3217-40a2-93fb-7e83be735408"}' --generated
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fldist run_air -p aqua-compiled/echo_greeter.echo_greeting_par.air -d '{"names": ["n1", "n2", "n3"], "greet": true, "echo_service":{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"fb5f7126-e1ee-4ecf-81e7-20804cb7203b"}, "greeting_services":[{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"5a03906b-3217-40a2-93fb-7e83be735408"},{"node":"12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt", "service_id":"5cf520ff-dd65-47d7-a51a-2bf08dfe2ede"}]}' --generated
|
||||
[
|
||||
[
|
||||
"Hi, n1",
|
||||
"Hi, n2",
|
||||
"Hi, n3",
|
||||
"Hi, n3"
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
fldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE run_air -p aqua-compiled/utilities.splitter.air -d '{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"e23c2a8b-c3f2-4067-8e92-803691fdf5b7", "array":[1,2,3,4,5,6,7,8,9], "chunk_size": 3 }' --generated
|
||||
[
|
||||
[
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5,
|
||||
6
|
||||
],
|
||||
[
|
||||
7,
|
||||
8,
|
||||
9
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
ldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE run_air -p aqua-compiled/utilities.increment_u64.air -d '{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"e23c2a8b-c3f2-4067-8e92-803691fdf5b7", "value":10, "step":3, "incr": true}' --generated
|
||||
[
|
||||
{
|
||||
"err_msg": "",
|
||||
"value": 13
|
||||
}
|
||||
]
|
||||
mbp16~/localdev/examples-fork/echo-greeter/utilities(main↑1|✚3…) % fldist --node-id 12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE run_air -p aqua-compiled/utilities.increment_u64.air -d '{"node":"12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE", "service_id":"e23c2a8b-c3f2-4067-8e92-803691fdf5b7", "value":10, "step":3, "incr": false}' --generated
|
||||
[
|
||||
{
|
||||
"err_msg": "",
|
||||
"value": 7
|
||||
}
|
||||
]
|
@ -1,10 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
|
||||
# This script builds all subprojects and puts all created Wasm modules in one dir
|
||||
mkdir -p artifacts
|
||||
rm -f artifacts/*.wasm
|
||||
|
||||
cargo update --aggressive
|
||||
marine build --release
|
||||
|
||||
rm -f artifacts/*.wasm
|
||||
|
||||
cp target/wasm32-wasi/release/greeting.wasm artifacts/
|
||||
|
Loading…
Reference in New Issue
Block a user