mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-06-13 08:51:19 +00:00
109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
/**
|
|
*
|
|
* 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.7-153
|
|
*
|
|
*/
|
|
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 topologyTest(client: FluenceClient, me: string, myRelay: string, friend: string, friendRelay: 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
|
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
|
(call %init_peer_id% ("getDataSrv" "me") [] me)
|
|
)
|
|
(call %init_peer_id% ("getDataSrv" "myRelay") [] myRelay)
|
|
)
|
|
(call %init_peer_id% ("getDataSrv" "friend") [] friend)
|
|
)
|
|
(call %init_peer_id% ("getDataSrv" "friendRelay") [] friendRelay)
|
|
)
|
|
(par
|
|
(seq
|
|
(seq
|
|
(seq
|
|
(seq
|
|
(seq
|
|
(call -relay- ("op" "noop") [])
|
|
(call friendRelay ("op" "noop") [])
|
|
)
|
|
(xor
|
|
(call friend ("testo" "getString") ["friends string via"] str2)
|
|
(seq
|
|
(seq
|
|
(call friendRelay ("op" "noop") [])
|
|
(call -relay- ("op" "noop") [])
|
|
)
|
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
|
)
|
|
)
|
|
)
|
|
(call friendRelay ("op" "noop") [])
|
|
)
|
|
(call -relay- ("op" "noop") [])
|
|
)
|
|
(call %init_peer_id% ("op" "noop") [])
|
|
)
|
|
(call %init_peer_id% ("lp" "print") ["my string in par"])
|
|
)
|
|
)
|
|
(call %init_peer_id% ("lp" "print") [str2])
|
|
)
|
|
(xor
|
|
(call %init_peer_id% ("callbackSrv" "response") ["finish"])
|
|
(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', 'me', () => {return me;});
|
|
h.on('getDataSrv', 'myRelay', () => {return myRelay;});
|
|
h.on('getDataSrv', 'friend', () => {return friend;});
|
|
h.on('getDataSrv', 'friendRelay', () => {return friendRelay;});
|
|
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 topologyTest');
|
|
})
|
|
.build();
|
|
});
|
|
await client.initiateFlow(request!);
|
|
return promise;
|
|
}
|
|
|