From 435102e2f22ec721126266e24cea932250303e58 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 09:53:29 +0900 Subject: [PATCH 1/2] feat: add serviceBillingConfig --- src/modules/app.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 50bb1f4..3bde511 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -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"; @@ -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([ @@ -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); } @@ -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(); From 8d4124f5ff4190b0a92ac2f0e180c5d520c2becb Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 10:01:57 +0900 Subject: [PATCH 2/2] style: space --- src/modules/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 3bde511..80351b1 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -160,7 +160,7 @@ export default class App extends ModuleBase { return buildSetOperation("SET_VALUE", path, config); } - private buildSetServiceBillingConfigOp(appName: string,serviceName: string, config: serviceBillingConfig) { + private buildSetServiceBillingConfigOp(appName: string, serviceName: string, config: serviceBillingConfig) { const path = Path.app(appName).billingConfigOfService(serviceName); return buildSetOperation("SET_VALUE", path, config); }