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

Commit

Permalink
Merge branch 'release/6.1.0' into 9135-improve-interop-example
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 authored Nov 12, 2023
2 parents 0f990eb + ee267e8 commit 8d29b5b
Show file tree
Hide file tree
Showing 350 changed files with 28,444 additions and 3,730 deletions.
683 changes: 0 additions & 683 deletions commander/oclif.manifest.json

This file was deleted.

22 changes: 11 additions & 11 deletions commander/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-commander",
"version": "6.0.0-rc.6",
"version": "6.1.0-rc.0",
"description": "A command line interface for Lisk",
"author": "Lisk Foundation <admin@lisk.com>, lightcurve GmbH <admin@lightcurve.io>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -101,16 +101,16 @@
"/docs"
],
"dependencies": {
"@liskhq/lisk-api-client": "^6.0.0-rc.4",
"@liskhq/lisk-chain": "^0.5.0-rc.4",
"@liskhq/lisk-client": "^6.0.0-rc.4",
"@liskhq/lisk-codec": "^0.4.0-rc.2",
"@liskhq/lisk-cryptography": "^4.0.0-rc.2",
"@liskhq/lisk-db": "0.3.10",
"@liskhq/lisk-passphrase": "^4.0.0-rc.0",
"@liskhq/lisk-transactions": "^6.0.0-rc.2",
"@liskhq/lisk-api-client": "^6.1.0-rc.0",
"@liskhq/lisk-chain": "^0.6.0-rc.0",
"@liskhq/lisk-client": "^6.1.0-rc.0",
"@liskhq/lisk-codec": "^0.5.0-rc.0",
"@liskhq/lisk-cryptography": "^4.1.0-rc.0",
"@liskhq/lisk-db": "0.3.7",
"@liskhq/lisk-passphrase": "^4.1.0-rc.0",
"@liskhq/lisk-transactions": "^6.1.0-rc.0",
"@liskhq/lisk-utils": "^0.4.0-rc.0",
"@liskhq/lisk-validator": "^0.8.0-rc.2",
"@liskhq/lisk-validator": "^0.9.0-rc.0",
"@oclif/core": "1.20.4",
"@oclif/plugin-autocomplete": "1.3.6",
"@oclif/plugin-help": "5.1.19",
Expand All @@ -121,7 +121,7 @@
"cli-table3": "0.6.0",
"fs-extra": "11.1.0",
"inquirer": "8.2.5",
"lisk-framework": "^0.11.0-rc.5",
"lisk-framework": "^0.12.0-rc.0",
"listr": "0.14.3",
"progress": "2.0.3",
"semver": "7.5.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@
}
},
"dependencies": {
"@liskhq/lisk-framework-dashboard-plugin": "0.3.0-rc.5",
"@liskhq/lisk-framework-faucet-plugin": "0.3.0-rc.5",
"@liskhq/lisk-framework-monitor-plugin": "0.4.0-rc.5",
"@liskhq/lisk-framework-forger-plugin": "0.4.0-rc.5",
"@liskhq/lisk-framework-report-misbehavior-plugin": "0.4.0-rc.5",
"@liskhq/lisk-framework-chain-connector-plugin": "0.1.0-rc.5",
"@liskhq/lisk-framework-dashboard-plugin": "0.4.0-rc.0",
"@liskhq/lisk-framework-faucet-plugin": "0.4.0-rc.0",
"@liskhq/lisk-framework-monitor-plugin": "0.5.0-rc.0",
"@liskhq/lisk-framework-forger-plugin": "0.5.0-rc.0",
"@liskhq/lisk-framework-report-misbehavior-plugin": "0.5.0-rc.0",
"@liskhq/lisk-framework-chain-connector-plugin": "0.2.0-rc.0",
"@oclif/core": "1.20.4",
"@oclif/plugin-autocomplete": "1.3.6",
"@oclif/plugin-help": "5.1.19",
"@oclif/plugin-version": "1.1.3",
"axios": "0.21.2",
"fs-extra": "11.1.0",
"inquirer": "8.2.5",
"lisk-commander": "6.0.0-rc.6",
"lisk-sdk": "6.0.0-rc.5",
"lisk-commander": "6.1.0-rc.0",
"lisk-sdk": "6.1.0-rc.0",
"tar": "6.1.11",
"tslib": "2.4.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { Application } from 'lisk-sdk';

// @ts-expect-error app will have typescript error for unsued variable
export const registerModules = (app: Application): void => {};
export const registerModules = (_app: Application): void => {};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build:check": "node -e \"require('./dist-node')\""
},
"dependencies": {
"lisk-sdk": "^6.0.0-rc.5"
"lisk-sdk": "^6.1.0-rc.0"
},
"devDependencies": {
"@types/jest": "26.0.21",
Expand Down
7 changes: 2 additions & 5 deletions commander/src/commands/generate/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ interface CommandCommandArgs {
}

export default class CommandCommand extends BaseBootstrapCommand {
static description = 'Creates an command skeleton for the given module name, name and id.';
static examples = [
'generate:command moduleName commandName commandID',
'generate:command nft transfer 1',
];
static description = 'Creates a command skeleton for the given module name and command name.';
static examples = ['generate:command moduleName commandName', 'generate:command nft transfer'];
static args = [
{
name: 'moduleName',
Expand Down
220 changes: 89 additions & 131 deletions commander/src/utils/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ import * as readline from 'readline';

import { FileSystemError, ValidationError } from './error';

interface PropertyValue {
readonly dataType: string;
readonly type: string;
readonly items: { type: string; properties: Record<string, unknown> };
}

interface Question {
readonly [key: string]: unknown;
}

interface NestedPropertyTemplate {
[key: string]: string[];
}

interface NestedAsset {
[key: string]: Array<Record<string, unknown>>;
}
Expand Down Expand Up @@ -193,36 +179,7 @@ export const readStdIn = async (): Promise<string[]> => {
return readFromStd;
};

const getNestedPropertyTemplate = (schema: Schema): NestedPropertyTemplate => {
const keyValEntries = Object.entries(schema.properties);
const template: NestedPropertyTemplate = {};

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < keyValEntries.length; i += 1) {
const [schemaPropertyName, schemaPropertyValue] = keyValEntries[i];
if ((schemaPropertyValue as PropertyValue).type === 'array') {
// nested items properties
if ((schemaPropertyValue as PropertyValue).items.type === 'object') {
template[schemaPropertyName] = Object.keys(
(schemaPropertyValue as PropertyValue).items.properties,
);
}
}
}
return template;
};

const castValue = (
val: string,
schemaType: string,
): number | bigint | string | string[] | Record<string, unknown> => {
if (schemaType === 'object') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(val);
}
if (schemaType === 'array') {
return val !== '' ? val.split(',') : [];
}
const castValue = (val: string, schemaType: string): string | number | bigint => {
if (schemaType === 'uint64' || schemaType === 'sint64') {
return BigInt(val);
}
Expand All @@ -232,107 +189,108 @@ const castValue = (
return val;
};

export const transformAsset = (
schema: Schema,
data: Record<string, string>,
): Record<string, unknown> => {
const propertySchema = Object.values(schema.properties);
const assetData = {} as Record<string, unknown>;
return Object.entries(data).reduce((acc, curr, index) => {
const propSchema = propertySchema[index] as { type: string; dataType: string };
// Property schema type can be scalar(string, bool, etc..) or structural(object, array)
const schemaType = propSchema.type || propSchema.dataType;
acc[curr[0]] = castValue(curr[1], schemaType);
return acc;
}, assetData);
};
const castArray = (items: string[], schemaType: string): string[] | number[] | bigint[] => {
if (schemaType === 'uint64' || schemaType === 'sint64') {
return items.map(i => BigInt(i));
}

export const transformNestedAsset = (
schema: Schema,
data: Array<Record<string, string>>,
): NestedAsset => {
const template = getNestedPropertyTemplate(schema);
const result = {} as NestedAsset;
const items: Array<Record<string, unknown>> = [];
for (const assetData of data) {
const [[key, val]] = Object.entries(assetData);
const templateValues = template[key];
const initData = {} as Record<string, unknown>;
const valObject = val.split(',').reduce((acc, curr, index) => {
acc[templateValues[index]] = Number.isInteger(Number(curr)) ? Number(curr) : curr;
return acc;
}, initData);
items.push(valObject);
result[key] = items;
if (schemaType === 'uint32' || schemaType === 'sint32') {
return items.map(i => Number(i));
}

return items;
};

const getNestedParametersFromPrompt = async (property: {
name: string;
items: { properties: Record<string, unknown> };
}) => {
let addMore = false;
const nestedArray: Array<Record<string, unknown>> = [];
const nestedProperties = Object.keys(property.items.properties);
const nestedPropertiesCsv = nestedProperties.join(',');
do {
const nestedPropertiesAnswer: Record<string, string> = await inquirer.prompt({
type: 'input',
name: property.name,
message: `Please enter: ${property.name}(${nestedPropertiesCsv}): `,
});

const properties = nestedPropertiesAnswer[property.name].split(',');

const nestedObject: Record<string, unknown> = {};

for (let i = 0; i < nestedProperties.length; i += 1) {
const propertySchema = property.items.properties[nestedProperties[i]] as { dataType: string };
nestedObject[nestedProperties[i]] =
properties[i] === undefined ? '' : castValue(properties[i], propertySchema.dataType);
}

nestedArray.push(nestedObject);

const confirmResponse = await inquirer.prompt({
type: 'confirm',
name: 'askAgain',
message: `Want to enter another ${property.name})`,
});

addMore = confirmResponse.askAgain as boolean;
} while (addMore);

const result = {} as Record<string, unknown>;
result[property.name] = nestedArray;

return result;
};

export const prepareQuestions = (schema: Schema): Question[] => {
const keyValEntries = Object.entries(schema.properties);
const questions: Question[] = [];
export const getParamsFromPrompt = async (
assetSchema: Schema | { properties: Record<string, unknown> },
): Promise<NestedAsset | Record<string, unknown>> => {
const result: Record<string, unknown> = {};
for (const propertyName of Object.keys(assetSchema.properties)) {
const property = assetSchema.properties[propertyName] as {
dataType?: string;
type?: 'array';
items?: { dataType?: string; type?: 'object'; properties?: Record<string, unknown> };
};

for (const [schemaPropertyName, schemaPropertyValue] of keyValEntries) {
if ((schemaPropertyValue as PropertyValue).type === 'array') {
let commaSeparatedKeys: string[] = [];
// nested items properties
if ((schemaPropertyValue as PropertyValue).items.type === 'object') {
commaSeparatedKeys = Object.keys((schemaPropertyValue as PropertyValue).items.properties);
}
questions.push({
type: 'input',
name: schemaPropertyName,
message: `Please enter: ${schemaPropertyName}(${
commaSeparatedKeys.length ? commaSeparatedKeys.join(', ') : 'comma separated values (a,b)'
}): `,
});
if ((schemaPropertyValue as PropertyValue).items.type === 'object') {
questions.push({
type: 'confirm',
name: 'askAgain',
message: `Want to enter another ${schemaPropertyName}(${commaSeparatedKeys.join(', ')})`,
if (property.type === 'array') {
if (property.items?.type === 'object' && property.items.properties !== undefined) {
const nestedResult = await getNestedParametersFromPrompt({
name: propertyName,
items: {
properties: property.items.properties,
},
});

result[propertyName] = nestedResult[propertyName];
} else if (property.items?.type === undefined && property.items?.dataType !== undefined) {
const answer: Record<string, string> = await inquirer.prompt({
type: 'input',
name: propertyName,
message: `Please enter: ${propertyName}(comma separated values (a,b)): `,
});

result[propertyName] = castArray(
answer[propertyName] === '' ? [] : answer[propertyName].split(','),
property.items.dataType,
);
}
} else {
questions.push({
const answer: Record<string, string> = await inquirer.prompt({
type: 'input',
name: schemaPropertyName,
message: `Please enter: ${schemaPropertyName}: `,
name: propertyName,
message: `Please enter: ${propertyName}: `,
});
}
}
return questions;
};

export const getParamsFromPrompt = async (
assetSchema: Schema,
output: Array<{ [key: string]: string }> = [],
): Promise<NestedAsset | Record<string, unknown>> => {
// prepare array of questions based on asset schema
const questions = prepareQuestions(assetSchema);
if (questions.length === 0) {
return {};
}
let isTypeConfirm = false;
// Prompt user with prepared questions
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const result = await inquirer.prompt(questions).then(async answer => {
const inquirerResult = answer as { [key: string]: string };
isTypeConfirm = typeof inquirerResult.askAgain === 'boolean';
// if its a multiple questions prompt user again
if (inquirerResult.askAgain) {
output.push(inquirerResult);
return getParamsFromPrompt(assetSchema, output);
result[propertyName] = castValue(
answer[propertyName],
(property as { dataType: string }).dataType,
);
}
output.push(inquirerResult);
return Promise.resolve(answer);
});
const filteredResult = output.map(({ askAgain, ...assetProps }) => assetProps);
}

// transform asset prompt result according to asset schema
return isTypeConfirm
? transformNestedAsset(assetSchema, filteredResult)
: transformAsset(assetSchema, result as Record<string, string>);
return result;
};

export const checkFileExtension = (filePath: string): void => {
Expand Down
2 changes: 1 addition & 1 deletion commander/test/bootstrapping/commands/hash-onion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('hash-onion command', () => {
for (let i = 0; i < result.hashes.length - 1; i += 1) {
let nextHash = Buffer.from(result.hashes[i + 1], 'hex');
for (let j = 0; j < result.distance; j += 1) {
nextHash = cryptography.utils.hash(nextHash).slice(0, 16);
nextHash = cryptography.utils.hash(nextHash).subarray(0, 16);
}
expect(result.hashes[i]).toBe(nextHash.toString('hex'));
}
Expand Down
Loading

0 comments on commit 8d29b5b

Please sign in to comment.