This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6748 from LiskHQ/6669-init-validators-module
Create module class, constants, schemas for validators module - Closes #6669
- Loading branch information
Showing
10 changed files
with
163 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 { MODULE_ID_VALIDATORS } from './constants'; | ||
import { GenesisBlockExecuteContext } from '../../node/state_machine'; | ||
import { ValidatorsAPI } from './api'; | ||
import { ValidatorsEndpoint } from './endpoint'; | ||
|
||
export class ValidatorsModule extends BaseModule { | ||
public id = MODULE_ID_VALIDATORS; | ||
public name = 'validators'; | ||
public api = new ValidatorsAPI(this.id); | ||
public endpoint = new ValidatorsEndpoint(this.id); | ||
private _blockTime!: number; | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
public async init(args: ModuleInitArgs): Promise<void> { | ||
const { moduleConfig } = args; | ||
const { blockTime } = moduleConfig; | ||
|
||
if (!blockTime || typeof blockTime !== 'number') { | ||
throw new Error('BlockTime must be a number.'); | ||
} | ||
if (blockTime < 1) { | ||
throw new Error('Block time cannot be less than 1.'); | ||
} | ||
this._blockTime = blockTime; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
public async afterGenesisBlockExecute(_context: GenesisBlockExecuteContext): Promise<void> { | ||
// eslint-disable-next-line no-console | ||
console.log(this._blockTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 validatorAccountSchema = { | ||
type: 'object', | ||
properties: { | ||
generatorKey: { | ||
dataType: 'bytes', | ||
fieldNumber: 1, | ||
}, | ||
blsKey: { | ||
dataType: 'bytes', | ||
fieldNumber: 2, | ||
}, | ||
}, | ||
required: ['generatorKey', 'blsKey'], | ||
}; | ||
|
||
export const generatorListSchema = { | ||
type: 'object', | ||
properties: { | ||
addresses: { | ||
type: 'array', | ||
fieldNumber: 1, | ||
items: { | ||
dataType: 'bytes', | ||
}, | ||
}, | ||
}, | ||
required: ['addresses'], | ||
}; | ||
|
||
export const validatorAddressSchema = { | ||
type: 'object', | ||
properties: { | ||
address: { | ||
dataType: 'bytes', | ||
fieldNumber: 1, | ||
}, | ||
}, | ||
required: ['address'], | ||
}; | ||
|
||
export const genesisDataSchema = { | ||
type: 'object', | ||
properties: { | ||
timestamp: { | ||
dataType: 'uint64', | ||
fieldNumber: 1, | ||
}, | ||
}, | ||
required: ['timestamp'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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/types'; | ||
|
||
export interface ValidatorKeys { | ||
generatorKey: Buffer; | ||
blsKey: Buffer; | ||
} | ||
|
||
export interface ValidatorsAPI { | ||
getGenerator: (apiContext: APIContext, timestamp: number) => Promise<Buffer>; | ||
getSlotNumber: (apiContext: APIContext, timestamp: number) => number; | ||
getSlotTime: (apiContext: APIContext, slot: number) => number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters