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

109 lines
3.3 KiB
TypeScript
Raw Normal View History

2021-04-29 11:56:02 +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-22 13:22:35 +03:00
* Aqua version: 0.1.7-153
2021-04-29 11:56:02 +03:00
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
2021-05-18 10:14:54 +03:00
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
2021-04-29 11:56:02 +03:00
2021-06-15 13:14:39 +03:00
export async function topologyTest(client: FluenceClient, me: string, myRelay: string, friend: string, friendRelay: string, config?: {ttl?: number}): Promise<string> {
2021-05-18 10:14:54 +03:00
let request: RequestFlow;
2021-04-29 11:56:02 +03:00
const promise = new Promise<string>((resolve, reject) => {
request = new RequestFlowBuilder()
.disableInjections()
2021-06-15 13:14:39 +03:00
.withTTL(config?.ttl || 5000)
2021-04-29 11:56:02 +03:00
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
2021-06-22 12:29:01 +03:00
(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
2021-04-29 11:56:02 +03:00
(seq
(seq
(seq
(seq
2021-04-29 14:15:20 +03:00
(seq
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
(call friendRelay ("op" "noop") [])
)
(xor
(call friend ("testo" "getString") ["friends string via"] str2)
2021-05-04 18:49:59 +03:00
(seq
(seq
2021-06-22 12:29:01 +03:00
(call friendRelay ("op" "noop") [])
(call -relay- ("op" "noop") [])
2021-05-04 18:49:59 +03:00
)
2021-06-22 12:29:01 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
2021-06-18 15:15:34 +03:00
)
)
)
2021-06-22 12:29:01 +03:00
(call friendRelay ("op" "noop") [])
)
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
2021-04-29 11:56:02 +03:00
)
2021-06-22 12:29:01 +03:00
(call %init_peer_id% ("op" "noop") [])
2021-04-29 11:56:02 +03:00
)
2021-06-22 12:29:01 +03:00
(call %init_peer_id% ("lp" "print") ["my string in par"])
2021-04-29 11:56:02 +03:00
)
)
(call %init_peer_id% ("lp" "print") [str2])
)
2021-05-04 18:49:59 +03:00
(xor
(call %init_peer_id% ("callbackSrv" "response") ["finish"])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
2021-04-29 11:56:02 +03:00
)
2021-06-18 15:15:34 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
2021-04-29 11:56:02 +03:00
)
`,
)
.configHandler((h) => {
2021-05-04 18:49:59 +03:00
h.on('getDataSrv', '-relay-', () => {
2021-04-29 11:56:02 +03:00
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();
});
2021-05-18 10:14:54 +03:00
await client.initiateFlow(request!);
2021-04-29 11:56:02 +03:00
return promise;
}