diff --git a/src/constants.ts b/src/constants.ts index bb8214a..cecbed1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -35,7 +35,9 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`, value: { ".rule": { - write: "data === null && util.isNumber(newData) && getValue(`/transfer/` + $userAddress + `/` + getValue(`/apps/" + `${appName}` + "/billingConfig/depositAddress`) + `/` + $transferKey + `/value`) === newData" + write: + "data === null && util.isNumber(newData) && " + + "getValue(`/transfer/` + $userAddress + `/` + getValue(`/apps/" + `${appName}` + "/billingConfig/depositAddress`) + `/` + $transferKey + `/value`) === newData" }, }, }, @@ -51,7 +53,10 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin ref: `${rootRef}/balance/$userAddress/history/$timestamp`, value: { ".rule": { - write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isNumber(newData.amount) && (newData.type === 'DEPOSIT' || newData.type === 'USAGE')" + write: + "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && " + + "util.isDict(newData) && util.isNumber(newData.amount) && " + + "(newData.type === 'DEPOSIT' || newData.type === 'USAGE')", }, }, }, @@ -60,9 +65,10 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin value: { ".rule": { write: - "auth.addr === $userAddress && " + + "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true || " + + "(auth.addr === $userAddress && " + "(getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`) === 0 || " + - "(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`)))" + "(getValue(`/apps/" + `${appName}` + "/balance/` + $userAddress + `/balance`) >= getValue(`/apps/" + `${appName}` + "/billingConfig/minCost`))))", }, }, }, diff --git a/src/internal.ts b/src/internal.ts index 57b676e..93482ef 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -22,10 +22,10 @@ export default class Internal { async handleRequest(req: Request, cost: number, status: RESPONSE_STATUS, responseData: string) { const { requesterAddress, requestKey, appName } = this.getDataFromServiceRequest(req); - const ops:SetOperation[] = []; + const ops: SetOperation[] = []; const responseOp = getResponseOp(appName, requesterAddress, requestKey, status, responseData, cost); ops.push(responseOp); - if(cost > 0) { + if (cost > 0) { const changeBalanceOp = getChangeBalanceOp(appName, requesterAddress, 'DEC_VALUE', cost); const writeHistoryOp = getWriteHistoryOp(appName, requesterAddress, HISTORY_TYPE.USAGE, cost, requestKey); ops.push(changeBalanceOp);