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

Set GC rule for requestKey #119

Merged
merged 6 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions src/ain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransactionBody } from "@ainblockchain/ain-util";
import { txResult } from "./types/type";
import { Signer } from "@ainblockchain/ain-js/lib/signer/signer";
import { DefaultSigner } from "@ainblockchain/ain-js/lib/signer/default-signer"
import { GetOptions } from "@ainblockchain/ain-js/lib/types";

// NOTE(yoojin): Plz suggest a good name.
export default class AinModule {
Expand All @@ -20,7 +21,7 @@ export default class AinModule {
initAin(chainId: 0 | 1) {
const blockchainAPIEndpoint = getBlockChainAPIEndpoint(chainId);
const blockchainEventEndpoint = getBlockChainEventEndpoint(chainId);
this.ain = new Ain(blockchainAPIEndpoint,blockchainEventEndpoint, chainId);
this.ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, chainId);
}

createAccount() {
Expand Down Expand Up @@ -89,9 +90,9 @@ export default class AinModule {
return await this.ain!.db.ref(balancePath).getValue();
}

async getValue(path: string) {
async getValue(path: string, options?: GetOptions) {
this.checkAinInitiated();
return await this.ain!.db.ref(path).getValue();
return await this.ain!.db.ref().getValue(path, options);
}

private async _sendTransaction(txBody: TransactionBody) {
Expand Down
2 changes: 1 addition & 1 deletion src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class Ainize {
*/
async getService(serviceName: string): Promise<Service> {
const servicePath = Path.app(serviceName).root();
const serviceData = await this.ain.getValue(servicePath);
const serviceData = await this.ain.getValue(servicePath, { is_shallow: true });
Copy link
Contributor Author

@jiyoung-an jiyoung-an May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added is_shallow option, please check if other functions work well.

if(!serviceData) {
throw new Error("Service not found");
}
Expand Down
22 changes: 17 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ export const Path = {
service: () => `${Path.app(appName).root()}/service`,
userOfService: (userAddress: string) =>
`${Path.app(appName).service()}/${userAddress}`,
requestKey: (userAddress: string, requestKey: string) =>
`${Path.app(appName).userOfService(userAddress)}/${requestKey}`,
request: (userAddress: string, requestKey: string) =>
`${Path.app(appName).userOfService(userAddress)}/${requestKey}/request`,
`${Path.app(appName).requestKey(userAddress, requestKey)}/request`,
response: (userAddress: string, requestKey: string) =>
`${Path.app(appName).userOfService(userAddress)}/${requestKey}/response`,
`${Path.app(appName).requestKey(userAddress, requestKey)}/response`,
}
},
transfer: (from: string, to: string, transferKey: string) =>
`/transfer/${from}/${to}/${transferKey}/value`,
}

export const defaultAppRules = (appName: string): { [type: string]: { ref: string, value: object } } => {
const rootRef = Path.app(appName).root();
return {
deposit: {
ref: `${Path.app(appName).depositOfUser("$userAddress")}/$transferKey`,
Expand All @@ -54,7 +55,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
},
},
balanceHistory: {
ref: `${rootRef}/balance/$userAddress/history/$timestamp`,
ref: `${Path.app(appName).balance()}/$userAddress/history/$timestamp`,
value: {
".rule": {
write:
Expand All @@ -64,6 +65,17 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
},
},
},
requestKey: {
ref: Path.app(appName).requestKey("$userAddress", "$requestKey"),
value: {
".rule": {
state: {
gc_max_siblings: 20,
gc_num_siblings_deleted: 10,
},
},
}
},
request: {
ref: Path.app(appName).request("$userAddress", "$requestKey"),
value: {
Expand All @@ -77,7 +89,7 @@ export const defaultAppRules = (appName: string): { [type: string]: { ref: strin
},
},
response: {
ref: Path.app(appName).response("userAddress", "$requestKey"),
ref: Path.app(appName).response("$userAddress", "$requestKey"),
value: {
".rule": {
write: "util.isAppAdmin(`" + `${appName}` + "`, auth.addr, getValue) === true && util.isDict(newData) && util.isString(newData.status)"
Expand Down
Loading