Skip to content

Commit

Permalink
feat: connect
Browse files Browse the repository at this point in the history
  • Loading branch information
akastercomcom committed Sep 20, 2023
1 parent cc06695 commit 3262d40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import AinModule from "./ain";
export default class Ainize {
private cache: NodeCache;
ain: AinModule = AinModule.getInstance();
private handler: Handler = Handler.getInstance();
middleware: Middleware;
appController: AppController = AppController.getInstance();

constructor(chainId: 1 | 0) {
this.ain.initAin(chainId);
this.handler.connect();
this.cache = new NodeCache();
this.middleware = new Middleware(this.cache);
}
Expand Down
7 changes: 5 additions & 2 deletions src/controllers/modelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Path } from "../constants";
import { getRequestDepositOp, getTransferOp } from "../utils/operator";
import { buildSetOperation, buildTxBody } from "../utils/builder";
import Handler from "../handlers/handler";
import { ContainerStatus } from "../types/type";

export default class ModelController {
private static instance: ModelController | undefined;
Expand All @@ -16,9 +17,9 @@ export default class ModelController {
return ModelController.instance;
}

//TODO(woojae): implement this
async isRunning(modelName: string) {
return await true;
const isRunning = await this.ain.getValue(Path.app(modelName).status());
return isRunning === ContainerStatus.RUNNING;
}

//TODO(woojae): implement this
Expand All @@ -40,6 +41,7 @@ export default class ModelController {

async chargeCredit(modelName: string, amount: number) {
this.isLoggedIn();
this.isRunning(modelName);
const transferKey = Date.now();
const userAddress = this.ain.getAddress();
const depositAddress = await this.getDepositAddress(modelName);
Expand Down Expand Up @@ -74,6 +76,7 @@ export default class ModelController {
//TODO(woojae): connect with handler
async use(modelName: string, requestData: string) {
this.isLoggedIn();
this.isRunning(modelName);
const result = await new Promise(async (resolve, reject) => {
const requestKey = Date.now();
const requesterAddress = this.ain.getAddress();
Expand Down

0 comments on commit 3262d40

Please sign in to comment.