Files
aqua-playground/src/compiled/examples/assignment.ts

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-06-07 17:23:27 +03:00
/**
*
* 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
2021-06-15 17:06:08 +03:00
* Aqua version: 0.1.6-SNAPSHOT
2021-06-07 17:23:27 +03:00
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
2021-06-15 13:14:39 +03:00
export async function doSmth(client: FluenceClient, arg: {value:string}, config?: {ttl?: number}): Promise<string[]> {
2021-06-07 17:23:27 +03:00
let request: RequestFlow;
2021-06-07 18:17:01 +03:00
const promise = new Promise<string[]>((resolve, reject) => {
2021-06-07 17:23:27 +03:00
request = new RequestFlowBuilder()
.disableInjections()
2021-06-15 13:14:39 +03:00
.withTTL(config?.ttl || 5000)
2021-06-07 17:23:27 +03:00
.withRawScript(
`
(xor
(seq
(seq
(seq
2021-06-07 18:17:01 +03:00
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "arg") [] arg)
)
(call %init_peer_id% ("op" "identity") [arg.$.value!] a)
2021-06-07 17:23:27 +03:00
)
2021-06-07 18:17:01 +03:00
(call %init_peer_id% ("op" "array") [a "hello"] res)
2021-06-07 17:23:27 +03:00
)
(xor
2021-06-07 18:17:01 +03:00
(call %init_peer_id% ("callbackSrv" "response") [res])
2021-06-07 17:23:27 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(seq
(call -relay- ("op" "identity") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'arg', () => {return arg;});
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 doSmth');
})
.build();
});
await client.initiateFlow(request!);
return promise;
}