171 lines
5.2 KiB
TypeScript
Raw Normal View History

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-29 11:56:02 +03:00
* Aqua version: 0.1.1-SNAPSHOT
2021-04-23 17:21:58 +03:00
*
*/
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 print(client: FluenceClient, str: string): Promise<void> {
let request;
const promise = new Promise<void>((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)
2021-04-23 17:21:58 +03:00
(call %init_peer_id% ("getDataSrv" "str") [] str)
2021-04-15 18:19:24 +03:00
)
(call %init_peer_id% ("println-service-id" "print") [str])
)
2021-04-29 11:56:02 +03:00
(seq
(call relay ("op" "identity") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
)
2021-04-15 18:19:24 +03:00
)
`,
)
.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
});
h.on('getRelayService', 'hasRelay', () => {// Not Used
2021-04-15 18:19:24 +03:00
return client.relayPeerId !== undefined;
});
h.on('getDataSrv', 'str', () => {return str;});
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 print');
2021-04-15 18:19:24 +03:00
})
.build();
});
await client.initiateFlow(request);
return Promise.race([promise, Promise.resolve()]);
}
export async function ifElseCall(client: FluenceClient, condition: boolean): Promise<void> {
let request;
const promise = new Promise<void>((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)
2021-04-23 17:21:58 +03:00
(call %init_peer_id% ("getDataSrv" "condition") [] condition)
2021-04-15 18:19:24 +03:00
)
(xor
(match condition true
(call %init_peer_id% ("println-service-id" "print") ["it is true"])
)
(call %init_peer_id% ("println-service-id" "print") ["it is false"])
)
)
2021-04-29 11:56:02 +03:00
(seq
(call relay ("op" "identity") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
)
2021-04-15 18:19:24 +03:00
)
`,
)
.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
});
h.on('getRelayService', 'hasRelay', () => {// Not Used
2021-04-15 18:19:24 +03:00
return client.relayPeerId !== undefined;
});
h.on('getDataSrv', 'condition', () => {return condition;});
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 ifElseCall');
2021-04-15 18:19:24 +03:00
})
.build();
});
await client.initiateFlow(request);
return Promise.race([promise, Promise.resolve()]);
}
export async function ifElseNumCall(client: FluenceClient, condition: number): Promise<void> {
let request;
const promise = new Promise<void>((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)
2021-04-23 17:21:58 +03:00
(call %init_peer_id% ("getDataSrv" "condition") [] condition)
2021-04-15 18:19:24 +03:00
)
(xor
(match condition 1
(call %init_peer_id% ("println-service-id" "print") ["it is 1"])
)
(call %init_peer_id% ("println-service-id" "print") ["it is not 1"])
)
)
2021-04-29 11:56:02 +03:00
(seq
(call relay ("op" "identity") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error%])
)
2021-04-15 18:19:24 +03:00
)
`,
)
.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
});
h.on('getRelayService', 'hasRelay', () => {// Not Used
2021-04-15 18:19:24 +03:00
return client.relayPeerId !== undefined;
});
h.on('getDataSrv', 'condition', () => {return condition;});
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 ifElseNumCall');
2021-04-15 18:19:24 +03:00
})
.build();
});
await client.initiateFlow(request);
return Promise.race([promise, Promise.resolve()]);
}