diff --git a/src/modules/app.ts b/src/modules/app.ts index 6f9e821..e3384e3 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -273,7 +273,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`)) || " + + "(!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`)" } } @@ -290,19 +290,12 @@ 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) && " + + "util.isEmpty(newData.service.default.maxCost) || (util.isNumber(newData.service.default.maxCost) && newData.service.default.maxCost >= 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)", - } - } - } } } 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; 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); } }