Skip to content

Commit

Permalink
Merge branch 'PermitTx,-GetPermitBuilder,-ReturnPermitBuilder-classes…
Browse files Browse the repository at this point in the history
…' into 'dev'

Permit tx, get permit builder, return permit builder classes

Closes #196

See merge request ergo/rosen-bridge/watcher!214
  • Loading branch information
vorujack committed Dec 27, 2023
2 parents 3884843 + 7a3fa96 commit 815416f
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions packages/transactions/permit/lib/GetPermitBuilder.ts
Original file line number Diff line number Diff line change
@@ -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
) {}
}
107 changes: 107 additions & 0 deletions packages/transactions/permit/lib/PermitTx.ts
Original file line number Diff line number Diff line change
@@ -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
);
};
}
15 changes: 15 additions & 0 deletions packages/transactions/permit/lib/ReturnPermitBuilder.ts
Original file line number Diff line number Diff line change
@@ -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
) {}
}
3 changes: 3 additions & 0 deletions packages/transactions/permit/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './GetPermitBuilder';
export * from './PermitTx';
export * from './ReturnPermitBuilder';
4 changes: 4 additions & 0 deletions packages/transactions/permit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@
},
"engines": {
"node": ">=18.12.0"
},
"dependencies": {
"@rosen-bridge/abstract-logger": "^1.0.0",
"@rosen-bridge/rwt-repo": "^2.0.0"
}
}

0 comments on commit 815416f

Please sign in to comment.