mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-03-15 07:20:49 +00:00
parent
3eacf708e6
commit
d65153e6de
8
package-lock.json
generated
8
package-lock.json
generated
@ -1107,10 +1107,10 @@
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"@fluencelabs/aquamarine-stepper": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-stepper/-/aquamarine-stepper-0.4.4.tgz",
|
||||
"integrity": "sha512-YJ9rs8QeeOEIfY3hDU7V2Wv1PvWBT6aT4G4m9IIqmtp8k6AkdF6cpInshQ/0CXk77Kn2N/+uD972TltNYnoecA=="
|
||||
"@fluencelabs/aquamarine-interpreter": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-interpreter/-/aquamarine-interpreter-0.7.0.tgz",
|
||||
"integrity": "sha512-2GPsOXSakpRPJFiKAcylK6Q/UhYHrQgrs8a1GCgr/OlrQEYkC4PY4HxnrdErt8fzTUDBHH4veKHKGM+IByYhxA=="
|
||||
},
|
||||
"@istanbuljs/load-nyc-config": {
|
||||
"version": "1.1.0",
|
||||
|
@ -16,7 +16,7 @@
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/aquamarine-stepper": "0.4.4",
|
||||
"@fluencelabs/aquamarine-interpreter": "^0.7.0",
|
||||
"async": "3.2.0",
|
||||
"base64-js": "1.3.1",
|
||||
"bs58": "4.0.1",
|
||||
|
@ -12,7 +12,10 @@ import {
|
||||
} from '../../internal/builtins';
|
||||
import { ModuleConfig } from '../../internal/moduleConfig';
|
||||
import { createConnectedClient } from '../util';
|
||||
import {checkConnection} from "../../api";
|
||||
import { checkConnection } from '../../api';
|
||||
import log from 'loglevel';
|
||||
import { generatePeerId } from '../..';
|
||||
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
|
||||
|
||||
const dev2multiaddr = '/dns4/dev.fluence.dev/tcp/19003/wss/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb';
|
||||
const dev3multiaddr = '/dns4/dev.fluence.dev/tcp/19004/wss/p2p/12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB';
|
||||
@ -45,7 +48,10 @@ describe('Builtins usage suite', () => {
|
||||
});
|
||||
|
||||
it('check_connection', async function () {
|
||||
const client = await createConnectedClient(dev2multiaddr);
|
||||
const peerId = await generatePeerId();
|
||||
const client = new FluenceClientImpl(peerId);
|
||||
await client.local();
|
||||
await client.connect(dev2multiaddr);
|
||||
|
||||
let isConnected = await checkConnection(client);
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import {encode} from 'bs58';
|
||||
import {generatePeerId, peerIdToSeed, seedToPeerId} from '../../internal/peerIdUtils';
|
||||
import {FluenceClientImpl} from '../../internal/FluenceClientImpl';
|
||||
import {createConnectedClient} from '../util';
|
||||
import { encode } from 'bs58';
|
||||
import { generatePeerId, peerIdToSeed, seedToPeerId } from '../../internal/peerIdUtils';
|
||||
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
|
||||
import { createConnectedClient } from '../util';
|
||||
import log from 'loglevel';
|
||||
import {createClient} from '../../api';
|
||||
import { createClient } from '../../api';
|
||||
import Multiaddr from 'multiaddr';
|
||||
|
||||
const devNodeAddress = '/dns4/dev.fluence.dev/tcp/19001/wss/p2p/12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9';
|
||||
|
@ -12,7 +12,24 @@ describe('== AST parsing suite', () => {
|
||||
Call: {
|
||||
peer_part: { PeerPk: { Variable: 'node' } },
|
||||
function_part: { ServiceIdWithFuncName: [{ Literal: 'service' }, { Literal: 'function' }] },
|
||||
args: [{ Variable: '1' }, { Variable: '2' }, { Variable: '3' }, { Variable: 'arg' }],
|
||||
args: [
|
||||
{
|
||||
Number: {
|
||||
Int: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
Number: {
|
||||
Int: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
Number: {
|
||||
Int: 3,
|
||||
},
|
||||
},
|
||||
{ Variable: 'arg' },
|
||||
],
|
||||
output: { Scalar: 'output' },
|
||||
},
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {generatePeerId} from '..';
|
||||
import {FluenceClientImpl} from '../internal/FluenceClientImpl';
|
||||
import { generatePeerId } from '..';
|
||||
import { createClient } from '../api';
|
||||
import { FluenceClientImpl } from '../internal/FluenceClientImpl';
|
||||
|
||||
export const createLocalClient = async () => {
|
||||
const peerId = await generatePeerId();
|
||||
@ -9,8 +10,5 @@ export const createLocalClient = async () => {
|
||||
};
|
||||
|
||||
export const createConnectedClient = async (node: string) => {
|
||||
const peerId = await generatePeerId();
|
||||
const client = new FluenceClientImpl(peerId);
|
||||
await client.connect(node);
|
||||
return client;
|
||||
return (await createClient(node)) as FluenceClientImpl;
|
||||
};
|
||||
|
21
src/api.ts
21
src/api.ts
@ -5,7 +5,7 @@ import Multiaddr from 'multiaddr';
|
||||
import PeerId, { isPeerId } from 'peer-id';
|
||||
import { generatePeerId, seedToPeerId } from './internal/peerIdUtils';
|
||||
import { FluenceClientImpl } from './internal/FluenceClientImpl';
|
||||
import log from "loglevel";
|
||||
import log from 'loglevel';
|
||||
|
||||
type Node = {
|
||||
peerId: string;
|
||||
@ -45,8 +45,8 @@ export const createClient = async (
|
||||
}
|
||||
|
||||
await client.connect(theAddress);
|
||||
if (!await checkConnection(client)) {
|
||||
throw new Error("Connection check failed. Check if the node is working or try to connect to another node")
|
||||
if (!(await checkConnection(client))) {
|
||||
throw new Error('Connection check failed. Check if the node is working or try to connect to another node');
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,8 +158,8 @@ export const sendParticleAsFetch = async <T>(
|
||||
|
||||
export const checkConnection = async (client: FluenceClient): Promise<boolean> => {
|
||||
let msg = Math.random().toString(36).substring(7);
|
||||
let callbackFn = "checkConnection"
|
||||
let callbackService = "_callback"
|
||||
let callbackFn = 'checkConnection';
|
||||
let callbackService = '_callback';
|
||||
|
||||
const particle = new Particle(
|
||||
`
|
||||
@ -171,9 +171,8 @@ export const checkConnection = async (client: FluenceClient): Promise<boolean> =
|
||||
{
|
||||
__relay: client.relayPeerId,
|
||||
myPeerId: client.selfPeerId,
|
||||
msg
|
||||
msg,
|
||||
},
|
||||
3000
|
||||
);
|
||||
|
||||
if (!client.isConnected) {
|
||||
@ -181,13 +180,13 @@ export const checkConnection = async (client: FluenceClient): Promise<boolean> =
|
||||
}
|
||||
|
||||
try {
|
||||
let result = await sendParticleAsFetch<string[][]>(client, particle, callbackFn, callbackService)
|
||||
let result = await sendParticleAsFetch<string[][]>(client, particle, callbackFn, callbackService);
|
||||
if (result[0][0] != msg) {
|
||||
log.warn("unexpected behavior. 'identity' must return arguments the passed arguments.")
|
||||
log.warn("unexpected behavior. 'identity' must return arguments the passed arguments.");
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
log.error("Error on establishing connection: ", e)
|
||||
log.error('Error on establishing connection: ', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ import { ParticleHandler, CallServiceResult, SecurityTetraplet } from './commonT
|
||||
|
||||
import PeerId from 'peer-id';
|
||||
import log from 'loglevel';
|
||||
import wasmBs64 from '@fluencelabs/aquamarine-stepper';
|
||||
import wasmBs64 from '@fluencelabs/aquamarine-interpreter';
|
||||
|
||||
export type InterpreterInvoke = (
|
||||
init_user_id: string,
|
||||
@ -33,8 +33,8 @@ type ImportObject = {
|
||||
'./aquamarine_client_bg.js': {
|
||||
// fn call_service_impl(service_id: String, fn_name: String, args: String, security_tetraplets: String) -> String;
|
||||
// prettier-ignore
|
||||
__wbg_callserviceimpl_5e179a02949d2e6b: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, ) => void;
|
||||
__wbg_getcurrentpeeridimpl_a7ef0866adbc56ef: (arg0: any) => void;
|
||||
__wbg_callserviceimpl_d9f9208b7e581e24: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, ) => void;
|
||||
__wbg_getcurrentpeeridimpl_c6a63062490312cd: (arg0: any) => void;
|
||||
__wbindgen_throw: (arg: any) => void;
|
||||
};
|
||||
host: LogImport;
|
||||
@ -130,14 +130,15 @@ const theParticleHandler = (
|
||||
args: string,
|
||||
tetraplets: string,
|
||||
): CallServiceResult => {
|
||||
let argsObject;
|
||||
let tetrapletsObject: SecurityTetraplet[][];
|
||||
try {
|
||||
let argsObject = JSON.parse(args);
|
||||
argsObject = JSON.parse(args);
|
||||
if (!Array.isArray(argsObject)) {
|
||||
throw new Error('args is not an array');
|
||||
}
|
||||
|
||||
let tetrapletsObject: SecurityTetraplet[][] = JSON.parse(tetraplets);
|
||||
return callback(service_id, fn_name, argsObject, tetrapletsObject);
|
||||
tetrapletsObject = JSON.parse(tetraplets);
|
||||
} catch (err) {
|
||||
console.error('Cannot parse arguments: ' + JSON.stringify(err));
|
||||
return {
|
||||
@ -145,6 +146,8 @@ const theParticleHandler = (
|
||||
ret_code: 1,
|
||||
};
|
||||
}
|
||||
|
||||
return callback(service_id, fn_name, argsObject, tetrapletsObject);
|
||||
};
|
||||
|
||||
/// Returns import object that describes host functions called by AIR interpreter
|
||||
@ -154,7 +157,7 @@ function newImportObject(particleHandler: ParticleHandler, cfg: HostImportsConfi
|
||||
// If so, an error with a new name will be occurred after wasm initialization.
|
||||
'./aquamarine_client_bg.js': {
|
||||
// prettier-ignore
|
||||
__wbg_callserviceimpl_5e179a02949d2e6b: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => {
|
||||
__wbg_callserviceimpl_d9f9208b7e581e24: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => {
|
||||
let wasm = cfg.exports;
|
||||
try {
|
||||
let serviceId = getStringFromWasm0(wasm, arg1, arg2);
|
||||
@ -178,7 +181,7 @@ function newImportObject(particleHandler: ParticleHandler, cfg: HostImportsConfi
|
||||
free(wasm, arg7, arg8);
|
||||
}
|
||||
},
|
||||
__wbg_getcurrentpeeridimpl_a7ef0866adbc56ef: (arg0: any) => {
|
||||
__wbg_getcurrentpeeridimpl_c6a63062490312cd: (arg0: any) => {
|
||||
let peerIdStr = peerId.toB58String();
|
||||
let wasm = cfg.exports;
|
||||
return_current_peer_id(wasm, peerIdStr, arg0);
|
||||
@ -195,8 +198,8 @@ function newLogImport(cfg: HostImportsConfig): ImportObject {
|
||||
return {
|
||||
host: log_import(cfg),
|
||||
'./aquamarine_client_bg.js': {
|
||||
__wbg_callserviceimpl_5e179a02949d2e6b: (_) => {},
|
||||
__wbg_getcurrentpeeridimpl_a7ef0866adbc56ef: (_) => {},
|
||||
__wbg_callserviceimpl_d9f9208b7e581e24: (_) => {},
|
||||
__wbg_getcurrentpeeridimpl_c6a63062490312cd: (_) => {},
|
||||
__wbindgen_throw: (_) => {},
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user