78 lines
2.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 checkStreams(client: FluenceClient, ch: 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
(seq
2021-05-04 18:49:59 +03:00
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
2021-04-29 11:56:02 +03:00
(call %init_peer_id% ("getDataSrv" "ch") [] ch)
)
(call %init_peer_id% ("stringer-id" "returnString") ["first"] $stream)
)
(call %init_peer_id% ("stringer-id" "returnString") ["second"] $stream)
)
(fold ch b
(seq
(call %init_peer_id% ("stringer-id" "returnString") [b] $stream)
(next b)
)
)
)
2021-05-04 18:49:59 +03:00
(xor
(call %init_peer_id% ("callbackSrv" "response") [$stream])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
2021-04-29 11:56:02 +03:00
)
2021-06-18 15:15:34 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
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', 'ch', () => {return ch;});
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 checkStreams');
})
.build();
});
2021-05-18 10:14:54 +03:00
await client.initiateFlow(request!);
2021-04-29 11:56:02 +03:00
return promise;
}