Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Create fee module class - Closes #6692 #6700

Merged
merged 10 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
17 changes: 17 additions & 0 deletions framework/src/modules/fee/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseAPI } from '../base_api';

export class FeeAPI extends BaseAPI {}
15 changes: 15 additions & 0 deletions framework/src/modules/fee/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export const MODULE_ID_FEE = 1;
17 changes: 17 additions & 0 deletions framework/src/modules/fee/endpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseEndpoint } from '../base_endpoint';

export class FeeEndpoint extends BaseEndpoint {}
15 changes: 15 additions & 0 deletions framework/src/modules/fee/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export { FeeModule } from './module';
59 changes: 59 additions & 0 deletions framework/src/modules/fee/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { BaseModule, ModuleInitArgs } from '../base_module';
import { BaseFee, TokenAPI, ModuleConfig } from './types';
import {
TransactionExecuteContext,
TransactionVerifyContext,
VerificationResult,
} from '../../node/state_machine';
import { FeeAPI } from './api';
import { FeeEndpoint } from './endpoint';
import { configSchema } from './schemas';

export class FeeModule extends BaseModule {
public id = 11;
mitsuaki-u marked this conversation as resolved.
Show resolved Hide resolved
public name = 'fee';
public api = new FeeAPI(this.id);
public configSchema = configSchema;
public endpoint = new FeeEndpoint(this.id);
private _tokenAPI!: TokenAPI;
private _minFeePerBytes!: number;
private _baseFees!: Array<BaseFee>;
private _moduleConfig!: ModuleConfig;

public addDependencies(tokenAPI: TokenAPI) {
this._tokenAPI = tokenAPI;
}

// eslint-disable-next-line @typescript-eslint/require-await
public async init(args: ModuleInitArgs): Promise<void> {
const { genesisConfig, moduleConfig } = args;
this._moduleConfig = (moduleConfig as unknown) as ModuleConfig;
this._minFeePerBytes = genesisConfig.minFeePerByte;
this._baseFees = genesisConfig.baseFees.map(fee => ({ ...fee, baseFee: BigInt(fee.baseFee) }));
}

// eslint-disable-next-line @typescript-eslint/require-await
public async verifyTransaction(_context: TransactionVerifyContext): Promise<VerificationResult> {
return { status: 1 };
}

// eslint-disable-next-line @typescript-eslint/require-await
public async beforeTransactionExecute(_context: TransactionExecuteContext): Promise<void> {
// eslint-disable-next-line no-console
console.log(this._tokenAPI, this._minFeePerBytes, this._baseFees, this._moduleConfig);
}
}
32 changes: 32 additions & 0 deletions framework/src/modules/fee/schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

export const configSchema = {
$id: '/fee/config',
type: 'object',
properties: {
feeTokenID: {
type: 'object',
properties: {
chainID: {
dataType: 'uint32',
},
localID: {
dataType: 'uint32',
},
},
},
},
required: ['feeTokenID'],
};
44 changes: 44 additions & 0 deletions framework/src/modules/fee/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright © 2021 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/

import { APIContext } from '../../node/state_machine';

export interface BaseFee {
moduleID: number;
commandID: number;
baseFee: bigint;
}

export interface ModuleConfig {
feeTokenID: {
mitsuaki-u marked this conversation as resolved.
Show resolved Hide resolved
chainID: number;
localID: number;
};
}

export interface TokenAPI {
transfer: (
apiContext: APIContext,
senderAddress: Buffer,
generatorAddress: Buffer,
id: { chainID: number; localID: number },
mitsuaki-u marked this conversation as resolved.
Show resolved Hide resolved
amount: bigint,
) => Promise<void>;
burn: (
apiContext: APIContext,
senderAddress: Buffer,
id: { chainID: number; localID: number },
mitsuaki-u marked this conversation as resolved.
Show resolved Hide resolved
amount: bigint,
) => Promise<void>;
}
1 change: 0 additions & 1 deletion framework/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export interface NetworkConfig {
}

export interface GenesisConfig {
[key: string]: unknown;
bftThreshold: number;
communityIdentifier: string;
blockTime: number;
Expand Down