From 478516effde7f5f53d9f1289d24197ae4f6aec5a Mon Sep 17 00:00:00 2001 From: Warrior-7 Date: Tue, 26 Dec 2023 00:26:41 +0330 Subject: [PATCH 1/2] add PermitTx, GetPermitBuilder and ReturnPermitBuilder classes --- package-lock.json | 16 +++ .../permit/lib/GetPermitBuilder.ts | 15 +++ packages/transactions/permit/lib/PermitTx.ts | 107 ++++++++++++++++++ .../permit/lib/ReturnPermitBuilder.ts | 15 +++ packages/transactions/permit/lib/index.ts | 3 + packages/transactions/permit/package.json | 4 + 6 files changed, 160 insertions(+) create mode 100644 packages/transactions/permit/lib/GetPermitBuilder.ts create mode 100644 packages/transactions/permit/lib/PermitTx.ts create mode 100644 packages/transactions/permit/lib/ReturnPermitBuilder.ts diff --git a/package-lock.json b/package-lock.json index f5a528c6..328a32cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9449,6 +9449,10 @@ "name": "permit-tx", "version": "0.1.0", "license": "GPL-3.0", + "dependencies": { + "@rosen-bridge/abstract-logger": "^1.0.0", + "@rosen-bridge/rwt-repo": "^2.0.0" + }, "devDependencies": { "@types/node": "^18.11.18", "@typescript-eslint/eslint-plugin": "^6.7.0", @@ -9464,6 +9468,11 @@ "node": ">=18.12.0" } }, + "packages/transactions/permit/node_modules/@rosen-bridge/abstract-logger": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@rosen-bridge/abstract-logger/-/abstract-logger-1.0.0.tgz", + "integrity": "sha512-hN/cb0HSlhqvaEjqzFPZGIYOa70gdPd+mYrS5C7uNrv1Vw6k2k4lY4US05rwBENjSQpwik1H4gdCBzUkbCcjGA==" + }, "packages/transactions/permit/node_modules/@types/node": { "version": "18.19.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.3.tgz", @@ -14480,6 +14489,8 @@ "permit-tx": { "version": "file:packages/transactions/permit", "requires": { + "@rosen-bridge/abstract-logger": "^1.0.0", + "@rosen-bridge/rwt-repo": "^2.0.0", "@types/node": "^18.11.18", "@typescript-eslint/eslint-plugin": "^6.7.0", "@typescript-eslint/parser": "^6.7.0", @@ -14491,6 +14502,11 @@ "vitest": "^0.26.2" }, "dependencies": { + "@rosen-bridge/abstract-logger": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@rosen-bridge/abstract-logger/-/abstract-logger-1.0.0.tgz", + "integrity": "sha512-hN/cb0HSlhqvaEjqzFPZGIYOa70gdPd+mYrS5C7uNrv1Vw6k2k4lY4US05rwBENjSQpwik1H4gdCBzUkbCcjGA==" + }, "@types/node": { "version": "18.19.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.3.tgz", diff --git a/packages/transactions/permit/lib/GetPermitBuilder.ts b/packages/transactions/permit/lib/GetPermitBuilder.ts new file mode 100644 index 00000000..840c1f7c --- /dev/null +++ b/packages/transactions/permit/lib/GetPermitBuilder.ts @@ -0,0 +1,15 @@ +import { AbstractLogger } from '@rosen-bridge/abstract-logger'; +import { RWTRepo } from '@rosen-bridge/rwt-repo'; + +export class GetPermitBuilder { + constructor( + private permitAddress: string, + private collateralAddress: string, + private changeAddress: string, + private rsn: string, + private rwt: string, + private txFee: string, + private rwtRepo: RWTRepo, + private logger?: AbstractLogger + ) {} +} diff --git a/packages/transactions/permit/lib/PermitTx.ts b/packages/transactions/permit/lib/PermitTx.ts new file mode 100644 index 00000000..4f91547c --- /dev/null +++ b/packages/transactions/permit/lib/PermitTx.ts @@ -0,0 +1,107 @@ +import { AbstractLogger } from '@rosen-bridge/abstract-logger'; +import { RWTRepo } from '@rosen-bridge/rwt-repo'; +import { GetPermitBuilder } from './GetPermitBuilder'; +import { ReturnPermitBuilder } from './ReturnPermitBuilder'; + +export class PermitTx { + private static _instance?: PermitTx; + + private constructor( + private permitAddress: string, + private collateralAddress: string, + private changeAddress: string, + private rsn: string, + private rwt: string, + private txFee: string, + private rwtRepo: RWTRepo, + private logger?: AbstractLogger + ) {} + + /** + * initializes the singleton instance of PermitTx + * + * @static + * @param {string} permitAddress + * @param {string} collateralAddress + * @param {string} changeAddress + * @param {string} rsn + * @param {string} rwt + * @param {string} txFee + * @param {RWTRepo} rwtRepo + * @param {AbstractLogger} [logger] + */ + static init = ( + permitAddress: string, + collateralAddress: string, + changeAddress: string, + rsn: string, + rwt: string, + txFee: string, + rwtRepo: RWTRepo, + logger?: AbstractLogger + ): void => { + if (PermitTx._instance != undefined) { + throw new Error('The singleton instance is already initialized.'); + } + + PermitTx._instance = new PermitTx( + permitAddress, + collateralAddress, + changeAddress, + rsn, + rwt, + txFee, + rwtRepo, + logger + ); + }; + + /** + * return the singleton instance of PermitTx + * + * @static + * @return {PermitTx} + */ + static getInstance = (): PermitTx => { + if (!this._instance) { + throw new Error('PermitTx instance is not initialized yet'); + } + return this._instance; + }; + + /** + * creates a new instance of GetPermitBuilder + * + * @return {GetPermitBuilder} + */ + newGetPermitBuilder = (): GetPermitBuilder => { + return new GetPermitBuilder( + this.permitAddress, + this.collateralAddress, + this.changeAddress, + this.rsn, + this.rwt, + this.txFee, + this.rwtRepo, + this.logger + ); + }; + + /** + * creates a new instance of ReturnPermitBuilder + * + * @return {ReturnPermitBuilder} + */ + newًReturnPermitBuilder = (): ReturnPermitBuilder => { + return new ReturnPermitBuilder( + this.permitAddress, + this.collateralAddress, + this.changeAddress, + this.rsn, + this.rwt, + this.txFee, + this.rwtRepo, + this.logger + ); + }; +} diff --git a/packages/transactions/permit/lib/ReturnPermitBuilder.ts b/packages/transactions/permit/lib/ReturnPermitBuilder.ts new file mode 100644 index 00000000..e956d475 --- /dev/null +++ b/packages/transactions/permit/lib/ReturnPermitBuilder.ts @@ -0,0 +1,15 @@ +import { AbstractLogger } from '@rosen-bridge/abstract-logger'; +import { RWTRepo } from '@rosen-bridge/rwt-repo'; + +export class ReturnPermitBuilder { + constructor( + private permitAddress: string, + private collateralAddress: string, + private changeAddress: string, + private rsn: string, + private rwt: string, + private txFee: string, + private rwtRepo: RWTRepo, + private logger?: AbstractLogger + ) {} +} diff --git a/packages/transactions/permit/lib/index.ts b/packages/transactions/permit/lib/index.ts index e69de29b..256b640d 100644 --- a/packages/transactions/permit/lib/index.ts +++ b/packages/transactions/permit/lib/index.ts @@ -0,0 +1,3 @@ +export * from './GetPermitBuilder'; +export * from './PermitTx'; +export * from './ReturnPermitBuilder'; diff --git a/packages/transactions/permit/package.json b/packages/transactions/permit/package.json index 374f5a68..122e59b6 100644 --- a/packages/transactions/permit/package.json +++ b/packages/transactions/permit/package.json @@ -30,5 +30,9 @@ }, "engines": { "node": ">=18.12.0" + }, + "dependencies": { + "@rosen-bridge/abstract-logger": "^1.0.0", + "@rosen-bridge/rwt-repo": "^2.0.0" } } From 7a3fa9658804c63a42e524d131e3ca2d830a29cf Mon Sep 17 00:00:00 2001 From: Warrior-7 Date: Wed, 27 Dec 2023 21:11:07 +0330 Subject: [PATCH 2/2] change PermitTx singleton instance name --- packages/transactions/permit/lib/PermitTx.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/transactions/permit/lib/PermitTx.ts b/packages/transactions/permit/lib/PermitTx.ts index 4f91547c..6d772f8d 100644 --- a/packages/transactions/permit/lib/PermitTx.ts +++ b/packages/transactions/permit/lib/PermitTx.ts @@ -4,7 +4,7 @@ import { GetPermitBuilder } from './GetPermitBuilder'; import { ReturnPermitBuilder } from './ReturnPermitBuilder'; export class PermitTx { - private static _instance?: PermitTx; + private static instance?: PermitTx; private constructor( private permitAddress: string, @@ -40,11 +40,11 @@ export class PermitTx { rwtRepo: RWTRepo, logger?: AbstractLogger ): void => { - if (PermitTx._instance != undefined) { + if (PermitTx.instance != undefined) { throw new Error('The singleton instance is already initialized.'); } - PermitTx._instance = new PermitTx( + PermitTx.instance = new PermitTx( permitAddress, collateralAddress, changeAddress, @@ -63,10 +63,10 @@ export class PermitTx { * @return {PermitTx} */ static getInstance = (): PermitTx => { - if (!this._instance) { + if (!this.instance) { throw new Error('PermitTx instance is not initialized yet'); } - return this._instance; + return this.instance; }; /**