mirror of
https://github.com/fluencelabs/examples
synced 2025-04-05 01:21:11 +00:00
add auqa scripts and compile targets
This commit is contained in:
parent
77a5732c16
commit
b54fef466c
13
echo-greeter/aqua-compiled/air/echo.echo.air
Normal file
13
echo-greeter/aqua-compiled/air/echo.echo.air
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "data") [] data)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("service-id" "echo") [data] res)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
|
||||||
|
)
|
16
echo-greeter/aqua-compiled/air/greeter.greeting.air
Normal file
16
echo-greeter/aqua-compiled/air/greeter.greeting.air
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "name") [] name)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "greeter") [] greeter)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("service-id" "greeting") [name greeter] res)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
|
||||||
|
)
|
64
echo-greeter/aqua-compiled/ts/echo.ts
Normal file
64
echo-greeter/aqua-compiled/ts/echo.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function echo(client: FluenceClient, data: string[]): Promise<string[]> {
|
||||||
|
let request;
|
||||||
|
const promise = new Promise<string[]>((resolve, reject) => {
|
||||||
|
request = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "data") [] data)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("service-id" "echo") [data] res)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', 'relay', () => {
|
||||||
|
return client.relayPeerId!;
|
||||||
|
});
|
||||||
|
h.on('getRelayService', 'hasReleay', () => {// Not Used
|
||||||
|
return client.relayPeerId !== undefined;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'data', () => {return data;});
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
68
echo-greeter/aqua-compiled/ts/greeter.ts
Normal file
68
echo-greeter/aqua-compiled/ts/greeter.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function greeting(client: FluenceClient, name: string, greeter: boolean): Promise<string> {
|
||||||
|
let request;
|
||||||
|
const promise = new Promise<string>((resolve, reject) => {
|
||||||
|
request = new RequestFlowBuilder()
|
||||||
|
.disableInjections()
|
||||||
|
.withRawScript(
|
||||||
|
`
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "name") [] name)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("getDataSrv" "greeter") [] greeter)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("service-id" "greeting") [name greeter] res)
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||||
|
)
|
||||||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
|
||||||
|
)
|
||||||
|
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.configHandler((h) => {
|
||||||
|
h.on('getDataSrv', 'relay', () => {
|
||||||
|
return client.relayPeerId!;
|
||||||
|
});
|
||||||
|
h.on('getRelayService', 'hasReleay', () => {// Not Used
|
||||||
|
return client.relayPeerId !== undefined;
|
||||||
|
});
|
||||||
|
h.on('getDataSrv', 'name', () => {return name;});
|
||||||
|
h.on('getDataSrv', 'greeter', () => {return greeter;});
|
||||||
|
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 greeting');
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
});
|
||||||
|
await client.initiateFlow(request);
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
6
echo-greeter/aqua-scripts/echo.aqua
Normal file
6
echo-greeter/aqua-scripts/echo.aqua
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
service Echo("service-id"):
|
||||||
|
echo: []string -> []string
|
||||||
|
|
||||||
|
func echo(data: []string) -> []string:
|
||||||
|
res <- Echo.echo(data)
|
||||||
|
<- res
|
20
echo-greeter/aqua-scripts/echo_greeter.aqua
Normal file
20
echo-greeter/aqua-scripts/echo_greeter.aqua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
service Echo("service-id"):
|
||||||
|
echo: []string -> []string
|
||||||
|
|
||||||
|
|
||||||
|
service Greeting("service-id"):
|
||||||
|
greeting: string, bool -> string
|
||||||
|
|
||||||
|
func seq_echo_greeter(data: []string, name: string, greeter: bool) -> []string:
|
||||||
|
big_res: []string
|
||||||
|
echo_res <- Echo.echo(data)
|
||||||
|
for s <- echo_res:
|
||||||
|
big_res.append(Greeting.greeting(s, greeter))
|
||||||
|
<- big_res
|
||||||
|
|
||||||
|
func par_echo_greeter(data: []string, name: string, greeter: bool) -> []string:
|
||||||
|
big_res: []string
|
||||||
|
echo_res <- Echo.echo(data)
|
||||||
|
for s <- echo_res par:
|
||||||
|
big_res.append(Greeting.greeting(s, greeter))
|
||||||
|
<- big_res
|
7
echo-greeter/aqua-scripts/greeter.aqua
Normal file
7
echo-greeter/aqua-scripts/greeter.aqua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
service Greeting("service-id"):
|
||||||
|
greeting: string, bool -> string
|
||||||
|
-- greeting: string -> string
|
||||||
|
|
||||||
|
func greeting(name: string, greeter:bool) -> string:
|
||||||
|
res <- Greeting.greeting(name, greeter)
|
||||||
|
<- res
|
Loading…
x
Reference in New Issue
Block a user