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

Add set service billing config. #32

Merged
merged 2 commits into from
Sep 13, 2023
Merged
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
28 changes: 23 additions & 5 deletions src/modules/app.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 } from "../constants";
import { appBillingConfig, setRuleParam, setTriggerFunctionParm, triggerFunctionConfig } from "../types/type";
import { appBillingConfig, serviceBillingConfig, setRuleParam, setTriggerFunctionParm, triggerFunctionConfig } from "../types/type";
import { buildSetOperation } from "../utils/builder";
import ModuleBase from "./moduleBase";

Expand Down Expand Up @@ -40,7 +40,7 @@ export default class App extends ModuleBase {
}
}
}
const configOp = this.buildSetBillingConfigOp(appName, defaultConfig);
const configOp = this.buildSetAppBillingConfigOp(appName, defaultConfig);
setBillingConfigOps.push(configOp);

const txBody = this.buildTxBody([
Expand All @@ -58,8 +58,21 @@ export default class App extends ModuleBase {
* @param {appBillingConfig} config - The configuration of your app's billing.
* @returns Result of transaction.
*/
async setBillingConfig(appName: string, config: appBillingConfig) {
const setConfigOp = this.buildSetBillingConfigOp(appName, config);
async setAppBillingConfig(appName: string, config: appBillingConfig) {
const setConfigOp = this.buildSetAppBillingConfigOp(appName, config);
const txBody = this.buildTxBody(setConfigOp);
return await this.sendTransaction(txBody);
}

/**
* Set billing config to a specific service.
* @param {string} appName
* @param {string} serviceName
* @param {serviceBillingConfig} config
* @returns Result of transaction.
*/
async setServiceBillingConfig(appName: string, serviceName: string, config: serviceBillingConfig) {
const setConfigOp = this.buildSetServiceBillingConfigOp(appName, serviceName, config);
const txBody = this.buildTxBody(setConfigOp);
return await this.sendTransaction(txBody);
}
Expand Down Expand Up @@ -142,11 +155,16 @@ export default class App extends ModuleBase {
return await this.ain.db.ref(balancePath).getValue();
}

private buildSetBillingConfigOp(appName: string, config: appBillingConfig) {
private buildSetAppBillingConfigOp(appName: string, config: appBillingConfig) {
const path = Path.app(appName).billingConfig();
return buildSetOperation("SET_VALUE", path, config);
}

private buildSetServiceBillingConfigOp(appName: string,serviceName: string, config: serviceBillingConfig) {
const path = Path.app(appName).billingConfigOfService(serviceName);
return buildSetOperation("SET_VALUE", path, config);
}

private buildCreateAppOp(appName: string): SetOperation {
const path = `/manage_app/${appName}/create/${Date.now()}`;
const adminAccount = this.getDefaultAccount();
Expand Down