Skip to content

Commit

Permalink
fix:pass token module methods as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa committed Nov 18, 2024
1 parent 2afd0eb commit e9cf60d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/app/modules.ts
Original file line number Diff line number Diff line change
@@ -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);
};
45 changes: 14 additions & 31 deletions src/app/modules/campaign/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
Expand All @@ -54,42 +60,19 @@ 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(),
endpoints: [],
assets: [],
};
}

// Lifecycle hooks
// public async init(_args: Modules.ModuleInitArgs): Promise<void> {
// // 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<void> {
// // verify block
// }

// Lifecycle hooks
// public async verifyTransaction(_context: StateMachine.TransactionVerifyContext): Promise<StateMachine.VerificationResult> {
// verify transaction will be called multiple times in the transaction pool
// return { status: StateMachine.VerifyStatus.OK };
// }

// public async beforeCommandExecute(_context: StateMachine.TransactionExecuteContext): Promise<void> {}

// public async afterCommandExecute(_context: StateMachine.TransactionExecuteContext): Promise<void> {}

// public async initGenesisState(_context: StateMachine.GenesisBlockExecuteContext): Promise<void> {}

// public async finalizeGenesisState(_context: StateMachine.GenesisBlockExecuteContext): Promise<void> {}

// public async beforeTransactionsExecute(_context: StateMachine.BlockExecuteContext): Promise<void> {}

// public async afterTransactionsExecute(_context: StateMachine.BlockAfterExecuteContext): Promise<void> {
}

0 comments on commit e9cf60d

Please sign in to comment.