Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connect #47

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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