Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit d65153e

Browse files
authored
Update interpreter (#26)
* Update interpreter version
1 parent 3eacf70 commit d65153e

File tree

8 files changed

+63
-40
lines changed

8 files changed

+63
-40
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author": "Fluence Labs",
1717
"license": "Apache-2.0",
1818
"dependencies": {
19-
"@fluencelabs/aquamarine-stepper": "0.4.4",
19+
"@fluencelabs/aquamarine-interpreter": "^0.7.0",
2020
"async": "3.2.0",
2121
"base64-js": "1.3.1",
2222
"bs58": "4.0.1",

src/__test__/integration/builtins.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
} from '../../internal/builtins';
1313
import { ModuleConfig } from '../../internal/moduleConfig';
1414
import { createConnectedClient } from '../util';
15-
import {checkConnection} from "../../api";
15+
import { checkConnection } from '../../api';
16+
import log from 'loglevel';
17+
import { generatePeerId } from '../..';
18+
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
1619

1720
const dev2multiaddr = '/dns4/dev.fluence.dev/tcp/19003/wss/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb';
1821
const dev3multiaddr = '/dns4/dev.fluence.dev/tcp/19004/wss/p2p/12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB';
@@ -45,7 +48,10 @@ describe('Builtins usage suite', () => {
4548
});
4649

4750
it('check_connection', async function () {
48-
const client = await createConnectedClient(dev2multiaddr);
51+
const peerId = await generatePeerId();
52+
const client = new FluenceClientImpl(peerId);
53+
await client.local();
54+
await client.connect(dev2multiaddr);
4955

5056
let isConnected = await checkConnection(client);
5157

src/__test__/integration/client.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {encode} from 'bs58';
2-
import {generatePeerId, peerIdToSeed, seedToPeerId} from '../../internal/peerIdUtils';
3-
import {FluenceClientImpl} from '../../internal/FluenceClientImpl';
4-
import {createConnectedClient} from '../util';
1+
import { encode } from 'bs58';
2+
import { generatePeerId, peerIdToSeed, seedToPeerId } from '../../internal/peerIdUtils';
3+
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
4+
import { createConnectedClient } from '../util';
55
import log from 'loglevel';
6-
import {createClient} from '../../api';
6+
import { createClient } from '../../api';
77
import Multiaddr from 'multiaddr';
88

99
const devNodeAddress = '/dns4/dev.fluence.dev/tcp/19001/wss/p2p/12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9';

src/__test__/unit/ast.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ describe('== AST parsing suite', () => {
1212
Call: {
1313
peer_part: { PeerPk: { Variable: 'node' } },
1414
function_part: { ServiceIdWithFuncName: [{ Literal: 'service' }, { Literal: 'function' }] },
15-
args: [{ Variable: '1' }, { Variable: '2' }, { Variable: '3' }, { Variable: 'arg' }],
15+
args: [
16+
{
17+
Number: {
18+
Int: 1,
19+
},
20+
},
21+
{
22+
Number: {
23+
Int: 2,
24+
},
25+
},
26+
{
27+
Number: {
28+
Int: 3,
29+
},
30+
},
31+
{ Variable: 'arg' },
32+
],
1633
output: { Scalar: 'output' },
1734
},
1835
});

src/__test__/util.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import {generatePeerId} from '..';
2-
import {FluenceClientImpl} from '../internal/FluenceClientImpl';
1+
import { generatePeerId } from '..';
2+
import { createClient } from '../api';
3+
import { FluenceClientImpl } from '../internal/FluenceClientImpl';
34

45
export const createLocalClient = async () => {
56
const peerId = await generatePeerId();
@@ -9,8 +10,5 @@ export const createLocalClient = async () => {
910
};
1011

1112
export const createConnectedClient = async (node: string) => {
12-
const peerId = await generatePeerId();
13-
const client = new FluenceClientImpl(peerId);
14-
await client.connect(node);
15-
return client;
13+
return (await createClient(node)) as FluenceClientImpl;
1614
};

src/api.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Multiaddr from 'multiaddr';
55
import PeerId, { isPeerId } from 'peer-id';
66
import { generatePeerId, seedToPeerId } from './internal/peerIdUtils';
77
import { FluenceClientImpl } from './internal/FluenceClientImpl';
8-
import log from "loglevel";
8+
import log from 'loglevel';
99

1010
type Node = {
1111
peerId: string;
@@ -45,8 +45,8 @@ export const createClient = async (
4545
}
4646

4747
await client.connect(theAddress);
48-
if (!await checkConnection(client)) {
49-
throw new Error("Connection check failed. Check if the node is working or try to connect to another node")
48+
if (!(await checkConnection(client))) {
49+
throw new Error('Connection check failed. Check if the node is working or try to connect to another node');
5050
}
5151
}
5252

@@ -158,8 +158,8 @@ export const sendParticleAsFetch = async <T>(
158158

159159
export const checkConnection = async (client: FluenceClient): Promise<boolean> => {
160160
let msg = Math.random().toString(36).substring(7);
161-
let callbackFn = "checkConnection"
162-
let callbackService = "_callback"
161+
let callbackFn = 'checkConnection';
162+
let callbackService = '_callback';
163163

164164
const particle = new Particle(
165165
`
@@ -171,23 +171,22 @@ export const checkConnection = async (client: FluenceClient): Promise<boolean> =
171171
{
172172
__relay: client.relayPeerId,
173173
myPeerId: client.selfPeerId,
174-
msg
174+
msg,
175175
},
176-
3000
177176
);
178177

179178
if (!client.isConnected) {
180179
return false;
181180
}
182181

183182
try {
184-
let result = await sendParticleAsFetch<string[][]>(client, particle, callbackFn, callbackService)
183+
let result = await sendParticleAsFetch<string[][]>(client, particle, callbackFn, callbackService);
185184
if (result[0][0] != msg) {
186-
log.warn("unexpected behavior. 'identity' must return arguments the passed arguments.")
185+
log.warn("unexpected behavior. 'identity' must return arguments the passed arguments.");
187186
}
188187
return true;
189188
} catch (e) {
190-
log.error("Error on establishing connection: ", e)
189+
log.error('Error on establishing connection: ', e);
191190
return false;
192191
}
193-
}
192+
};

src/internal/stepper.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ParticleHandler, CallServiceResult, SecurityTetraplet } from './commonT
2121

2222
import PeerId from 'peer-id';
2323
import log from 'loglevel';
24-
import wasmBs64 from '@fluencelabs/aquamarine-stepper';
24+
import wasmBs64 from '@fluencelabs/aquamarine-interpreter';
2525

2626
export type InterpreterInvoke = (
2727
init_user_id: string,
@@ -33,8 +33,8 @@ type ImportObject = {
3333
'./aquamarine_client_bg.js': {
3434
// fn call_service_impl(service_id: String, fn_name: String, args: String, security_tetraplets: String) -> String;
3535
// prettier-ignore
36-
__wbg_callserviceimpl_5e179a02949d2e6b: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, ) => void;
37-
__wbg_getcurrentpeeridimpl_a7ef0866adbc56ef: (arg0: any) => void;
36+
__wbg_callserviceimpl_d9f9208b7e581e24: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, ) => void;
37+
__wbg_getcurrentpeeridimpl_c6a63062490312cd: (arg0: any) => void;
3838
__wbindgen_throw: (arg: any) => void;
3939
};
4040
host: LogImport;
@@ -130,21 +130,24 @@ const theParticleHandler = (
130130
args: string,
131131
tetraplets: string,
132132
): CallServiceResult => {
133+
let argsObject;
134+
let tetrapletsObject: SecurityTetraplet[][];
133135
try {
134-
let argsObject = JSON.parse(args);
136+
argsObject = JSON.parse(args);
135137
if (!Array.isArray(argsObject)) {
136138
throw new Error('args is not an array');
137139
}
138140

139-
let tetrapletsObject: SecurityTetraplet[][] = JSON.parse(tetraplets);
140-
return callback(service_id, fn_name, argsObject, tetrapletsObject);
141+
tetrapletsObject = JSON.parse(tetraplets);
141142
} catch (err) {
142143
console.error('Cannot parse arguments: ' + JSON.stringify(err));
143144
return {
144145
result: JSON.stringify('Cannot parse arguments: ' + JSON.stringify(err)),
145146
ret_code: 1,
146147
};
147148
}
149+
150+
return callback(service_id, fn_name, argsObject, tetrapletsObject);
148151
};
149152

150153
/// Returns import object that describes host functions called by AIR interpreter
@@ -154,7 +157,7 @@ function newImportObject(particleHandler: ParticleHandler, cfg: HostImportsConfi
154157
// If so, an error with a new name will be occurred after wasm initialization.
155158
'./aquamarine_client_bg.js': {
156159
// prettier-ignore
157-
__wbg_callserviceimpl_5e179a02949d2e6b: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => {
160+
__wbg_callserviceimpl_d9f9208b7e581e24: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => {
158161
let wasm = cfg.exports;
159162
try {
160163
let serviceId = getStringFromWasm0(wasm, arg1, arg2);
@@ -178,7 +181,7 @@ function newImportObject(particleHandler: ParticleHandler, cfg: HostImportsConfi
178181
free(wasm, arg7, arg8);
179182
}
180183
},
181-
__wbg_getcurrentpeeridimpl_a7ef0866adbc56ef: (arg0: any) => {
184+
__wbg_getcurrentpeeridimpl_c6a63062490312cd: (arg0: any) => {
182185
let peerIdStr = peerId.toB58String();
183186
let wasm = cfg.exports;
184187
return_current_peer_id(wasm, peerIdStr, arg0);
@@ -195,8 +198,8 @@ function newLogImport(cfg: HostImportsConfig): ImportObject {
195198
return {
196199
host: log_import(cfg),
197200
'./aquamarine_client_bg.js': {
198-
__wbg_callserviceimpl_5e179a02949d2e6b: (_) => {},
199-
__wbg_getcurrentpeeridimpl_a7ef0866adbc56ef: (_) => {},
201+
__wbg_callserviceimpl_d9f9208b7e581e24: (_) => {},
202+
__wbg_getcurrentpeeridimpl_c6a63062490312cd: (_) => {},
200203
__wbindgen_throw: (_) => {},
201204
},
202205
};

0 commit comments

Comments
 (0)