From e9cf60dfa7c074248a9da3992997f393740cd328 Mon Sep 17 00:00:00 2001 From: reyraa Date: Mon, 18 Nov 2024 15:24:14 +0100 Subject: [PATCH] fix:pass token module methods as dependency --- src/app/app.ts | 4 +-- src/app/modules.ts | 8 ++++-- src/app/modules/campaign/module.ts | 45 ++++++++++-------------------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/app/app.ts b/src/app/app.ts index 6173d5a..2994aec 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -3,9 +3,9 @@ import { registerModules } from './modules'; import { registerPlugins } from './plugins'; export const getApplication = (config: Types.PartialApplicationConfig): Application => { - const { app } = Application.defaultApplication(config); + const { app, method } = Application.defaultApplication(config); - registerModules(app); + registerModules(app, method.token); registerPlugins(app); return app; diff --git a/src/app/modules.ts b/src/app/modules.ts index 9837295..a70bd94 100644 --- a/src/app/modules.ts +++ b/src/app/modules.ts @@ -1,7 +1,11 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { Application } from 'klayr-sdk'; +// eslint-disable-next-line import/no-extraneous-dependencies +import { Modules } from 'klayr-framework'; import { CampaignModule } from './modules/campaign/module'; -export const registerModules = (app: Application): void => { - app.registerModule(new CampaignModule()); +export const registerModules = (app: Application, token: Modules.Token.TokenMethod): void => { + const campaignModule = new CampaignModule(); + campaignModule.addDependencies(token); + app.registerModule(campaignModule); }; diff --git a/src/app/modules/campaign/module.ts b/src/app/modules/campaign/module.ts index cc0acd6..0ec42ac 100644 --- a/src/app/modules/campaign/module.ts +++ b/src/app/modules/campaign/module.ts @@ -29,6 +29,11 @@ import { CampaignMethod } from './method'; export class CampaignModule extends Modules.BaseModule { public endpoint = new CampaignEndpoint(this.stores, this.offchainStores); public method = new CampaignMethod(this.stores, this.events); + + private readonly _contributeCommand = new ContributeCommand(this.stores, this.events); + private readonly _payoutCommand = new PayoutCommand(this.stores, this.events); + private readonly _reimburseCommand = new ReimburseCommand(this.stores, this.events); + public commands = [ new CreateCommand(this.stores, this.events), new AddTierCommand(this.stores, this.events), @@ -37,6 +42,7 @@ export class CampaignModule extends Modules.BaseModule { new PayoutCommand(this.stores, this.events), new ReimburseCommand(this.stores, this.events), ]; + private _tokenMethod!: Modules.Token.TokenMethod; public constructor() { super(); @@ -54,6 +60,14 @@ export class CampaignModule extends Modules.BaseModule { this.events.register(CampaignPayoutProcessed, new CampaignPayoutProcessed(this.name)); } + public addDependencies(tokenMethod: Modules.Token.TokenMethod): void { + this._tokenMethod = tokenMethod; + + this._contributeCommand.addDependencies(this._tokenMethod); + this._payoutCommand.addDependencies(this._tokenMethod); + this._reimburseCommand.addDependencies(this._tokenMethod); + } + public metadata(): Modules.ModuleMetadata { return { ...this.baseMetadata(), @@ -61,35 +75,4 @@ export class CampaignModule extends Modules.BaseModule { assets: [], }; } - - // Lifecycle hooks - // public async init(_args: Modules.ModuleInitArgs): Promise { - // // initialize this module when starting a node - // } - - // public async insertAssets(_context: StateMachine.InsertAssetContext) { - // // initialize block generation, add asset - // } - - // public async verifyAssets(_context: StateMachine.BlockVerifyContext): Promise { - // // verify block - // } - - // Lifecycle hooks - // public async verifyTransaction(_context: StateMachine.TransactionVerifyContext): Promise { - // verify transaction will be called multiple times in the transaction pool - // return { status: StateMachine.VerifyStatus.OK }; - // } - - // public async beforeCommandExecute(_context: StateMachine.TransactionExecuteContext): Promise {} - - // public async afterCommandExecute(_context: StateMachine.TransactionExecuteContext): Promise {} - - // public async initGenesisState(_context: StateMachine.GenesisBlockExecuteContext): Promise {} - - // public async finalizeGenesisState(_context: StateMachine.GenesisBlockExecuteContext): Promise {} - - // public async beforeTransactionsExecute(_context: StateMachine.BlockExecuteContext): Promise {} - - // public async afterTransactionsExecute(_context: StateMachine.BlockAfterExecuteContext): Promise { }