From 19044eee626e6329cb64b7189e676e6fd82d2a87 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 15:50:26 +0900 Subject: [PATCH 01/10] fix: throw all tx result --- src/modules/moduleBase.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/modules/moduleBase.ts b/src/modules/moduleBase.ts index 163d948..56789a9 100644 --- a/src/modules/moduleBase.ts +++ b/src/modules/moduleBase.ts @@ -32,25 +32,22 @@ export default class ModuleBase { return await this.ain.sendTransaction(txBody); } - private getFailedOpResultList(result: txResult): opResult[] { + private hasFailedOpResultList(result: txResult): boolean { if (result.result_list) { - return Object.values(result.result_list).filter( + return Object.values(result.result_list).some( (result: { code: number }) => result.code !== 0 ); } - return []; + return result.code !== 0; } private handleTxResultWrapper(operation: Function) { return async (args: any) => { const res = await operation(args); const { tx_hash, result } = res; - const failedOpResult = this.getFailedOpResultList(result); - if (failedOpResult.length > 0) { - const errorString = failedOpResult.map((value) => `\n code: ${value.code} - ${value.message}`); - console.log('failedOpResult :>> ', failedOpResult); + if (this.hasFailedOpResultList(result)) { throw new Error( - `Failed to send transaction (${tx_hash}).` + errorString + `Failed to send transaction (${tx_hash}).\n Tx Result: ${JSON.stringify(result)}` ); } return tx_hash; From 603c0ecb41a01c7938364d68259971b7fee21100 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 15:51:04 +0900 Subject: [PATCH 02/10] fix: billing config rules --- src/modules/app.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 7f92ce5..b46373d 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -283,19 +283,11 @@ export default class App extends ModuleBase { ref: Path.app(appName).billingConfig(), value: { ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && " + - "util.isString(newData.depositAddress) && util.isDict(newData.service) && util.isDict(newData.service.default)", + write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.depositAddress) && " + + "util.isDict(newData.service) && util.isDict(newData.service.default) && util.isNumber(newData.service.default.costPerToken) && util.isNumber(newData.service.default.minCost)", } } }, - billingConfigOfService: { - ref: Path.app(appName).billingConfigOfService("$serviceName"), - value: { - ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth,addr, getValue) === true && util.isDict(newData) && util.isNumber(newData.minCost)", - } - } - } } } From 99fc5802e9974e9a17eff06600cc9fe3216db621 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 15:54:16 +0900 Subject: [PATCH 03/10] fix: request rule --- 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 b46373d..7eeddb5 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -266,7 +266,7 @@ export default class App extends ModuleBase { ".rule": { write: "auth.addr === $userAddress && getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) !== null && " + - "((getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName) !== null) && (getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`)) || " + + "((getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`) !== null) && (getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`)) || " + "getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/service/default/minCost`)" } } From a751210f1b683f0a7961eba0e3c18eedfe2a3ecb Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 16:02:45 +0900 Subject: [PATCH 04/10] feat: add maxCost rule --- src/modules/app.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 7eeddb5..cd8152d 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -284,7 +284,8 @@ export default class App extends ModuleBase { value: { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.depositAddress) && " + - "util.isDict(newData.service) && util.isDict(newData.service.default) && util.isNumber(newData.service.default.costPerToken) && util.isNumber(newData.service.default.minCost)", + "util.isDict(newData.service) && util.isDict(newData.service.default) && util.isNumber(newData.service.default.costPerToken) && util.isNumber(newData.service.default.minCost) && " + + "util.isNull(newData.service.default.maxCost) || (util.isNumber(newData.service.default.maxCost) && newData.service.default.maxCost >= newData.service.default.minCost", } } }, From 26d0c5a1d340d6d8cfd6c01b96910a414c453c95 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 16:10:58 +0900 Subject: [PATCH 05/10] fix: typo --- 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 cd8152d..e67272d 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -285,7 +285,7 @@ export default class App extends ModuleBase { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.depositAddress) && " + "util.isDict(newData.service) && util.isDict(newData.service.default) && util.isNumber(newData.service.default.costPerToken) && util.isNumber(newData.service.default.minCost) && " + - "util.isNull(newData.service.default.maxCost) || (util.isNumber(newData.service.default.maxCost) && newData.service.default.maxCost >= newData.service.default.minCost", + "util.isNull(newData.service.default.maxCost) || (util.isNumber(newData.service.default.maxCost) && newData.service.default.maxCost >= newData.service.default.minCost)", } } }, From b2c93b378d3224ca6c46756ad5c805a27b653366 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 16:20:25 +0900 Subject: [PATCH 06/10] fix: rule null check --- src/modules/app.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index e67272d..3060279 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -44,9 +44,9 @@ export default class App extends ModuleBase { setBillingConfigOps.push(configOp); const txBody = this.buildTxBody([ - createAppOp, + // createAppOp, ...setRuleOps, - ...setFunctionOps, + // ...setFunctionOps, ...setBillingConfigOps, ]); return await this.sendTransaction(txBody); @@ -285,7 +285,7 @@ export default class App extends ModuleBase { ".rule": { write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.depositAddress) && " + "util.isDict(newData.service) && util.isDict(newData.service.default) && util.isNumber(newData.service.default.costPerToken) && util.isNumber(newData.service.default.minCost) && " + - "util.isNull(newData.service.default.maxCost) || (util.isNumber(newData.service.default.maxCost) && newData.service.default.maxCost >= newData.service.default.minCost)", + "util.isEmpty(newData.service.default.maxCost) || (util.isNumber(newData.service.default.maxCost) && newData.service.default.maxCost >= newData.service.default.minCost)", } } }, From 227713e4c25622e9152d47c9a10a9aa0613f3e62 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 17:19:09 +0900 Subject: [PATCH 07/10] fix: request rull null check --- src/modules/app.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 3060279..fb1bc7a 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -92,7 +92,7 @@ export default class App extends ModuleBase { * @param {setTriggerFunctionParam[]} functions * @returns Result of transaction. */ - async setTriggerFunctions(appName: string, functions: setTriggerFunctionParm[]) { + async setTriggerFunctions(appName: string, functions: any[]) { const setFunctionOps: SetOperation[] = []; for (const param of Object.values(functions)) { const value = this.buildSetFunctionValue(param); @@ -266,7 +266,7 @@ export default class App extends ModuleBase { ".rule": { write: "auth.addr === $userAddress && getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) !== null && " + - "((getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`) !== null) && (getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`)) || " + + "(!util.isEmpty(getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`))) && (getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/` + $serviceName + `/minCost`)) || " + "getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/service/default/minCost`)" } } From d01dd71b7e1963de6af537160ff78961c6b616d1 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 17:19:26 +0900 Subject: [PATCH 08/10] fix: send transaction to wrapped method --- src/modules/wallet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/wallet.ts b/src/modules/wallet.ts index e585072..16dc8d4 100644 --- a/src/modules/wallet.ts +++ b/src/modules/wallet.ts @@ -62,6 +62,6 @@ export default class Wallet extends ModuleBase{ throw new Error ("You need to add account"); } txBody.address = signerAddress; - return await this.ain.sendTransaction(txBody); + return await this.sendTransaction(txBody); } } From f7a870ed6adb029cdc1d33f5453c711b2ff9f0cd Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 17:20:09 +0900 Subject: [PATCH 09/10] fix: uncomment --- src/modules/app.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index fb1bc7a..064875e 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -44,9 +44,9 @@ export default class App extends ModuleBase { setBillingConfigOps.push(configOp); const txBody = this.buildTxBody([ - // createAppOp, + createAppOp, ...setRuleOps, - // ...setFunctionOps, + ...setFunctionOps, ...setBillingConfigOps, ]); return await this.sendTransaction(txBody); From 92186d1f9380341d4c7c89663f9659703eece3a4 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 13 Sep 2023 17:23:04 +0900 Subject: [PATCH 10/10] fix: type --- 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 064875e..8fd74c6 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -92,7 +92,7 @@ export default class App extends ModuleBase { * @param {setTriggerFunctionParam[]} functions * @returns Result of transaction. */ - async setTriggerFunctions(appName: string, functions: any[]) { + async setTriggerFunctions(appName: string, functions: setTriggerFunctionParm[]) { const setFunctionOps: SetOperation[] = []; for (const param of Object.values(functions)) { const value = this.buildSetFunctionValue(param);