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

Commit

Permalink
Add TypeDoc to lisk-transactions (#7909)
Browse files Browse the repository at this point in the history
### What was the problem?

This PR resolves #7901 

Please note there is currently a bug in TypeDoc with the effect that
references between packages are not working, see
TypeStrong/typedoc#1835

### How was it solved?

- Export relevant data structures
- Add relevant code comments
- Add typedoc to the dev dependencies
- Add typedoc options to the `package.json` in each package.
- Create typedoc.json and include required options for generating the
docs properly.
- Create new folder `docs/typedoc` to store generated typeDocs

### How was it tested?

`cd lisk-sdk/`
`npx typedoc`

### Result


https://liskhq.github.io/lisk-docs/lisk-sdk/v6/references/typedoc/modules/_liskhq_lisk_transactions.html
  • Loading branch information
Tschakki authored Jan 9, 2023
1 parent 3214cf7 commit fa63da6
Show file tree
Hide file tree
Showing 24 changed files with 358 additions and 10 deletions.
2 changes: 1 addition & 1 deletion commander/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Upon successful completion, NPM will add the `lisk-commander` executable `lisk`

## Usage

```sh-session
```shell
$ lisk COMMAND
running command...
$ lisk (-v|--version|version)
Expand Down
5 changes: 5 additions & 0 deletions commander/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist/index.js",
"bin": {
"lisk": "./bin/run"
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-codec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-cryptography/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-passphrase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-transaction-pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"typings": "dist-node/index.d.ts",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions elements/lisk-transactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"node": ">=16.14.1 <=16",
"npm": ">=8.1.0"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"tsconfig": "./tsconfig.json"
},
"main": "dist-node/index.js",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
9 changes: 9 additions & 0 deletions elements/lisk-transactions/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@

import { utils } from '@liskhq/lisk-cryptography';

/**
* The transaction tag is used during the signature creation to create unique signatures for transactions.
*
* The tag for transactions is `LSK_TX` as defined in the Lisk protocol.
* For more information, check out the corresponding LIPs.
*
* @see [LIP 0037 - Use message tags and chain identifiers for signatures](https://github.com/LiskHQ/lips/blob/main/proposals/lip-0037.md) and
* @see [LIP 0068 - Define new transaction schema](https://github.com/LiskHQ/lips/blob/main/proposals/lip-0068.md) for more information about message tags.
*/
export const TAG_TRANSACTION = utils.createMessageTag('TX');
32 changes: 29 additions & 3 deletions elements/lisk-transactions/src/fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,42 @@

import { getBytes } from './sign';

/** Available options for {@link computeMinFee} */
export interface Options {
/** Minimum fee per byte. Default value: {@link DEFAULT_MIN_FEE_PER_BYTE} */
readonly minFeePerByte?: number;
/** Number of signatures included in the transaction. Default value: {@link DEFAULT_NUMBER_OF_SIGNATURES} */
readonly numberOfSignatures?: number;
/** Number of empty signatures in the transaction. Default value: {@link DEFAULT_SIGNATURE_BYTE_SIZE} */
readonly numberOfEmptySignatures?: number;
}

const DEFAULT_MIN_FEE_PER_BYTE = 1000;
const DEFAULT_NUMBER_OF_SIGNATURES = 1;
const DEFAULT_SIGNATURE_BYTE_SIZE = 64;
/** Default value for `minFeePerByte`. */
export const DEFAULT_MIN_FEE_PER_BYTE = 1000;
/** Default value for `numberOfSignatures`. */
export const DEFAULT_NUMBER_OF_SIGNATURES = 1;
/** Default byte size for transaction signatures. */
export const DEFAULT_SIGNATURE_BYTE_SIZE = 64;

/**
* Computes the minimum fee for a provided transaction.
*
* @example
* ```ts
* import { computeMinFee } from '@liskhq/lisk-transactions';
* const minFee = computeMinFee(TransferTrx, transferParamsSchema, options);
* ```
*
* @param trx the {@link baseTransactionSchema | transaction} object
* @param assetSchema Schema for the command parameters.
* The specific schemas for parameters are described in the [Modules reference](https://lisk.com/documentation/lisk-sdk/modules/index.html).
* @param options
*
* @returns Minimum fee for the provided transaction.
*
* @see [LIP 0013 - Replace static fee system by dynamic fee system](https://github.com/LiskHQ/lips/blob/main/proposals/lip-0013.md)
* @see [LIP 0048 - Introduce Fee Module](https://github.com/LiskHQ/lips/blob/main/proposals/lip-0048.md#minimum-fee-per-transaction)
* */
export const computeMinFee = (
trx: Record<string, unknown>,
assetSchema?: object,
Expand Down
29 changes: 29 additions & 0 deletions elements/lisk-transactions/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ const getDecimalPlaces = (amount: string): number =>
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
(amount.split('.')[1] || '').length;

/**
* Converts a given amount of Beddows to LSK.
* 1 LSK = 10^8 Beddows.
*
* @example
* ```ts
* import { convertBeddowsToLSK } from '@liskhq/lisk-transactions';
* const lskAmount = convertBeddowsToLSK("150000000");
* ```
*
* @param beddowsAmount Amount in Beddows
*
* @returns Amount in LSK
*
* */
export const convertBeddowsToLSK = (beddowsAmount?: string): string => {
if (typeof beddowsAmount !== 'string') {
throw new Error('Cannot convert non-string amount');
Expand All @@ -43,6 +58,20 @@ export const convertBeddowsToLSK = (beddowsAmount?: string): string => {
return res;
};

/**
* Converts a given amount of Beddows to LSK.
* 1 LSK = 10^8 Beddows.
*
* @example
* ```ts
* import { convertLSKToBeddows } from '@liskhq/lisk-transactions';
* const lskAmount = convertLSKToBeddows("15");
* ```
*
* @param lskAmount Amount in LSK
*
* @returns Amount in Beddows
* */
export const convertLSKToBeddows = (lskAmount?: string): string => {
if (typeof lskAmount !== 'string') {
throw new Error('Cannot convert non-string amount');
Expand Down
10 changes: 9 additions & 1 deletion elements/lisk-transactions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
*
*/

export { computeMinFee, Options } from './fee';
export {
Options,
computeMinFee,
DEFAULT_MIN_FEE_PER_BYTE,
DEFAULT_NUMBER_OF_SIGNATURES,
DEFAULT_SIGNATURE_BYTE_SIZE,
} from './fee';
export { convertBeddowsToLSK, convertLSKToBeddows } from './format';
export {
MultiSignatureKeys,
getBytes,
getSigningBytes,
signTransaction,
Expand All @@ -25,3 +32,4 @@ export {
} from './sign';
export { validateTransaction } from './validate';
export * from './constants';
export { baseTransactionSchema } from './schema';
6 changes: 6 additions & 0 deletions elements/lisk-transactions/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
* Removal or modification of this copyright notice is prohibited.
*
*/

/**
* Schema for Lisk Transactions.
*
* @see [LIP 0068 - Define new transaction schema](https://github.com/LiskHQ/lips/blob/main/proposals/lip-0068.md)
*/
export const baseTransactionSchema = {
$id: '/lisk/baseTransaction',
type: 'object',
Expand Down
Loading

0 comments on commit fa63da6

Please sign in to comment.