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

Commit

Permalink
🌱 Update function to create genesis block
Browse files Browse the repository at this point in the history
- Remove genesis block package since genesis block cannot be created
  without application registered with modules
- Create genesis block creation function in generator and expose from
  application
  • Loading branch information
shuse2 committed Nov 25, 2021
1 parent 864dfba commit bd4f760
Show file tree
Hide file tree
Showing 54 changed files with 422 additions and 2,328 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile.sdk
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pipeline {
steps {
setup()
nvm(getNodejsVersion()) {
sh 'npx lerna run test:ci --ignore lisk-framework --ignore lisk-commander --ignore=@liskhq/lisk-framework-* --ignore @liskhq/lisk-p2p --ignore @liskhq/lisk-genesis --ignore @liskhq/lisk-api-client --ignore lisk-elements'
sh 'npx lerna run test:ci --ignore lisk-framework --ignore lisk-commander --ignore=@liskhq/lisk-framework-* --ignore @liskhq/lisk-p2p --ignore @liskhq/lisk-api-client --ignore lisk-elements'
}
}
post {
Expand Down
1 change: 0 additions & 1 deletion commander/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"@liskhq/lisk-codec": "^0.2.1",
"@liskhq/lisk-cryptography": "^3.2.0",
"@liskhq/lisk-db": "^0.2.0",
"@liskhq/lisk-genesis": "^0.2.3",
"@liskhq/lisk-passphrase": "^3.1.0",
"@liskhq/lisk-transactions": "^5.2.0",
"@liskhq/lisk-utils": "^0.2.0",
Expand Down
1 change: 0 additions & 1 deletion elements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Lisk Elements supports the modular architecture of the Lisk SDK, where libraries
| [@liskhq/lisk-codec](./lisk-codec) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-codec) | Decoder and encoder using Lisk JSON schema according to the Lisk protocol |
| [@liskhq/lisk-cryptography](./lisk-cryptography) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-cryptography) | General cryptographic functions for use with Lisk-related software |
| [@liskhq/lisk-db](./lisk-db) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-db) | A database access implementation for use with Lisk-related software |
| [@liskhq/lisk-genesis](./lisk-genesis) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-genesis) | Genesis block creation functions according to the Lisk protocol |
| [@liskhq/lisk-p2p](./lisk-p2p) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-p2p) | _unstructured_ P2P library for the Lisk protocol |
| [@liskhq/lisk-passphrase](./lisk-passphrase) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-passphrase) | Mnemonic passphrase helpers for use with Lisk-related software |
| [@liskhq/lisk-transactions](./lisk-transactions) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-transactions) | Everything related to transactions according to the Lisk protocol |
Expand Down
24 changes: 19 additions & 5 deletions elements/lisk-chain/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@

import { codec } from '@liskhq/lisk-codec';
import { regularMerkleTree } from '@liskhq/lisk-tree';
import { BlockAssets } from './block_assets';
import { BlockHeader } from './block_header';
import { BlockAssetJSON, BlockAssets } from './block_assets';
import { BlockHeader, BlockHeaderJSON } from './block_header';
import { blockSchema } from './schema';
import { Transaction } from './transaction';
import { Transaction, TransactionJSON } from './transaction';

interface BlockAttrs {
header: Buffer;
payload: Buffer[];
assets: Buffer[];
}

export interface BlockJSON {
header: BlockHeaderJSON;
payload: TransactionJSON[];
assets: BlockAssetJSON[];
}

export class Block {
// eslint-disable-next-line no-useless-constructor
public constructor(
Expand All @@ -45,7 +51,7 @@ export class Block {
);
}

public static fromJSON(value: Record<string, unknown>): Block {
public static fromJSON(value: BlockJSON): Block {
const { header, payload, assets } = value;
if (typeof header !== 'object') {
throw new Error('Invalid block format. header must be an object.');
Expand All @@ -59,7 +65,7 @@ export class Block {

return new Block(
BlockHeader.fromJSON(value.header as Record<string, unknown>),
payload.map(v => Transaction.fromBytes(v)),
payload.map(v => Transaction.fromJSON(v)),
BlockAssets.fromJSON(assets),
);
}
Expand All @@ -72,6 +78,14 @@ export class Block {
});
}

public toJSON(): BlockJSON {
return {
header: this.header.toJSON(),
payload: this.payload.map(p => p.toJSON()),
assets: this.assets.toJSON(),
};
}

public validate(): void {
this.header.validate();
for (const tx of this.payload) {
Expand Down
10 changes: 10 additions & 0 deletions elements/lisk-chain/src/block_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import { codec } from '@liskhq/lisk-codec';
import { MerkleTree } from '@liskhq/lisk-tree';
import { blockAssetSchema } from './schema';
import { MAX_ASSET_DATA_SIZE_BYTES } from './constants';
import { JSONObject } from './types';

export interface BlockAsset {
moduleID: number;
data: Buffer;
}

export type BlockAssetJSON = JSONObject<BlockAsset>;

export class BlockAssets {
private readonly _assets: BlockAsset[] = [];
private _assetRoot!: Buffer;
Expand Down Expand Up @@ -60,6 +63,13 @@ export class BlockAssets {
return [...this._assets];
}

public toJSON(): BlockAssetJSON[] {
return this._assets.map(asset => ({
moduleID: asset.moduleID,
data: asset.data.toString('hex'),
}));
}

public setAsset(moduleID: number, value: Buffer): void {
const asset = this.getAsset(moduleID);
if (asset) {
Expand Down
23 changes: 2 additions & 21 deletions elements/lisk-chain/src/block_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { codec } from '@liskhq/lisk-codec';
import { validator, LiskValidationError } from '@liskhq/lisk-validator';
import { EMPTY_BUFFER, EMPTY_HASH, TAG_BLOCK_HEADER } from './constants';
import { blockHeaderSchema, blockHeaderSchemaWithId, signingBlockHeaderSchema } from './schema';
import { JSONObject } from './types';

export interface BlockHeaderAttrs {
readonly version: number;
Expand All @@ -39,26 +40,7 @@ export interface BlockHeaderAttrs {
id?: Buffer;
}

export interface BlockHeaderJSON {
readonly version: number;
readonly timestamp: number;
readonly height: number;
readonly generatorAddress: string;
readonly previousBlockID: string;
readonly maxHeightPrevoted: number;
readonly maxHeightGenerated: number;
readonly aggregateCommit: {
readonly height: number;
readonly aggregationBits: string;
readonly certificateSignature: string;
};
readonly validatorsHash: string;
readonly stateRoot: string;
readonly transactionRoot: string;
readonly assetsRoot: string;
readonly signature: string;
readonly id: string;
}
export type BlockHeaderJSON = JSONObject<BlockHeaderAttrs>;

export class BlockHeader {
public readonly version: number;
Expand Down Expand Up @@ -335,7 +317,6 @@ export class BlockHeader {

private _resetComputedValues() {
this._id = undefined;
this._signature = undefined;
}

private _getSigningProps() {
Expand Down
4 changes: 2 additions & 2 deletions elements/lisk-chain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export { Slots } from './slots';
export { concatDBKeys } from './utils';

export { StateStore, NotFoundError, CurrentState, SMTStore } from './state_store';
export { Block } from './block';
export { BlockAsset, BlockAssets } from './block_assets';
export { Block, BlockJSON } from './block';
export { BlockAsset, BlockAssets, BlockAssetJSON } from './block_assets';
export { BlockHeader, BlockHeaderAttrs, BlockHeaderJSON } from './block_header';
export { DataAccess } from './data_access';
16 changes: 4 additions & 12 deletions elements/lisk-chain/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { codec } from '@liskhq/lisk-codec';
import { hash, getAddressFromPublicKey, signDataWithPrivateKey } from '@liskhq/lisk-cryptography';
import { validator, LiskValidationError } from '@liskhq/lisk-validator';
import { TAG_TRANSACTION } from './constants';
import { JSONObject } from './types';

export interface TransactionAttrs {
readonly moduleID: number;
Expand All @@ -27,16 +28,7 @@ export interface TransactionAttrs {
readonly signatures: ReadonlyArray<Buffer>;
readonly id?: Buffer;
}

export interface TransactionJSON {
readonly moduleID: number;
readonly commandID: number;
readonly senderPublicKey: string;
readonly nonce: string;
readonly fee: string;
readonly params: string;
readonly signatures: ReadonlyArray<string>;
}
export type TransactionJSON = JSONObject<TransactionAttrs>;

export const transactionSchema = {
$id: 'lisk/transaction',
Expand Down Expand Up @@ -118,7 +110,7 @@ export class Transaction {
return new Transaction(tx);
}

public static fromJSON(value: Record<string, unknown>): Transaction {
public static fromJSON(value: TransactionJSON): Transaction {
const tx = codec.fromJSON<TransactionAttrs>(transactionSchema, value);
return new Transaction(tx);
}
Expand Down Expand Up @@ -177,7 +169,7 @@ export class Transaction {
}
}

public toJSON(): TransactionJSON {
public toJSON(): JSONObject<TransactionAttrs> {
return codec.toJSON(transactionSchema, this._getProps());
}

Expand Down
11 changes: 11 additions & 0 deletions elements/lisk-chain/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ export interface UpdatedDiff {
readonly key: Buffer;
readonly value: Buffer;
}

type Primitive = string | number | bigint | boolean | null | undefined;
type Replaced<T, TReplace, TWith, TKeep = Primitive> = T extends TReplace | TKeep
? T extends TReplace
? TWith | Exclude<T, TReplace>
: T
: {
[P in keyof T]: Replaced<T[P], TReplace, TWith, TKeep>;
};

export type JSONObject<T> = Replaced<T, bigint | Buffer, string>;
1 change: 0 additions & 1 deletion elements/lisk-elements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const { transactions } = require('lisk-elements');
| [@liskhq/lisk-codec](https://www.npmjs.com/package/@liskhq/lisk-codec) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-codec) | Decoder and encoder using Lisk JSON schema according to the Lisk protocol |
| [@liskhq/lisk-cryptography](https://www.npmjs.com/package/@liskhq/lisk-cryptography) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-cryptography) | General cryptographic functions for use with Lisk-related software |
| [@liskhq/lisk-db](https://www.npmjs.com/package/@liskhq/lisk-db) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-db) | A database access implementation for use with Lisk-related software |
| [@liskhq/lisk-genesis](https://www.npmjs.com/package/@liskhq/lisk-genesis) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-genesis) | Genesis block creation functions according to the Lisk protocol |
| [@liskhq/lisk-p2p](https://www.npmjs.com/package/@liskhq/lisk-p2p) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-p2p) | _unstructured_ P2P library for the Lisk protocol |
| [@liskhq/lisk-passphrase](https://www.npmjs.com/package/@liskhq/lisk-passphrase) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-passphrase) | Mnemonic passphrase helpers for use with Lisk-related software |
| [@liskhq/lisk-transactions](https://www.npmjs.com/package/@liskhq/lisk-transactions) | ![npm](https://img.shields.io/npm/v/@liskhq/lisk-transactions) | Everything related to transactions according to the Lisk protocol |
Expand Down
1 change: 0 additions & 1 deletion elements/lisk-elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@liskhq/lisk-codec": "^0.2.1",
"@liskhq/lisk-cryptography": "^3.2.0",
"@liskhq/lisk-db": "^0.2.0",
"@liskhq/lisk-genesis": "^0.2.3",
"@liskhq/lisk-p2p": "^0.7.2",
"@liskhq/lisk-passphrase": "^3.1.0",
"@liskhq/lisk-transaction-pool": "^0.5.1",
Expand Down
3 changes: 0 additions & 3 deletions elements/lisk-genesis/.eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions elements/lisk-genesis/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion elements/lisk-genesis/.npmignore

This file was deleted.

1 change: 0 additions & 1 deletion elements/lisk-genesis/.npmrc

This file was deleted.

1 change: 0 additions & 1 deletion elements/lisk-genesis/.prettierignore

This file was deleted.

1 change: 0 additions & 1 deletion elements/lisk-genesis/.prettierrc.json

This file was deleted.

28 changes: 0 additions & 28 deletions elements/lisk-genesis/README.md

This file was deleted.

1 change: 0 additions & 1 deletion elements/lisk-genesis/jest.config.js

This file was deleted.

66 changes: 0 additions & 66 deletions elements/lisk-genesis/package.json

This file was deleted.

1 change: 0 additions & 1 deletion elements/lisk-genesis/scripts

This file was deleted.

25 changes: 0 additions & 25 deletions elements/lisk-genesis/src/constants.ts

This file was deleted.

Loading

0 comments on commit bd4f760

Please sign in to comment.