2021-04-23 17:21:58 +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-04-15 18:19:24 +03:00
|
|
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
|
|
|
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function getAliasedData(client: FluenceClient): Promise<string> {
|
|
|
|
let request;
|
|
|
|
const promise = new Promise<string>((resolve, reject) => {
|
|
|
|
request = new RequestFlowBuilder()
|
2021-04-23 17:21:58 +03:00
|
|
|
.disableInjections()
|
2021-04-15 18:19:24 +03:00
|
|
|
.withRawScript(
|
|
|
|
`
|
|
|
|
(xor
|
|
|
|
(seq
|
|
|
|
(seq
|
|
|
|
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
|
|
|
|
(call %init_peer_id% ("somesrv" "get") [] res)
|
|
|
|
)
|
|
|
|
(call %init_peer_id% ("callbackSrv" "response") [res.$.peerId!])
|
|
|
|
)
|
|
|
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
|
|
|
|
)
|
|
|
|
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
.configHandler((h) => {
|
|
|
|
h.on('getDataSrv', 'relay', () => {
|
2021-04-23 17:21:58 +03:00
|
|
|
return client.relayPeerId!;
|
2021-04-15 18:19:24 +03:00
|
|
|
});
|
2021-04-26 19:14:07 +03:00
|
|
|
h.on('getRelayService', 'hasRelay', () => {// Not Used
|
2021-04-15 18:19:24 +03:00
|
|
|
return client.relayPeerId !== undefined;
|
|
|
|
});
|
|
|
|
|
2021-04-23 17:21:58 +03:00
|
|
|
h.onEvent('callbackSrv', 'response', (args) => {
|
2021-04-15 18:19:24 +03:00
|
|
|
const [res] = args;
|
|
|
|
resolve(res);
|
|
|
|
});
|
|
|
|
|
2021-04-23 17:21:58 +03:00
|
|
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
2021-04-15 18:19:24 +03:00
|
|
|
// assuming error is the single argument
|
|
|
|
const [err] = args;
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.handleScriptError(reject)
|
|
|
|
.handleTimeout(() => {
|
2021-04-23 17:21:58 +03:00
|
|
|
reject('Request timed out for getAliasedData');
|
2021-04-15 18:19:24 +03:00
|
|
|
})
|
|
|
|
.build();
|
|
|
|
});
|
|
|
|
await client.initiateFlow(request);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|