Skip to content

Commit

Permalink
merge develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
akastercomcom committed Jan 22, 2024
2 parents 8506957 + def679c commit d3b4f4b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ainize-team/ainize-js",
"version": "1.0.4",
"version": "1.0.6",
"main": "dist/ainize.js",
"types": "dist/ainize.d.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
write:
"auth.addr === $userAddress && " +
"(getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`) === 0 || " +
"(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`))"
"(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`)))"
},
},
},
Expand Down
28 changes: 16 additions & 12 deletions src/controllers/serviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,24 @@ export default class ServiceController {
return await this.ain.getValue(creditHistoryPath) as creditHistories;
}

async request(serviceName: string, requestData: any) : Promise<any> {
await this.checkRunning(serviceName);
async request(serviceName: string, requestData: any, requestKey?: string) : Promise<any> {
this.checkRunning(serviceName);
const result = await new Promise(async (resolve, reject) => {
const requestKey = Date.now();
const requesterAddress = this.ain.getAddress();
const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString());
await this.handler.subscribe(responsePath, resolve);
const requestPath = Path.app(serviceName).request(requesterAddress, requestKey);
const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData);
const txBody = buildTxBody(requestOp);
await this.ain.sendTransaction(txBody);
return requestKey;
requestKey = requestKey || Date.now().toString();
try {
const requesterAddress = this.ain.getAddress();
const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString());
await this.handler.subscribe(responsePath, resolve);
const requestPath = Path.app(serviceName).request(requesterAddress, requestKey);
const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData);
const txBody = buildTxBody(requestOp);
await this.ain.sendTransaction(txBody);
} catch (e: any) {
if (e instanceof Error)
return reject(new Error(e.message));
}
});
return result as string;
return result;
}

async run(serviceName: string): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export default class Service {
* @param {string} requestData String data for request to service.
* @returns {string} Response data from service.
*/
async request(requestData: any) {
async request(requestData: any, requestKey?: string) {
this.isLoggedIn();
return await this.serviceController.request(this.serviceName, requestData);
return await this.serviceController.request(this.serviceName, requestData, requestKey);
}

/**
Expand Down

0 comments on commit d3b4f4b

Please sign in to comment.