Expose parse ast method from AVM (#161)

This commit is contained in:
Pavel
2022-08-04 12:05:31 +03:00
committed by GitHub
parent f0906066c5
commit 9eafbed86b
2 changed files with 61 additions and 0 deletions

View File

@ -352,6 +352,34 @@ export class FluencePeer {
*/
get internals() {
return {
parseAst: async (air: string): Promise<{ success: boolean; data: any }> => {
const status = this.getStatus();
if (!status.isInitialized) {
new Error("Can't use avm: peer is not initialized");
}
const args = JSON.stringify([air]);
const rawRes = await this._fluenceAppService!.callService('avm', 'ast', args, undefined);
let res;
try {
res = JSON.parse(rawRes);
res = res.result as string;
if (res.startsWith('error')) {
return {
success: false,
data: res,
};
} else {
return {
success: true,
data: JSON.parse(res),
};
}
} catch (err) {
throw new Error('Failed to call avm. Raw result: ' + rawRes + '. Error: ' + err);
}
},
createNewParticle: (script: string, ttl: number = this._defaultTTL) => {
const status = this.getStatus();