Skip to content

Commit

Permalink
feat: add setContainerStatus and use on createApp
Browse files Browse the repository at this point in the history
  • Loading branch information
yoojinko committed Sep 19, 2023
1 parent 2f3edc0 commit 94fda8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/controllers/appController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SetOperation } from "@ainblockchain/ain-js/lib/types";
import { Path, defaultAppRules } from "../constants";
import { appBillingConfig, createAppConfig, setRuleParam, setTriggerFunctionParm, triggerFunctionConfig } from "../types/type";
import { ContainerStatus, appBillingConfig, createAppConfig, setRuleParam, setTriggerFunctionParm, triggerFunctionConfig } from "../types/type";
import { buildSetOperation, buildTxBody } from "../utils/builder";
import AinModule from '../ain';

Expand Down Expand Up @@ -42,11 +42,14 @@ export default class AppController {
const configOp = this.buildSetAppBillingConfigOp(appName, billingConfig);
setBillingConfigOps.push(configOp);

const statusOp = this.buildSetContainerStatusOp(appName, ContainerStatus.RUNNING);

const txBody = buildTxBody([
createAppOp,
...setRuleOps,
...setFunctionOps,
...setBillingConfigOps,
statusOp,
]);
return await this.ain.sendTransaction(txBody);
}
Expand Down Expand Up @@ -112,6 +115,12 @@ export default class AppController {
return await this.ain.sendTransaction(txBody);
}

async setContainerStatus(appName: string, status: ContainerStatus) {
const op = this.buildSetContainerStatusOp(appName, status);
const txBody = buildTxBody(op);
return await this.ain.sendTransaction(txBody);
}

/**
* Add admin on app.
* @param {string} appName
Expand All @@ -136,7 +145,7 @@ export default class AppController {
return await this.ain.sendTransaction(txBody);
}

/**
/**
* Check cost of request and check if account can pay. You should use this function before send or handle request.
* If you don't set address, it will use default account's address.
* @param {string} appName - App name you want to request service to.
Expand Down Expand Up @@ -166,6 +175,11 @@ export default class AppController {
return await this.ain.getValue(balancePath);
}

private buildSetContainerStatusOp(appName: string, status: ContainerStatus) {
const path = Path.app(appName).status();
return buildSetOperation("SET_VALUE", path, status);
}

private buildSetAppBillingConfigOp(appName: string, config: appBillingConfig) {
const path = Path.app(appName).billingConfig();
return buildSetOperation("SET_VALUE", path, config);
Expand Down
5 changes: 5 additions & 0 deletions src/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ export type createAppConfig = {
billingConfig: appBillingConfig,
serviceUrl: string,
}

export enum ContainerStatus {
RUNNING = "RUNNING",
STOP = "STOP",
}

0 comments on commit 94fda8e

Please sign in to comment.