From 2cd16572230709ae138f198d86501255ff56828e Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 15:56:04 +0200 Subject: [PATCH 01/10] Create fee module index --- framework/src/modules/fee/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 framework/src/modules/fee/index.ts diff --git a/framework/src/modules/fee/index.ts b/framework/src/modules/fee/index.ts new file mode 100644 index 00000000000..a22298df1f6 --- /dev/null +++ b/framework/src/modules/fee/index.ts @@ -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'; From 1ef92334b28fc0ed037f0a35b6d62a4400083e52 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 15:56:27 +0200 Subject: [PATCH 02/10] Create api.ts --- framework/src/modules/fee/api.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 framework/src/modules/fee/api.ts diff --git a/framework/src/modules/fee/api.ts b/framework/src/modules/fee/api.ts new file mode 100644 index 00000000000..c18baa0d23c --- /dev/null +++ b/framework/src/modules/fee/api.ts @@ -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 {} From 0e58c46d13a6dea494897ee8e5c3638ea9c11116 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 15:56:42 +0200 Subject: [PATCH 03/10] Create constants.ts --- framework/src/modules/fee/constants.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 framework/src/modules/fee/constants.ts diff --git a/framework/src/modules/fee/constants.ts b/framework/src/modules/fee/constants.ts new file mode 100644 index 00000000000..01713caae78 --- /dev/null +++ b/framework/src/modules/fee/constants.ts @@ -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; From d4e11c3f1464963ad0e0d831a9e85bfe24939d55 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 18:48:32 +0200 Subject: [PATCH 04/10] Create endpoint.ts --- framework/src/modules/fee/endpoint.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 framework/src/modules/fee/endpoint.ts diff --git a/framework/src/modules/fee/endpoint.ts b/framework/src/modules/fee/endpoint.ts new file mode 100644 index 00000000000..5e6fc06ee3c --- /dev/null +++ b/framework/src/modules/fee/endpoint.ts @@ -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 {} From 16474ee48e2609cc0f88c300e20d04e21464b294 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 18:48:50 +0200 Subject: [PATCH 05/10] Create schemas.ts --- framework/src/modules/fee/schemas.ts | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 framework/src/modules/fee/schemas.ts diff --git a/framework/src/modules/fee/schemas.ts b/framework/src/modules/fee/schemas.ts new file mode 100644 index 00000000000..a1a29b2e2c3 --- /dev/null +++ b/framework/src/modules/fee/schemas.ts @@ -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'], +}; From 0efcf8f052d4bbecab178a8f7f0955ff0329f261 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 18:49:01 +0200 Subject: [PATCH 06/10] Create types.ts --- framework/src/modules/fee/types.ts | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 framework/src/modules/fee/types.ts diff --git a/framework/src/modules/fee/types.ts b/framework/src/modules/fee/types.ts new file mode 100644 index 00000000000..8c58da3a088 --- /dev/null +++ b/framework/src/modules/fee/types.ts @@ -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: { + chainID: number; + localID: number; + }; +} + +export interface TokenAPI { + transfer: ( + apiContext: APIContext, + senderAddress: Buffer, + generatorAddress: Buffer, + id: { chainID: number; localID: number }, + amount: bigint, + ) => Promise; + burn: ( + apiContext: APIContext, + senderAddress: Buffer, + id: { chainID: number; localID: number }, + amount: bigint, + ) => Promise; +} From f98b7ed03fbd295ea1ea5d8ee1eafa50297ce3f8 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 18:49:11 +0200 Subject: [PATCH 07/10] Update types.ts --- framework/src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/src/types.ts b/framework/src/types.ts index 33b1352dd96..828485161bb 100644 --- a/framework/src/types.ts +++ b/framework/src/types.ts @@ -77,7 +77,6 @@ export interface NetworkConfig { } export interface GenesisConfig { - [key: string]: unknown; bftThreshold: number; communityIdentifier: string; blockTime: number; From 81db6898d2b8aa0d7964d921489e1c4976751dae Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Mon, 30 Aug 2021 18:49:29 +0200 Subject: [PATCH 08/10] Create fee module class --- framework/src/modules/fee/module.ts | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 framework/src/modules/fee/module.ts diff --git a/framework/src/modules/fee/module.ts b/framework/src/modules/fee/module.ts new file mode 100644 index 00000000000..447e06aa283 --- /dev/null +++ b/framework/src/modules/fee/module.ts @@ -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; + 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; + private _moduleConfig!: ModuleConfig; + + public addDependencies(tokenAPI: TokenAPI) { + this._tokenAPI = tokenAPI; + } + + // eslint-disable-next-line @typescript-eslint/require-await + public async init(args: ModuleInitArgs): Promise { + 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 { + return { status: 1 }; + } + + // eslint-disable-next-line @typescript-eslint/require-await + public async beforeTransactionExecute(_context: TransactionExecuteContext): Promise { + // eslint-disable-next-line no-console + console.log(this._tokenAPI, this._minFeePerBytes, this._baseFees, this._moduleConfig); + } +} From 088a7c39dcf082822df654bc805c2c35c35c12d8 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Tue, 31 Aug 2021 09:46:23 +0200 Subject: [PATCH 09/10] Update module.ts --- framework/src/modules/fee/module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/src/modules/fee/module.ts b/framework/src/modules/fee/module.ts index 447e06aa283..f42a6cc5f76 100644 --- a/framework/src/modules/fee/module.ts +++ b/framework/src/modules/fee/module.ts @@ -13,6 +13,7 @@ */ import { BaseModule, ModuleInitArgs } from '../base_module'; +import { MODULE_ID_FEE } from './constants'; import { BaseFee, TokenAPI, ModuleConfig } from './types'; import { TransactionExecuteContext, @@ -24,7 +25,7 @@ import { FeeEndpoint } from './endpoint'; import { configSchema } from './schemas'; export class FeeModule extends BaseModule { - public id = 11; + public id = MODULE_ID_FEE; public name = 'fee'; public api = new FeeAPI(this.id); public configSchema = configSchema; From b7007d7a8d170c1754ba35d49f6418cdd687b3b9 Mon Sep 17 00:00:00 2001 From: Mitsuaki Uchimoto Date: Tue, 31 Aug 2021 11:39:27 +0200 Subject: [PATCH 10/10] Update types.ts --- framework/src/modules/fee/types.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/framework/src/modules/fee/types.ts b/framework/src/modules/fee/types.ts index 8c58da3a088..4a5f8242ad3 100644 --- a/framework/src/modules/fee/types.ts +++ b/framework/src/modules/fee/types.ts @@ -20,11 +20,13 @@ export interface BaseFee { baseFee: bigint; } +export interface FeeTokenID { + chainID: number; + localID: number; +} + export interface ModuleConfig { - feeTokenID: { - chainID: number; - localID: number; - }; + feeTokenID: FeeTokenID; } export interface TokenAPI { @@ -32,13 +34,13 @@ export interface TokenAPI { apiContext: APIContext, senderAddress: Buffer, generatorAddress: Buffer, - id: { chainID: number; localID: number }, + id: FeeTokenID, amount: bigint, ) => Promise; burn: ( apiContext: APIContext, senderAddress: Buffer, - id: { chainID: number; localID: number }, + id: FeeTokenID, amount: bigint, ) => Promise; }