35 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-02-26 00:18:07 +03:00
import { FluenceClient, Particle, sendParticleAsFetch } from '@fluencelabs/fluence';
import { testNet } from '@fluencelabs/fluence-network-environment';
import { v4 as uuidv4 } from 'uuid';
export const relayNode = testNet[3];
const node = relayNode.peerId;
2021-03-02 23:32:03 +03:00
const serviceId = '4d082281-c72c-468b-b30a-e9ebad70546c';
2021-02-26 00:18:07 +03:00
export const curlRequest = async (client: FluenceClient, url: String, ttl: number) => {
const script = `
(seq
(call myRelay ("op" "identity") [])
(seq
(call node (serviceId "request") [url] result)
(seq
(call myRelay ("op" "identity") [])
(call myPeerId ("_callback" callback) [result])
)
)
)
`;
let callbackId = uuidv4();
const data = new Map();
data.set('node', node);
data.set('serviceId', serviceId);
data.set('myRelay', client.relayPeerId);
data.set('myPeerId', client.selfPeerId);
data.set('callback', callbackId);
data.set('url', url);
2021-03-02 23:32:03 +03:00
return await sendParticleAsFetch<any>(client, new Particle(script, data, ttl), callbackId);
2021-02-26 00:18:07 +03:00
};