From a5de9cead1a6740a807b77c8330a35c836ba232c Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Fri, 7 Dec 2018 17:08:13 +0100 Subject: [PATCH 1/9] Updated package.json config, scripts and dependencies --- package.json | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index b92dd2f..0c596d9 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,24 @@ "name": "ethereumjs-common", "version": "0.6.1", "description": "Resources common to all Ethereum implementations", - "main": "index.js", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "scripts": { + "build": "tsc -p ./tsconfig.prod.json", + "prepublishOnly": "npm run test && npm run build", "coverage": "nyc npm run test && nyc report --reporter=text-lcov > .nyc_output/lcov.info", "coveralls": "npm run coverage && coveralls <.nyc_output/lcov.info", - "lint": "standard", - "lint:fix": "standard --fix", - "test": "npm run lint && node tests/", - "build:docs": "documentation build ./index.js --format md --shallow > ./docs/index.md" + "format": "prettier --list-different '**/*.{ts,json,md}'", + "format:fix": "prettier --write '**/*.{ts,json,md}'", + "tslint": "tslint -p ./tsconfig.json -e node_modules/**/* -e **/node_modules/**/* -e dist/**/* **/*.ts", + "tslint:fix": "tslint --fix --format stylish -p ./tsconfig.json -e node_modules/**/* -e **/node_modules/**/* -e dist/**/* **/*.ts", + "tsc": "tsc --noEmit", + "lint": "npm run format && npm run tslint && npm run tsc", + "lint:fix": "npm run format:fix && npm run tslint:fix && npm run tsc", + "unitTests": "ts-node ./node_modules/tape/bin/tape ./tests/*.ts", + "test": "npm run lint && npm run unitTests", + "test:fix": "npm run lint:fix && npm run unitTests", + "docs:build": "typedoc --out docs --excludePrivate --excludeExternals --mode file --readme none --theme markdown --mdEngine github src/*.ts" }, "repository": { "type": "git", @@ -24,9 +34,6 @@ "networks", "bootstrap" ], - "nyc": { - "exclude": "tests/*.js" - }, "author": "", "license": "MIT", "bugs": { @@ -34,11 +41,22 @@ }, "homepage": "https://github.com/ethereumjs-ethereumjs/common", "devDependencies": { + "@ethereumjs/config-nyc": "^1.0.0", + "@ethereumjs/config-prettier": "^1.0.1", + "@ethereumjs/config-tsc": "^1.0.2", + "@ethereumjs/config-tslint": "^1.0.0", + "@types/node": "^10.12.2", + "@types/tape": "^4.2.33", "coveralls": "^3.0.1", - "documentation": "^6.3.2", "nyc": "^11.7.1", - "standard": "^11.0.1", - "tape": "^4.2.0" + "prettier": "^1.15.3", + "tape": "^4.9.2", + "ts-node": "^7.0.1", + "tslint": "^5.12.0", + "typedoc": "^0.14.0", + "typedoc-plugin-markdown": "^1.1.21", + "typescript": "^3.2.2", + "typestrict": "^1.0.2" }, "maintainers": [ { From b7c926d6e5fd9e68ccd3582e3d5e220cef5b245d Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Fri, 7 Dec 2018 17:09:00 +0100 Subject: [PATCH 2/9] Added TypeScript and build relevant folders to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 748b550..72cc80a 100644 --- a/.gitignore +++ b/.gitignore @@ -67,4 +67,4 @@ build/Release node_modules package-lock.json - +dist From 2fe546e4df432e4f51671b5887990c3d4ea57d68 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Fri, 7 Dec 2018 17:13:55 +0100 Subject: [PATCH 3/9] Moved all source files to src folder --- {chains => src/chains}/goerli.json | 0 {chains => src/chains}/index.js | 0 {chains => src/chains}/kovan.json | 0 {chains => src/chains}/mainnet.json | 0 {chains => src/chains}/rinkeby.json | 0 {chains => src/chains}/ropsten.json | 0 {genesisStates => src/genesisStates}/goerli.json | 0 {genesisStates => src/genesisStates}/index.js | 0 {genesisStates => src/genesisStates}/kovan.json | 0 {genesisStates => src/genesisStates}/mainnet.json | 0 {genesisStates => src/genesisStates}/rinkeby.json | 0 {genesisStates => src/genesisStates}/ropsten.json | 0 {hardforks => src/hardforks}/byzantium.json | 0 {hardforks => src/hardforks}/chainstart.json | 0 {hardforks => src/hardforks}/constantinople.json | 0 {hardforks => src/hardforks}/dao.json | 0 {hardforks => src/hardforks}/homestead.json | 0 {hardforks => src/hardforks}/index.js | 0 {hardforks => src/hardforks}/spuriousDragon.json | 0 {hardforks => src/hardforks}/tangerineWhistle.json | 0 index.js => src/index.js | 0 21 files changed, 0 insertions(+), 0 deletions(-) rename {chains => src/chains}/goerli.json (100%) rename {chains => src/chains}/index.js (100%) rename {chains => src/chains}/kovan.json (100%) rename {chains => src/chains}/mainnet.json (100%) rename {chains => src/chains}/rinkeby.json (100%) rename {chains => src/chains}/ropsten.json (100%) rename {genesisStates => src/genesisStates}/goerli.json (100%) rename {genesisStates => src/genesisStates}/index.js (100%) rename {genesisStates => src/genesisStates}/kovan.json (100%) rename {genesisStates => src/genesisStates}/mainnet.json (100%) rename {genesisStates => src/genesisStates}/rinkeby.json (100%) rename {genesisStates => src/genesisStates}/ropsten.json (100%) rename {hardforks => src/hardforks}/byzantium.json (100%) rename {hardforks => src/hardforks}/chainstart.json (100%) rename {hardforks => src/hardforks}/constantinople.json (100%) rename {hardforks => src/hardforks}/dao.json (100%) rename {hardforks => src/hardforks}/homestead.json (100%) rename {hardforks => src/hardforks}/index.js (100%) rename {hardforks => src/hardforks}/spuriousDragon.json (100%) rename {hardforks => src/hardforks}/tangerineWhistle.json (100%) rename index.js => src/index.js (100%) diff --git a/chains/goerli.json b/src/chains/goerli.json similarity index 100% rename from chains/goerli.json rename to src/chains/goerli.json diff --git a/chains/index.js b/src/chains/index.js similarity index 100% rename from chains/index.js rename to src/chains/index.js diff --git a/chains/kovan.json b/src/chains/kovan.json similarity index 100% rename from chains/kovan.json rename to src/chains/kovan.json diff --git a/chains/mainnet.json b/src/chains/mainnet.json similarity index 100% rename from chains/mainnet.json rename to src/chains/mainnet.json diff --git a/chains/rinkeby.json b/src/chains/rinkeby.json similarity index 100% rename from chains/rinkeby.json rename to src/chains/rinkeby.json diff --git a/chains/ropsten.json b/src/chains/ropsten.json similarity index 100% rename from chains/ropsten.json rename to src/chains/ropsten.json diff --git a/genesisStates/goerli.json b/src/genesisStates/goerli.json similarity index 100% rename from genesisStates/goerli.json rename to src/genesisStates/goerli.json diff --git a/genesisStates/index.js b/src/genesisStates/index.js similarity index 100% rename from genesisStates/index.js rename to src/genesisStates/index.js diff --git a/genesisStates/kovan.json b/src/genesisStates/kovan.json similarity index 100% rename from genesisStates/kovan.json rename to src/genesisStates/kovan.json diff --git a/genesisStates/mainnet.json b/src/genesisStates/mainnet.json similarity index 100% rename from genesisStates/mainnet.json rename to src/genesisStates/mainnet.json diff --git a/genesisStates/rinkeby.json b/src/genesisStates/rinkeby.json similarity index 100% rename from genesisStates/rinkeby.json rename to src/genesisStates/rinkeby.json diff --git a/genesisStates/ropsten.json b/src/genesisStates/ropsten.json similarity index 100% rename from genesisStates/ropsten.json rename to src/genesisStates/ropsten.json diff --git a/hardforks/byzantium.json b/src/hardforks/byzantium.json similarity index 100% rename from hardforks/byzantium.json rename to src/hardforks/byzantium.json diff --git a/hardforks/chainstart.json b/src/hardforks/chainstart.json similarity index 100% rename from hardforks/chainstart.json rename to src/hardforks/chainstart.json diff --git a/hardforks/constantinople.json b/src/hardforks/constantinople.json similarity index 100% rename from hardforks/constantinople.json rename to src/hardforks/constantinople.json diff --git a/hardforks/dao.json b/src/hardforks/dao.json similarity index 100% rename from hardforks/dao.json rename to src/hardforks/dao.json diff --git a/hardforks/homestead.json b/src/hardforks/homestead.json similarity index 100% rename from hardforks/homestead.json rename to src/hardforks/homestead.json diff --git a/hardforks/index.js b/src/hardforks/index.js similarity index 100% rename from hardforks/index.js rename to src/hardforks/index.js diff --git a/hardforks/spuriousDragon.json b/src/hardforks/spuriousDragon.json similarity index 100% rename from hardforks/spuriousDragon.json rename to src/hardforks/spuriousDragon.json diff --git a/hardforks/tangerineWhistle.json b/src/hardforks/tangerineWhistle.json similarity index 100% rename from hardforks/tangerineWhistle.json rename to src/hardforks/tangerineWhistle.json diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js From 562a4f46fc83041597ec3ee069b054781e0935df Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Fri, 7 Dec 2018 17:16:32 +0100 Subject: [PATCH 4/9] Use TypeScript .ts file extensions for all .js source files (renaming) --- src/chains/{index.js => index.ts} | 0 src/genesisStates/{index.js => index.ts} | 0 src/hardforks/{index.js => index.ts} | 0 src/{index.js => index.ts} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/chains/{index.js => index.ts} (100%) rename src/genesisStates/{index.js => index.ts} (100%) rename src/hardforks/{index.js => index.ts} (100%) rename src/{index.js => index.ts} (100%) diff --git a/src/chains/index.js b/src/chains/index.ts similarity index 100% rename from src/chains/index.js rename to src/chains/index.ts diff --git a/src/genesisStates/index.js b/src/genesisStates/index.ts similarity index 100% rename from src/genesisStates/index.js rename to src/genesisStates/index.ts diff --git a/src/hardforks/index.js b/src/hardforks/index.ts similarity index 100% rename from src/hardforks/index.js rename to src/hardforks/index.ts diff --git a/src/index.js b/src/index.ts similarity index 100% rename from src/index.js rename to src/index.ts From c96fd74416c591e34a2ed20dab1392032d43ab7a Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 7 Jan 2019 10:38:16 +0100 Subject: [PATCH 5/9] Added TypeScript, Prettier and TSLint configuration files --- .nycrc | 3 +++ .prettierignore | 5 +++++ prettier.config.js | 1 + tsconfig.json | 4 ++++ tsconfig.prod.json | 7 +++++++ tslint.json | 3 +++ 6 files changed, 23 insertions(+) create mode 100644 .nycrc create mode 100644 .prettierignore create mode 100644 prettier.config.js create mode 100644 tsconfig.json create mode 100644 tsconfig.prod.json create mode 100644 tslint.json diff --git a/.nycrc b/.nycrc new file mode 100644 index 0000000..b54064b --- /dev/null +++ b/.nycrc @@ -0,0 +1,3 @@ +{ + "extends": "@ethereumjs/config-nyc" +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..a69149e --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +node_modules +.vscode +package.json +dist +.nyc_output diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..0f2e5b7 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1 @@ +module.exports = require('@ethereumjs/config-prettier') diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e7f1cf6 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@ethereumjs/config-tsc", + "include": ["src/**/*.ts", "src/**/*.json", "tests/*.ts", "tests/*.json"] +} diff --git a/tsconfig.prod.json b/tsconfig.prod.json new file mode 100644 index 0000000..854acb1 --- /dev/null +++ b/tsconfig.prod.json @@ -0,0 +1,7 @@ +{ + "extends": "@ethereumjs/config-tsc", + "compilerOptions": { + "outDir": "./dist" + }, + "include": ["src/**/*.ts", "src/**/*.json"] +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..2ba21c4 --- /dev/null +++ b/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "@ethereumjs/config-tslint" +} From 4bb186378c00bbdedeecd27a2c8afeaac9a6c9e5 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Fri, 7 Dec 2018 17:20:39 +0100 Subject: [PATCH 6/9] TypeScript code updates, type declarations --- docs/index.md | 187 ++++++++----------- src/chains/index.ts | 30 +-- src/chains/kovan.json | 3 +- src/chains/ropsten.json | 70 +++---- src/genesisStates/goerli.json | 2 +- src/genesisStates/index.ts | 30 +-- src/genesisStates/kovan.json | 2 +- src/genesisStates/rinkeby.json | 2 +- src/genesisStates/ropsten.json | 2 +- src/hardforks/byzantium.json | 2 +- src/hardforks/chainstart.json | 2 +- src/hardforks/dao.json | 2 +- src/hardforks/homestead.json | 2 +- src/hardforks/index.ts | 18 +- src/hardforks/spuriousDragon.json | 2 +- src/hardforks/tangerineWhistle.json | 2 +- src/index.ts | 274 +++++++++++++++------------- src/types.ts | 13 ++ 18 files changed, 321 insertions(+), 324 deletions(-) create mode 100644 src/types.ts diff --git a/docs/index.md b/docs/index.md index fd08748..2d970ce 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,32 +2,32 @@ ### Table of Contents -- [Common][1] - - [setChain][2] - - [setHardfork][3] - - [\_chooseHardfork][4] - - [\_getHardfork][5] - - [\_isSupportedHardfork][6] - - [param][7] - - [paramByBlock][8] - - [hardforkIsActiveOnBlock][9] - - [activeOnBlock][10] - - [hardforkGteHardfork][11] - - [gteHardfork][12] - - [hardforkIsActiveOnChain][13] - - [activeHardforks][14] - - [activeHardfork][15] - - [hardforkBlock][16] - - [isHardforkBlock][17] - - [consensus][18] - - [finality][19] - - [genesis][20] - - [hardforks][21] - - [bootstrapNodes][22] - - [hardfork][23] - - [chainId][24] - - [chainName][25] - - [networkId][26] +- [Common][1] + - [setChain][2] + - [setHardfork][3] + - [\_chooseHardfork][4] + - [\_getHardfork][5] + - [\_isSupportedHardfork][6] + - [param][7] + - [paramByBlock][8] + - [hardforkIsActiveOnBlock][9] + - [activeOnBlock][10] + - [hardforkGteHardfork][11] + - [gteHardfork][12] + - [hardforkIsActiveOnChain][13] + - [activeHardforks][14] + - [activeHardfork][15] + - [hardforkBlock][16] + - [isHardforkBlock][17] + - [consensus][18] + - [finality][19] + - [genesis][20] + - [hardforks][21] + - [bootstrapNodes][22] + - [hardfork][23] + - [chainId][24] + - [chainName][25] + - [networkId][26] ## Common @@ -35,9 +35,9 @@ Common class to access chain and hardfork parameters **Parameters** -- `chain` **([String][27] \| [Number][28] | Dictionary)** String ('mainnet') or Number (1) chain -- `hardfork` **[String][27]** String identifier ('byzantium') for hardfork (optional) -- `supportedHardforks` **[Array][29]** Limit parameter returns to the given hardforks (optional) +- `chain` **([String][27] \| [Number][28] | Dictionary)** String ('mainnet') or Number (1) chain +- `hardfork` **[String][27]** String identifier ('byzantium') for hardfork (optional) +- `supportedHardforks` **[Array][29]** Limit parameter returns to the given hardforks (optional) ### setChain @@ -45,8 +45,8 @@ Sets the chain **Parameters** -- `chain` **([String][27] \| [Number][28] | Dictionary)** String ('mainnet') or Number (1) chain - representation. Or, a Dictionary of chain parameters for a private network. +- `chain` **([String][27] \| [Number][28] | Dictionary)** String ('mainnet') or Number (1) chain + representation. Or, a Dictionary of chain parameters for a private network. ### setHardfork @@ -54,7 +54,7 @@ Sets the hardfork to get params for **Parameters** -- `hardfork` **[String][27]** String identifier ('byzantium') +- `hardfork` **[String][27]** String identifier ('byzantium') ### \_chooseHardfork @@ -62,8 +62,8 @@ Internal helper function to choose between hardfork set and hardfork provided as **Parameters** -- `hardfork` **[String][27]** Hardfork given to function as a parameter -- `onlySupported` +- `hardfork` **[String][27]** Hardfork given to function as a parameter +- `onlySupported` Returns **[String][27]** Hardfork chosen to be used @@ -73,9 +73,9 @@ Internal helper function, returns the params for the given hardfork for the chai **Parameters** -- `hardfork` **[String][27]** Hardfork name +- `hardfork` **[String][27]** Hardfork name -Returns **Dictionary** +Returns **Dictionary** ### \_isSupportedHardfork @@ -83,7 +83,7 @@ Internal helper function to check if a hardfork is set to be supported by the li **Parameters** -- `hardfork` **[String][27]** Hardfork name +- `hardfork` **[String][27]** Hardfork name Returns **[Boolean][30]** True if hardfork is supported @@ -93,9 +93,9 @@ Returns the parameter corresponding to a hardfork **Parameters** -- `topic` **[String][27]** Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') -- `name` **[String][27]** Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) -- `hardfork` **[String][27]** Hardfork name, optional if hardfork set +- `topic` **[String][27]** Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') +- `name` **[String][27]** Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) +- `hardfork` **[String][27]** Hardfork name, optional if hardfork set ### paramByBlock @@ -103,9 +103,9 @@ Returns a parameter for the hardfork active on block number **Parameters** -- `topic` **[String][27]** Parameter topic -- `name` **[String][27]** Parameter name -- `blockNumber` **[Number][28]** Block number +- `topic` **[String][27]** Parameter topic +- `name` **[String][27]** Parameter name +- `blockNumber` **[Number][28]** Block number ### hardforkIsActiveOnBlock @@ -113,12 +113,12 @@ Checks if set or provided hardfork is active on block number **Parameters** -- `hardfork` **[String][27]** Hardfork name or null (for HF set) -- `blockNumber` **[Number][28]** -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) +- `hardfork` **[String][27]** Hardfork name or null (for HF set) +- `blockNumber` **[Number][28]** +- `opts` **[Array][29]** + - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) -Returns **[Boolean][30]** +Returns **[Boolean][30]** ### activeOnBlock @@ -126,11 +126,11 @@ Alias to hardforkIsActiveOnBlock when hardfork is set **Parameters** -- `blockNumber` **[Number][28]** -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) +- `blockNumber` **[Number][28]** +- `opts` **[Array][29]** + - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) -Returns **[Boolean][30]** +Returns **[Boolean][30]** ### hardforkGteHardfork @@ -138,13 +138,13 @@ Sequence based check if given or set HF1 is greater than or equal HF2 **Parameters** -- `hardfork1` **[String][27]** Hardfork name or null (if set) -- `hardfork2` **[String][27]** Hardfork name -- `opts` **[Array][29]** - - `opts.onlyActive` **Array.Boolean** optional, only active HFs (default: false) - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) +- `hardfork1` **[String][27]** Hardfork name or null (if set) +- `hardfork2` **[String][27]** Hardfork name +- `opts` **[Array][29]** + - `opts.onlyActive` **Array.Boolean** optional, only active HFs (default: false) + - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) -Returns **[Boolean][30]** +Returns **[Boolean][30]** ### gteHardfork @@ -152,12 +152,12 @@ Alias to hardforkGteHardfork when hardfork is set **Parameters** -- `hardfork` **[String][27]** Hardfork name -- `opts` **[Array][29]** - - `opts.onlyActive` **Array.Boolean** optional, only active HFs (default: false) - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) +- `hardfork` **[String][27]** Hardfork name +- `opts` **[Array][29]** + - `opts.onlyActive` **Array.Boolean** optional, only active HFs (default: false) + - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) -Returns **[Boolean][30]** +Returns **[Boolean][30]** ### hardforkIsActiveOnChain @@ -165,11 +165,11 @@ Checks if given or set hardfork is active on the chain **Parameters** -- `hardfork` **[String][27]** Hardfork name, optional if HF set -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) +- `hardfork` **[String][27]** Hardfork name, optional if HF set +- `opts` **[Array][29]** + - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) -Returns **[Boolean][30]** +Returns **[Boolean][30]** ### activeHardforks @@ -177,9 +177,9 @@ Returns the active hardfork switches for the current chain **Parameters** -- `blockNumber` **[Number][28]** up to block if provided, otherwise for the whole chain -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false) +- `blockNumber` **[Number][28]** up to block if provided, otherwise for the whole chain +- `opts` **[Array][29]** + - `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false) Returns **[Array][29]** Array with hardfork arrays @@ -189,9 +189,9 @@ Returns the latest active hardfork name for chain or block or throws if unavaila **Parameters** -- `blockNumber` **[Number][28]** up to block if provided, otherwise for the whole chain -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false) +- `blockNumber` **[Number][28]** up to block if provided, otherwise for the whole chain +- `opts` **[Array][29]** + - `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false) Returns **[String][27]** Hardfork name @@ -201,7 +201,7 @@ Returns the hardfork change block for hardfork provided or set **Parameters** -- `hardfork` **[String][27]** Hardfork name, optional if HF set +- `hardfork` **[String][27]** Hardfork name, optional if HF set Returns **[Number][28]** Block number @@ -211,10 +211,10 @@ True if block number provided is the hardfork (given or set) change block of the **Parameters** -- `blockNumber` **[Number][28]** Number of the block to check -- `hardfork` **[String][27]** Hardfork name, optional if HF set +- `blockNumber` **[Number][28]** Number of the block to check +- `hardfork` **[String][27]** Hardfork name, optional if HF set -Returns **[Boolean][30]** +Returns **[Boolean][30]** ### consensus @@ -222,7 +222,7 @@ Provide the consensus type for the hardfork set or provided as param **Parameters** -- `hardfork` **[String][27]** Hardfork name, optional if hardfork set +- `hardfork` **[String][27]** Hardfork name, optional if hardfork set Returns **[String][27]** Consensus type (e.g. 'pow', 'poa') @@ -232,7 +232,7 @@ Provide the finality type for the hardfork set or provided as param **Parameters** -- `hardfork` **[String][27]** Hardfork name, optional if hardfork set +- `hardfork` **[String][27]** Hardfork name, optional if hardfork set Returns **[String][27]** Finality type (e.g. 'pos', null of no finality) @@ -279,61 +279,32 @@ Returns the Id of current network Returns **[Number][28]** network Id [1]: #common - [2]: #setchain - [3]: #sethardfork - [4]: #_choosehardfork - [5]: #_gethardfork - [6]: #_issupportedhardfork - [7]: #param - [8]: #parambyblock - [9]: #hardforkisactiveonblock - [10]: #activeonblock - [11]: #hardforkgtehardfork - [12]: #gtehardfork - [13]: #hardforkisactiveonchain - [14]: #activehardforks - [15]: #activehardfork - [16]: #hardforkblock - [17]: #ishardforkblock - [18]: #consensus - [19]: #finality - [20]: #genesis - [21]: #hardforks - [22]: #bootstrapnodes - [23]: #hardfork - [24]: #chainid - [25]: #chainname - [26]: #networkid - [27]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - [28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number - [29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array - [30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean diff --git a/src/chains/index.ts b/src/chains/index.ts index 99058f4..faf1b2e 100644 --- a/src/chains/index.ts +++ b/src/chains/index.ts @@ -1,16 +1,16 @@ -var chains = {} -chains['names'] = {} +import { chainsType } from './../types' -chains['names'][1] = 'mainnet' -chains['names'][3] = 'ropsten' -chains['names'][4] = 'rinkeby' -chains['names'][42] = 'kovan' -chains['names'][6284] = 'goerli' - -chains['mainnet'] = require('./mainnet.json') -chains['ropsten'] = require('./ropsten.json') -chains['rinkeby'] = require('./rinkeby.json') -chains['kovan'] = require('./kovan.json') -chains['goerli'] = require('./goerli.json') - -module.exports = chains +export const chains: chainsType = { + names: { + '1': 'mainnet', + '3': 'ropsten', + '4': 'rinkeby', + '42': 'kovan', + '6284': 'goerli', + }, + mainnet: require('./mainnet.json'), + ropsten: require('./ropsten.json'), + rinkeby: require('./rinkeby.json'), + kovan: require('./kovan.json'), + goerli: require('./goerli.json'), +} diff --git a/src/chains/kovan.json b/src/chains/kovan.json index f66af10..ebda072 100644 --- a/src/chains/kovan.json +++ b/src/chains/kovan.json @@ -13,8 +13,7 @@ "extraData": "0x", "stateRoot": "0x2480155b48a1cea17d67dbfdfaafe821c1d19cdd478c5358e8ec56dec24502b2" }, - "hardforks": [ - ], + "hardforks": [], "bootstrapNodes": [ { "ip": "40.71.221.215", diff --git a/src/chains/ropsten.json b/src/chains/ropsten.json index 3e58a8f..7990ed8 100644 --- a/src/chains/ropsten.json +++ b/src/chains/ropsten.json @@ -59,40 +59,40 @@ ], "bootstrapNodes": [ { - "ip": "52.176.7.10", - "port": "30303", - "id": "30b7ab30a01c124a6cceca36863ece12c4f5fa68e3ba9b0b51407ccc002eeed3b3102d20a88f1c1d3c3154e2449317b8ef95090e77b312d5cc39354f86d5d606", - "network": "Ropsten", - "chainId": 3, - "location": "US", - "comment": "US-Azure geth" - }, - { - "ip": "52.176.100.77", - "port": "30303", - "id": "865a63255b3bb68023b6bffd5095118fcc13e79dcf014fe4e47e065c350c7cc72af2e53eff895f11ba1bbb6a2b33271c1116ee870f266618eadfc2e78aa7349c", - "network": "Ropsten", - "chainId": 3, - "location": "US", - "comment": "US-Azure parity" - }, - { - "ip": "52.232.243.152", - "port": "30303", - "id": "6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f", - "network": "Ropsten", - "chainId": 3, - "location": "US", - "comment": "Parity" - }, - { - "ip": "192.81.208.223", - "port": "30303", - "id": "94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09", - "network": "Ropsten", - "chainId": 3, - "location": "US", - "comment": "@gpip" - } + "ip": "52.176.7.10", + "port": "30303", + "id": "30b7ab30a01c124a6cceca36863ece12c4f5fa68e3ba9b0b51407ccc002eeed3b3102d20a88f1c1d3c3154e2449317b8ef95090e77b312d5cc39354f86d5d606", + "network": "Ropsten", + "chainId": 3, + "location": "US", + "comment": "US-Azure geth" + }, + { + "ip": "52.176.100.77", + "port": "30303", + "id": "865a63255b3bb68023b6bffd5095118fcc13e79dcf014fe4e47e065c350c7cc72af2e53eff895f11ba1bbb6a2b33271c1116ee870f266618eadfc2e78aa7349c", + "network": "Ropsten", + "chainId": 3, + "location": "US", + "comment": "US-Azure parity" + }, + { + "ip": "52.232.243.152", + "port": "30303", + "id": "6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f", + "network": "Ropsten", + "chainId": 3, + "location": "US", + "comment": "Parity" + }, + { + "ip": "192.81.208.223", + "port": "30303", + "id": "94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09", + "network": "Ropsten", + "chainId": 3, + "location": "US", + "comment": "@gpip" + } ] } diff --git a/src/genesisStates/goerli.json b/src/genesisStates/goerli.json index 6f73c25..db60e46 100644 --- a/src/genesisStates/goerli.json +++ b/src/genesisStates/goerli.json @@ -257,4 +257,4 @@ "0x00000000000000000000000000000000000000ff": "0x1", "0x009fcc115ad9ef38288a82a014dea30f63a84383": "0x100000000000000000000000000000000000000000000000000", "0x0015c90d0e12186bc51c9d51aff4d3fb6e984291": "0x100000000000000000000000000000000000000000000000000" -} \ No newline at end of file +} diff --git a/src/genesisStates/index.ts b/src/genesisStates/index.ts index 17bfef5..4fd173a 100644 --- a/src/genesisStates/index.ts +++ b/src/genesisStates/index.ts @@ -1,16 +1,16 @@ -var genesisStates = {} -genesisStates['names'] = {} +import { genesisStatesType } from './../types' -genesisStates['names'][1] = 'mainnet' -genesisStates['names'][3] = 'ropsten' -genesisStates['names'][4] = 'rinkeby' -genesisStates['names'][42] = 'kovan' -genesisStates['names'][6284] = 'goerli' - -genesisStates['mainnet'] = require('./mainnet.json') -genesisStates['ropsten'] = require('./ropsten.json') -genesisStates['rinkeby'] = require('./rinkeby.json') -genesisStates['kovan'] = require('./kovan.json') -genesisStates['goerli'] = require('./goerli.json') - -module.exports = genesisStates +export const genesisStates: genesisStatesType = { + names: { + '1': 'mainnet', + '3': 'ropsten', + '4': 'rinkeby', + '42': 'kovan', + '6284': 'goerli', + }, + mainnet: require('./mainnet.json'), + ropsten: require('./ropsten.json'), + rinkeby: require('./rinkeby.json'), + kovan: require('./kovan.json'), + goerli: require('./goerli.json'), +} diff --git a/src/genesisStates/kovan.json b/src/genesisStates/kovan.json index 9e26dfe..0967ef4 100644 --- a/src/genesisStates/kovan.json +++ b/src/genesisStates/kovan.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/src/genesisStates/rinkeby.json b/src/genesisStates/rinkeby.json index b7ed6d2..1376331 100644 --- a/src/genesisStates/rinkeby.json +++ b/src/genesisStates/rinkeby.json @@ -256,4 +256,4 @@ "0x00000000000000000000000000000000000000fe": "0x1", "0x00000000000000000000000000000000000000ff": "0x1", "0x31b98d14007bdee637298086988a0bbd31184523": "0x200000000000000000000000000000000000000000000000000000000000000" -} \ No newline at end of file +} diff --git a/src/genesisStates/ropsten.json b/src/genesisStates/ropsten.json index dbb7583..ec13160 100644 --- a/src/genesisStates/ropsten.json +++ b/src/genesisStates/ropsten.json @@ -256,4 +256,4 @@ "0x000000000000000000000000000000000000000f": "0", "0x00000000000000000000000000000000000000d5": "0", "0x00000000000000000000000000000000000000da": "0" -} \ No newline at end of file +} diff --git a/src/hardforks/byzantium.json b/src/hardforks/byzantium.json index 86f6f8d..1810df4 100644 --- a/src/hardforks/byzantium.json +++ b/src/hardforks/byzantium.json @@ -37,4 +37,4 @@ }, "casper": {}, "sharding": {} -} \ No newline at end of file +} diff --git a/src/hardforks/chainstart.json b/src/hardforks/chainstart.json index 5c7aa23..e1d25a7 100644 --- a/src/hardforks/chainstart.json +++ b/src/hardforks/chainstart.json @@ -204,4 +204,4 @@ }, "casper": {}, "sharding": {} -} \ No newline at end of file +} diff --git a/src/hardforks/dao.json b/src/hardforks/dao.json index a3519f5..b10c653 100644 --- a/src/hardforks/dao.json +++ b/src/hardforks/dao.json @@ -11,4 +11,4 @@ "pow": {}, "casper": {}, "sharding": {} -} \ No newline at end of file +} diff --git a/src/hardforks/homestead.json b/src/hardforks/homestead.json index fb9184a..951d4d9 100644 --- a/src/hardforks/homestead.json +++ b/src/hardforks/homestead.json @@ -11,4 +11,4 @@ "pow": {}, "casper": {}, "sharding": {} -} \ No newline at end of file +} diff --git a/src/hardforks/index.ts b/src/hardforks/index.ts index bc3b28b..e966056 100644 --- a/src/hardforks/index.ts +++ b/src/hardforks/index.ts @@ -1,11 +1,9 @@ -const hardforkChanges = [ - [ 'chainstart', require('./chainstart.json') ], - [ 'homestead', require('./homestead.json') ], - [ 'dao', require('./dao.json') ], - [ 'tangerineWhistle', require('./tangerineWhistle.json') ], - [ 'spuriousDragon', require('./spuriousDragon.json') ], - [ 'byzantium', require('./byzantium.json') ], - [ 'constantinople', require('./constantinople.json') ] +export const hardforks = [ + ['chainstart', require('./chainstart.json')], + ['homestead', require('./homestead.json')], + ['dao', require('./dao.json')], + ['tangerineWhistle', require('./tangerineWhistle.json')], + ['spuriousDragon', require('./spuriousDragon.json')], + ['byzantium', require('./byzantium.json')], + ['constantinople', require('./constantinople.json')], ] - -module.exports = hardforkChanges diff --git a/src/hardforks/spuriousDragon.json b/src/hardforks/spuriousDragon.json index 834c2f5..03b5d2e 100644 --- a/src/hardforks/spuriousDragon.json +++ b/src/hardforks/spuriousDragon.json @@ -21,4 +21,4 @@ "pow": {}, "casper": {}, "sharding": {} -} \ No newline at end of file +} diff --git a/src/hardforks/tangerineWhistle.json b/src/hardforks/tangerineWhistle.json index e7cdae3..87408fe 100644 --- a/src/hardforks/tangerineWhistle.json +++ b/src/hardforks/tangerineWhistle.json @@ -20,4 +20,4 @@ "pow": {}, "casper": {}, "sharding": {} -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 7a922cb..72cded5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,33 @@ -const chainParams = require('./chains') -const hardforkChanges = require('./hardforks') +import { chains as chainParams } from './chains' +import { hardforks as hardforkChanges } from './hardforks' + +interface hardforkOptions { + /** optional, only allow supported HFs (default: false) */ + onlySupported?: boolean + /** optional, only active HFs (default: false) */ + onlyActive?: boolean +} /** * Common class to access chain and hardfork parameters */ -class Common { +export default class Common { + private _hardfork: string | null + private _supportedHardforks: Array + private _chainParams: object + /** * @constructor - * @param {String|Number|Dictionary} chain String ('mainnet') or Number (1) chain - * @param {String} hardfork String identifier ('byzantium') for hardfork (optional) - * @param {Array} supportedHardforks Limit parameter returns to the given hardforks (optional) + * @param chain String ('mainnet') or Number (1) chain + * @param hardfork String identifier ('byzantium') for hardfork (optional) + * @param supportedHardforks Limit parameter returns to the given hardforks (optional) */ - constructor (chain, hardfork, supportedHardforks) { - this.setChain(chain) + constructor( + chain: string | number | object, + hardfork?: string | null, + supportedHardforks?: Array, + ) { + this._chainParams = this.setChain(chain) this._hardfork = null this._supportedHardforks = supportedHardforks === undefined ? [] : supportedHardforks if (hardfork) { @@ -22,26 +37,27 @@ class Common { /** * Sets the chain - * @param {String|Number|Dictionary} chain String ('mainnet') or Number (1) chain + * @param chain String ('mainnet') or Number (1) chain * representation. Or, a Dictionary of chain parameters for a private network. + * @returns The dictionary with parameters set as chain */ - setChain (chain) { - if (typeof (chain) === 'number') { + setChain(chain: string | number | object): any { + if (typeof chain === 'number') { if (chainParams['names'][chain]) { this._chainParams = chainParams[chainParams['names'][chain]] } else { throw new Error(`Chain with ID ${chain} not supported`) } - } else if (typeof (chain) === 'string') { + } else if (typeof chain === 'string') { if (chainParams[chain]) { this._chainParams = chainParams[chain] } else { throw new Error(`Chain with name ${chain} not supported`) } - } else if (typeof (chain) === 'object') { + } else if (typeof chain === 'object') { const required = ['networkId', 'genesis', 'hardforks', 'bootstrapNodes'] - for (let param of required) { - if (chain[param] === undefined) { + for (const param of required) { + if ((chain)[param] === undefined) { throw new Error(`Missing required chain parameter: ${param}`) } } @@ -49,18 +65,19 @@ class Common { } else { throw new Error('Wrong input format') } + return this._chainParams } /** * Sets the hardfork to get params for - * @param {String} hardfork String identifier ('byzantium') + * @param hardfork String identifier ('byzantium') */ - setHardfork (hardfork) { + setHardfork(hardfork: string | null): void { if (!this._isSupportedHardfork(hardfork)) { throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`) } let changed = false - for (let hfChanges of hardforkChanges) { + for (const hfChanges of hardforkChanges) { if (hfChanges[0] === hardfork) { this._hardfork = hardfork changed = true @@ -73,10 +90,10 @@ class Common { /** * Internal helper function to choose between hardfork set and hardfork provided as param - * @param {String} hardfork Hardfork given to function as a parameter - * @returns {String} Hardfork chosen to be used + * @param hardfork Hardfork given to function as a parameter + * @returns Hardfork chosen to be used */ - _chooseHardfork (hardfork, onlySupported) { + _chooseHardfork(hardfork?: string | null, onlySupported?: boolean): string { onlySupported = onlySupported === undefined ? true : onlySupported if (!hardfork) { if (!this._hardfork) { @@ -84,7 +101,7 @@ class Common { } else { hardfork = this._hardfork } - } else if (!this._isSupportedHardfork(hardfork)) { + } else if (onlySupported && !this._isSupportedHardfork(hardfork)) { throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`) } return hardfork @@ -92,12 +109,12 @@ class Common { /** * Internal helper function, returns the params for the given hardfork for the chain set - * @param {String} hardfork Hardfork name - * @returns {Dictionary} + * @param hardfork Hardfork name + * @returns Dictionary with hardfork params */ - _getHardfork (hardfork) { - let hfs = this.hardforks() - for (let hf of hfs) { + _getHardfork(hardfork: string): any { + const hfs = this.hardforks() + for (const hf of hfs) { if (hf['name'] === hardfork) return hf } throw new Error(`Hardfork ${hardfork} not defined for chain ${this.chainName()}`) @@ -105,12 +122,12 @@ class Common { /** * Internal helper function to check if a hardfork is set to be supported by the library - * @param {String} hardfork Hardfork name - * @returns {Boolean} True if hardfork is supported + * @param hardfork Hardfork name + * @returns True if hardfork is supported */ - _isSupportedHardfork (hardfork) { + _isSupportedHardfork(hardfork: string | null): boolean { if (this._supportedHardforks.length > 0) { - for (let supportedHf of this._supportedHardforks) { + for (const supportedHf of this._supportedHardforks) { if (hardfork === supportedHf) return true } } else { @@ -121,15 +138,15 @@ class Common { /** * Returns the parameter corresponding to a hardfork - * @param {String} topic Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') - * @param {String} name Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) - * @param {String} hardfork Hardfork name, optional if hardfork set + * @param topic Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') + * @param name Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) + * @param hardfork Hardfork name, optional if hardfork set */ - param (topic, name, hardfork) { + param(topic: string, name: string, hardfork?: string): any { hardfork = this._chooseHardfork(hardfork) let value - for (let hfChanges of hardforkChanges) { + for (const hfChanges of hardforkChanges) { if (!hfChanges[1][topic]) { throw new Error(`Topic ${topic} not defined`) } @@ -146,56 +163,60 @@ class Common { /** * Returns a parameter for the hardfork active on block number - * @param {String} topic Parameter topic - * @param {String} name Parameter name - * @param {Number} blockNumber Block number + * @param topic Parameter topic + * @param name Parameter name + * @param blockNumber Block number */ - paramByBlock (topic, name, blockNumber) { - let activeHfs = this.activeHardforks(blockNumber) - let hardfork = activeHfs[activeHfs.length - 1]['name'] + paramByBlock(topic: string, name: string, blockNumber: number): any { + const activeHfs = this.activeHardforks(blockNumber) + const hardfork = activeHfs[activeHfs.length - 1]['name'] return this.param(topic, name, hardfork) } /** * Checks if set or provided hardfork is active on block number - * @param {String} hardfork Hardfork name or null (for HF set) - * @param {Number} blockNumber - * @param {Array} opts - * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false) - * @returns {Boolean} + * @param hardfork Hardfork name or null (for HF set) + * @param blockNumber + * @param opts Hardfork options (onlyActive unused) + * @returns True if HF is active on block number */ - hardforkIsActiveOnBlock (hardfork, blockNumber, opts) { - opts = opts !== undefined ? opts : [] - let onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported + hardforkIsActiveOnBlock( + hardfork: string | null, + blockNumber: number, + opts?: hardforkOptions, + ): boolean { + opts = opts !== undefined ? opts : {} + const onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported hardfork = this._chooseHardfork(hardfork, onlySupported) - let hfBlock = this.hardforkBlock(hardfork) + const hfBlock = this.hardforkBlock(hardfork) if (hfBlock !== null && blockNumber >= hfBlock) return true return false } /** * Alias to hardforkIsActiveOnBlock when hardfork is set - * @param {Number} blockNumber - * @param {Array} opts - * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false) - * @returns {Boolean} + * @param blockNumber + * @param opts Hardfork options (onlyActive unused) + * @returns True if HF is active on block number */ - activeOnBlock (blockNumber, opts) { + activeOnBlock(blockNumber: number, opts?: hardforkOptions): boolean { return this.hardforkIsActiveOnBlock(null, blockNumber, opts) } /** * Sequence based check if given or set HF1 is greater than or equal HF2 - * @param {String} hardfork1 Hardfork name or null (if set) - * @param {String} hardfork2 Hardfork name - * @param {Array} opts - * @param {Array.Boolean} opts.onlyActive optional, only active HFs (default: false) - * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false) - * @returns {Boolean} + * @param hardfork1 Hardfork name or null (if set) + * @param hardfork2 Hardfork name + * @param opts Hardfork options + * @returns True if HF1 gte HF2 */ - hardforkGteHardfork (hardfork1, hardfork2, opts) { - opts = opts !== undefined ? opts : [] - let onlyActive = opts.onlyActive === undefined ? false : opts.onlyActive + hardforkGteHardfork( + hardfork1: string | null, + hardfork2: string, + opts?: hardforkOptions, + ): boolean { + opts = opts !== undefined ? opts : {} + const onlyActive = opts.onlyActive === undefined ? false : opts.onlyActive hardfork1 = this._chooseHardfork(hardfork1, opts.onlySupported) let hardforks @@ -205,9 +226,10 @@ class Common { hardforks = this.hardforks() } - let posHf1, posHf2 + let posHf1 = 0, + posHf2 = 0 let index = 0 - for (let hf of hardforks) { + for (const hf of hardforks) { if (hf['name'] === hardfork1) posHf1 = index if (hf['name'] === hardfork2) posHf2 = index index += 1 @@ -217,28 +239,25 @@ class Common { /** * Alias to hardforkGteHardfork when hardfork is set - * @param {String} hardfork Hardfork name - * @param {Array} opts - * @param {Array.Boolean} opts.onlyActive optional, only active HFs (default: false) - * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false) - * @returns {Boolean} + * @param hardfork Hardfork name + * @param opts Hardfork options + * @returns True if hardfork set is greater than hardfork provided */ - gteHardfork (hardfork, opts) { + gteHardfork(hardfork: string, opts?: hardforkOptions): boolean { return this.hardforkGteHardfork(null, hardfork, opts) } /** * Checks if given or set hardfork is active on the chain - * @param {String} hardfork Hardfork name, optional if HF set - * @param {Array} opts - * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false) - * @returns {Boolean} + * @param hardfork Hardfork name, optional if HF set + * @param opts Hardfork options (onlyActive unused) + * @returns True if hardfork is active on the chain */ - hardforkIsActiveOnChain (hardfork, opts) { - opts = opts !== undefined ? opts : [] - let onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported + hardforkIsActiveOnChain(hardfork?: string | null, opts?: hardforkOptions): boolean { + opts = opts !== undefined ? opts : {} + const onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported hardfork = this._chooseHardfork(hardfork, onlySupported) - for (let hf of this.hardforks()) { + for (const hf of this.hardforks()) { if (hf['name'] === hardfork && hf['block'] !== null) return true } return false @@ -246,18 +265,17 @@ class Common { /** * Returns the active hardfork switches for the current chain - * @param {Number} blockNumber up to block if provided, otherwise for the whole chain - * @param {Array} opts - * @param {Array.Boolean} opts.onlySupported optional, limit results to supported HFs (default: false) - * @return {Array} Array with hardfork arrays + * @param blockNumber up to block if provided, otherwise for the whole chain + * @param opts Hardfork options (onlyActive unused) + * @return Array with hardfork arrays */ - activeHardforks (blockNumber, opts) { - opts = opts !== undefined ? opts : [] - let activeHardforks = [] - let hfs = this.hardforks() - for (let hf of hfs) { + activeHardforks(blockNumber?: number | null, opts?: hardforkOptions): Array { + opts = opts !== undefined ? opts : {} + const activeHardforks = [] + const hfs = this.hardforks() + for (const hf of hfs) { if (hf['block'] === null) continue - if ((blockNumber !== undefined && blockNumber !== null) && blockNumber < hf['block']) break + if (blockNumber !== undefined && blockNumber !== null && blockNumber < hf['block']) break if (opts.onlySupported && !this._isSupportedHardfork(hf['name'])) continue activeHardforks.push(hf) @@ -267,13 +285,13 @@ class Common { /** * Returns the latest active hardfork name for chain or block or throws if unavailable - * @param {Number} blockNumber up to block if provided, otherwise for the whole chain - * @param {Array} opts - * @param {Array.Boolean} opts.onlySupported optional, limit results to supported HFs (default: false) - * @return {String} Hardfork name + * @param blockNumber up to block if provided, otherwise for the whole chain + * @param opts Hardfork options (onlyActive unused) + * @return Hardfork name */ - activeHardfork (blockNumber, opts) { - let activeHardforks = this.activeHardforks(blockNumber, opts) + activeHardfork(blockNumber?: number | null, opts?: hardforkOptions): string { + opts = opts !== undefined ? opts : {} + const activeHardforks = this.activeHardforks(blockNumber, opts) if (activeHardforks.length > 0) { return activeHardforks[activeHardforks.length - 1]['name'] } else { @@ -283,21 +301,21 @@ class Common { /** * Returns the hardfork change block for hardfork provided or set - * @param {String} hardfork Hardfork name, optional if HF set - * @returns {Number} Block number + * @param hardfork Hardfork name, optional if HF set + * @returns Block number */ - hardforkBlock (hardfork) { + hardforkBlock(hardfork?: string): number { hardfork = this._chooseHardfork(hardfork, false) return this._getHardfork(hardfork)['block'] } /** * True if block number provided is the hardfork (given or set) change block of the current chain - * @param {Number} blockNumber Number of the block to check - * @param {String} hardfork Hardfork name, optional if HF set - * @returns {Boolean} + * @param blockNumber Number of the block to check + * @param hardfork Hardfork name, optional if HF set + * @returns True if blockNumber is HF block */ - isHardforkBlock (blockNumber, hardfork) { + isHardforkBlock(blockNumber: number, hardfork?: string): boolean { hardfork = this._chooseHardfork(hardfork, false) if (this.hardforkBlock(hardfork) === blockNumber) { return true @@ -308,10 +326,10 @@ class Common { /** * Provide the consensus type for the hardfork set or provided as param - * @param {String} hardfork Hardfork name, optional if hardfork set - * @returns {String} Consensus type (e.g. 'pow', 'poa') + * @param hardfork Hardfork name, optional if hardfork set + * @returns Consensus type (e.g. 'pow', 'poa') */ - consensus (hardfork) { + consensus(hardfork?: string): string { hardfork = this._chooseHardfork(hardfork) return this._getHardfork(hardfork)['consensus'] } @@ -321,66 +339,64 @@ class Common { * @param {String} hardfork Hardfork name, optional if hardfork set * @returns {String} Finality type (e.g. 'pos', null of no finality) */ - finality (hardfork) { + finality(hardfork?: string): string { hardfork = this._chooseHardfork(hardfork) return this._getHardfork(hardfork)['finality'] } /** * Returns the Genesis parameters of current chain - * @returns {Dictionary} Genesis dict - */ - genesis () { - return this._chainParams['genesis'] + * @returns Genesis dictionary + */ + genesis(): any { + return (this._chainParams)['genesis'] } /** * Returns the hardforks for current chain * @returns {Array} Array with arrays of hardforks */ - hardforks () { - return this._chainParams['hardforks'] + hardforks(): any { + return (this._chainParams)['hardforks'] } /** * Returns bootstrap nodes for the current chain * @returns {Dictionary} Dict with bootstrap nodes */ - bootstrapNodes () { - return this._chainParams['bootstrapNodes'] + bootstrapNodes(): any { + return (this._chainParams)['bootstrapNodes'] } /** * Returns the hardfork set - * @returns {String} Hardfork name + * @returns Hardfork name */ - hardfork () { + hardfork(): string | null { return this._hardfork } /** * Returns the Id of current chain - * @returns {Number} chain Id + * @returns chain Id */ - chainId () { - return this._chainParams['chainId'] + chainId(): number { + return (this._chainParams)['chainId'] } /** * Returns the name of current chain - * @returns {String} chain name (lower case) + * @returns chain name (lower case) */ - chainName () { - return chainParams['names'][this.chainId()] || this._chainParams['name'] + chainName(): string { + return chainParams['names'][this.chainId()] || (this._chainParams)['name'] } /** * Returns the Id of current network - * @returns {Number} network Id + * @returns network Id */ - networkId () { - return this._chainParams['networkId'] + networkId(): number { + return (this._chainParams)['networkId'] } } - -module.exports = Common diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..f9c6b02 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,13 @@ +export interface genesisStatesType { + names: { + [key: string]: string + } + [key: string]: {} +} + +export interface chainsType { + names: { + [key: string]: string + } + [key: string]: {} +} From 3fea995fc1923e799a56a78f114065edfe03d39f Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 7 Jan 2019 12:26:30 +0100 Subject: [PATCH 7/9] Use TypeScript .ts file extensions for all .js test files (renaming) --- tests/{chains.js => chains.ts} | 0 tests/{hardforks.js => hardforks.ts} | 0 tests/index.js | 3 --- tests/{params.js => params.ts} | 0 4 files changed, 3 deletions(-) rename tests/{chains.js => chains.ts} (100%) rename tests/{hardforks.js => hardforks.ts} (100%) delete mode 100644 tests/index.js rename tests/{params.js => params.ts} (100%) diff --git a/tests/chains.js b/tests/chains.ts similarity index 100% rename from tests/chains.js rename to tests/chains.ts diff --git a/tests/hardforks.js b/tests/hardforks.ts similarity index 100% rename from tests/hardforks.js rename to tests/hardforks.ts diff --git a/tests/index.js b/tests/index.js deleted file mode 100644 index ffb9735..0000000 --- a/tests/index.js +++ /dev/null @@ -1,3 +0,0 @@ -require('./chains.js') -require('./hardforks.js') -require('./params.js') diff --git a/tests/params.js b/tests/params.ts similarity index 100% rename from tests/params.js rename to tests/params.ts From 245d4d95e9f84c87c6573728a3e97a5a562a0031 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 7 Jan 2019 12:38:22 +0100 Subject: [PATCH 8/9] TypeScript test updates --- tests/chains.ts | 118 +++++++++++++++------ tests/hardforks.ts | 248 +++++++++++++++++++++++++++++++++++---------- tests/params.ts | 104 +++++++++++++++---- 3 files changed, 367 insertions(+), 103 deletions(-) diff --git a/tests/chains.ts b/tests/chains.ts index 0c8c5a1..a143284 100644 --- a/tests/chains.ts +++ b/tests/chains.ts @@ -1,8 +1,8 @@ -const tape = require('tape') -const Common = require('../index.js') +import * as tape from 'tape' +import Common from '../src/' -tape('[Common]: Initialization / Chain params', function (t) { - t.test('Should initialize with chain provided', function (st) { +tape('[Common]: Initialization / Chain params', function(t: tape.Test) { + t.test('Should initialize with chain provided', function(st: tape.Test) { let c = new Common('mainnet') st.equal(c.chainName(), 'mainnet', 'should initialize with chain name') st.equal(c.chainId(), 1, 'should return correct chain Id') @@ -16,70 +16,128 @@ tape('[Common]: Initialization / Chain params', function (t) { st.end() }) - t.test('Should initialize with chain and hardfork provided', function (st) { - let c = new Common('mainnet', 'byzantium') + t.test('Should initialize with chain and hardfork provided', function(st: tape.Test) { + const c = new Common('mainnet', 'byzantium') st.equal(c.hardfork(), 'byzantium', 'should return correct hardfork name') st.end() }) - t.test('Should initialize with supportedHardforks provided', function (st) { - let c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople']) + t.test('Should initialize with supportedHardforks provided', function(st: tape.Test) { + const c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople']) st.equal(c._isSupportedHardfork('byzantium'), true, 'should return true for supported HF') - st.equal(c._isSupportedHardfork('spuriousDragon'), false, 'should return false for unsupported HF') + st.equal( + c._isSupportedHardfork('spuriousDragon'), + false, + 'should return false for unsupported HF', + ) st.end() }) - t.test('Should handle initialization errors', function (st) { - st.throws(function () { new Common('chainnotexisting') }, /not supported$/, 'should throw an exception on non-existing chain') // eslint-disable-line no-new - st.throws(function () { new Common('mainnet', 'hardforknotexisting') }, /not supported$/, 'should throw an exception on non-existing hardfork') // eslint-disable-line no-new - st.throws(function () { new Common('mainnet', 'spuriousDragon', ['byzantium', 'constantinople']) }, /supportedHardforks$/, 'should throw an exception on conflicting active/supported HF params') // eslint-disable-line no-new + t.test('Should handle initialization errors', function(st: tape.Test) { + st.throws( + function() { + new Common('chainnotexisting') + }, + /not supported$/, + 'should throw an exception on non-existing chain', + ) // eslint-disable-line no-new + st.throws( + function() { + new Common('mainnet', 'hardforknotexisting') + }, + /not supported$/, + 'should throw an exception on non-existing hardfork', + ) // eslint-disable-line no-new + st.throws( + function() { + new Common('mainnet', 'spuriousDragon', ['byzantium', 'constantinople']) + }, + /supportedHardforks$/, + 'should throw an exception on conflicting active/supported HF params', + ) // eslint-disable-line no-new st.end() }) - t.test('Should provide correct access to chain parameters', function (st) { - let c = new Common('mainnet') - st.equal(c.genesis().hash, '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', 'should return correct genesis hash') + t.test('Should provide correct access to chain parameters', function(st: tape.Test) { + const c = new Common('mainnet') + st.equal( + c.genesis().hash, + '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', + 'should return correct genesis hash', + ) st.equal(c.hardforks()[3]['block'], 2463000, 'should return correct hardfork data') st.equal(c.bootstrapNodes()[0].port, 30303, 'should return a bootstrap node array') st.end() }) - t.test('Should be able to access data for all chains provided', function (st) { - let c = new Common('mainnet') - st.equal(c.genesis().hash, '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', 'mainnet') + t.test('Should be able to access data for all chains provided', function(st: tape.Test) { + const c = new Common('mainnet') + st.equal( + c.genesis().hash, + '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', + 'mainnet', + ) c.setChain('ropsten') - st.equal(c.genesis().hash, '0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d', 'ropsten') + st.equal( + c.genesis().hash, + '0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d', + 'ropsten', + ) c.setChain('rinkeby') - st.equal(c.genesis().hash, '0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177', 'rinkeby') + st.equal( + c.genesis().hash, + '0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177', + 'rinkeby', + ) c.setChain('kovan') - st.equal(c.genesis().hash, '0xa3c565fc15c7478862d50ccd6561e3c06b24cc509bf388941c25ea985ce32cb9', 'kovan') + st.equal( + c.genesis().hash, + '0xa3c565fc15c7478862d50ccd6561e3c06b24cc509bf388941c25ea985ce32cb9', + 'kovan', + ) c.setChain('goerli') - st.equal(c.genesis().hash, '0xfa57319d09fd8a32faaf18d338c8a925a5a7975285bf29ecd024e083cba8abb1', 'goerli') + st.equal( + c.genesis().hash, + '0xfa57319d09fd8a32faaf18d338c8a925a5a7975285bf29ecd024e083cba8abb1', + 'goerli', + ) st.end() }) - t.test('Should provide correct access to private network chain parameters', function (st) { - let chainParams = require('./testnet.json') - let c = new Common(chainParams, 'byzantium') + t.test('Should provide correct access to private network chain parameters', function( + st: tape.Test, + ) { + const chainParams = require('./testnet.json') + const c = new Common(chainParams, 'byzantium') st.equal(c.chainName(), 'testnet', 'should initialize with chain name') st.equal(c.chainId(), 12345, 'should return correct chain Id') st.equal(c.networkId(), 12345, 'should return correct network Id') - st.equal(c.genesis().hash, '0xaa00000000000000000000000000000000000000000000000000000000000000', 'should return correct genesis hash') + st.equal( + c.genesis().hash, + '0xaa00000000000000000000000000000000000000000000000000000000000000', + 'should return correct genesis hash', + ) st.equal(c.hardforks()[3]['block'], 3, 'should return correct hardfork data') st.equal(c.bootstrapNodes()[1].ip, '10.0.0.2', 'should return a bootstrap node array') st.end() }) - t.test('Should handle custom chain parameters with missing field', function (st) { - let chainParams = require('./testnet.json') + t.test('Should handle custom chain parameters with missing field', function(st: tape.Test) { + const chainParams = require('./testnet.json') delete chainParams['hardforks'] - st.throws(function () { new Common(chainParams) }, /Missing required/, 'should throw an exception on missing parameter') // eslint-disable-line no-new + st.throws( + function() { + new Common(chainParams) + }, + /Missing required/, + 'should throw an exception on missing parameter', + ) // eslint-disable-line no-new st.end() }) diff --git a/tests/hardforks.ts b/tests/hardforks.ts index 9f75af5..0e62ba5 100644 --- a/tests/hardforks.ts +++ b/tests/hardforks.ts @@ -1,20 +1,20 @@ -const tape = require('tape') -const Common = require('../index.js') +import * as tape from 'tape' +import Common from '../src/' -tape('[Common]: Hardfork logic', function (t) { - t.test('Hardfork access', function (st) { - let supportedHardforks = [ +tape('[Common]: Hardfork logic', function(t: tape.Test) { + t.test('Hardfork access', function(st: tape.Test) { + const supportedHardforks = [ 'chainstart', 'homestead', 'dao', 'tangerineWhistle', 'spuriousDragon', 'byzantium', - 'constantinople' + 'constantinople', ] let c - for (let hardfork of supportedHardforks) { + for (const hardfork of supportedHardforks) { c = new Common('mainnet', hardfork) st.equal(c.hardfork(), hardfork, hardfork) } @@ -22,103 +22,249 @@ tape('[Common]: Hardfork logic', function (t) { st.end() }) - t.test('hardforkBlock()', function (st) { + t.test('hardforkBlock()', function(st: tape.Test) { let c = new Common('ropsten') - st.equal(c.hardforkBlock('byzantium'), 1700000, 'should return the correct HF change block for byzantium (provided)') + st.equal( + c.hardforkBlock('byzantium'), + 1700000, + 'should return the correct HF change block for byzantium (provided)', + ) c = new Common('ropsten', 'byzantium') - st.equal(c.hardforkBlock(), 1700000, 'should return the correct HF change block for byzantium (set)') + st.equal( + c.hardforkBlock(), + 1700000, + 'should return the correct HF change block for byzantium (set)', + ) st.end() }) - t.test('isHardforkBlock()', function (st) { + t.test('isHardforkBlock()', function(st: tape.Test) { let c = new Common('ropsten') - st.equal(c.isHardforkBlock(1700000, 'byzantium'), true, 'should return true for HF change block for byzantium (provided)') - st.equal(c.isHardforkBlock(1700001, 'byzantium'), false, 'should return false for another block for byzantium (provided)') + st.equal( + c.isHardforkBlock(1700000, 'byzantium'), + true, + 'should return true for HF change block for byzantium (provided)', + ) + st.equal( + c.isHardforkBlock(1700001, 'byzantium'), + false, + 'should return false for another block for byzantium (provided)', + ) c = new Common('ropsten', 'byzantium') - st.equal(c.isHardforkBlock(1700000), true, 'should return true for HF change block for byzantium (set)') - st.equal(c.isHardforkBlock(1700001), false, 'should return false for another block for byzantium (set)') + st.equal( + c.isHardforkBlock(1700000), + true, + 'should return true for HF change block for byzantium (set)', + ) + st.equal( + c.isHardforkBlock(1700001), + false, + 'should return false for another block for byzantium (set)', + ) st.end() }) - t.test('activeHardforks()', function (st) { + t.test('activeHardforks()', function(st: tape.Test) { let c = new Common('ropsten') st.equal(c.activeHardforks().length, 5, 'should return 5 active hardforks for Ropsten') - st.equal(c.activeHardforks()[3]['name'], 'spuriousDragon', 'should return the correct HF data for Ropsten') - st.equal(c.activeHardforks(9).length, 3, 'should return 3 active hardforks for Ropsten up to block 9') - st.equal(c.activeHardforks(10).length, 4, 'should return 4 active hardforks for Ropsten up to block 10') + st.equal( + c.activeHardforks()[3]['name'], + 'spuriousDragon', + 'should return the correct HF data for Ropsten', + ) + st.equal( + c.activeHardforks(9).length, + 3, + 'should return 3 active hardforks for Ropsten up to block 9', + ) + st.equal( + c.activeHardforks(10).length, + 4, + 'should return 4 active hardforks for Ropsten up to block 10', + ) c = new Common('ropsten', null, ['spuriousDragon', 'byzantium', 'constantinople']) - st.equal(c.activeHardforks(null, { onlySupported: true }).length, 2, 'should return 2 active HFs when restricted to supported HFs') + st.equal( + c.activeHardforks(null, { onlySupported: true }).length, + 2, + 'should return 2 active HFs when restricted to supported HFs', + ) st.end() }) - t.test('activeHardfork()', function (st) { + t.test('activeHardfork()', function(st: tape.Test) { let c = new Common('ropsten') - st.equal(c.activeHardfork(), 'byzantium', 'should return byzantium as latest active HF for Ropsten') - st.equal(c.activeHardfork(10), 'spuriousDragon', 'should return spuriousDragon as latest active HF for Ropsten for block 10') + st.equal( + c.activeHardfork(), + 'byzantium', + 'should return byzantium as latest active HF for Ropsten', + ) + st.equal( + c.activeHardfork(10), + 'spuriousDragon', + 'should return spuriousDragon as latest active HF for Ropsten for block 10', + ) c = new Common('ropsten', null, ['tangerineWhistle', 'spuriousDragon']) - st.equal(c.activeHardfork(null, { onlySupported: true }), 'spuriousDragon', 'should return spuriousDragon as latest active HF for Ropsten with limited supported hardforks') + st.equal( + c.activeHardfork(null, { onlySupported: true }), + 'spuriousDragon', + 'should return spuriousDragon as latest active HF for Ropsten with limited supported hardforks', + ) st.end() }) - t.test('hardforkIsActiveOnBlock() / activeOnBlock()', function (st) { + t.test('hardforkIsActiveOnBlock() / activeOnBlock()', function(st: tape.Test) { let c = new Common('ropsten') - st.equal(c.hardforkIsActiveOnBlock('byzantium', 1700000), true, 'Ropsten, byzantium (provided), 1700000 -> true') - st.equal(c.hardforkIsActiveOnBlock('byzantium', 1700005), true, 'Ropsten, byzantium (provided), 1700005 -> true') - st.equal(c.hardforkIsActiveOnBlock('byzantium', 1699999), false, 'Ropsten, byzantium (provided), 1699999 -> false') + st.equal( + c.hardforkIsActiveOnBlock('byzantium', 1700000), + true, + 'Ropsten, byzantium (provided), 1700000 -> true', + ) + st.equal( + c.hardforkIsActiveOnBlock('byzantium', 1700005), + true, + 'Ropsten, byzantium (provided), 1700005 -> true', + ) + st.equal( + c.hardforkIsActiveOnBlock('byzantium', 1699999), + false, + 'Ropsten, byzantium (provided), 1699999 -> false', + ) c = new Common('ropsten', 'byzantium') - st.equal(c.hardforkIsActiveOnBlock(null, 1700000), true, 'Ropsten, byzantium (set), 1700000 -> true') - st.equal(c.activeOnBlock(1700000), true, 'Ropsten, byzantium (set), 1700000 -> true (alias function)') - st.equal(c.hardforkIsActiveOnBlock(null, 1700005), true, 'Ropsten, byzantium (set), 1700005 -> true') - st.equal(c.hardforkIsActiveOnBlock(null, 1699999), false, 'Ropsten, byzantium (set), 1699999 -> false') + st.equal( + c.hardforkIsActiveOnBlock(null, 1700000), + true, + 'Ropsten, byzantium (set), 1700000 -> true', + ) + st.equal( + c.activeOnBlock(1700000), + true, + 'Ropsten, byzantium (set), 1700000 -> true (alias function)', + ) + st.equal( + c.hardforkIsActiveOnBlock(null, 1700005), + true, + 'Ropsten, byzantium (set), 1700005 -> true', + ) + st.equal( + c.hardforkIsActiveOnBlock(null, 1699999), + false, + 'Ropsten, byzantium (set), 1699999 -> false', + ) st.end() }) - t.test('hardforkGteHardfork()', function (st) { + t.test('hardforkGteHardfork()', function(st: tape.Test) { let c = new Common('ropsten') - st.equal(c.hardforkGteHardfork('constantinople', 'byzantium'), true, 'Ropsten, constantinople >= byzantium (provided) -> true') - st.equal(c.hardforkGteHardfork('constantinople', 'byzantium', { onlyActive: true }), false, 'Ropsten, constantinople >= byzantium (provided), onlyActive -> fale') - st.equal(c.hardforkGteHardfork('byzantium', 'byzantium'), true, 'Ropsten, byzantium >= byzantium (provided) -> true') - st.equal(c.hardforkGteHardfork('spuriousDragon', 'byzantium'), false, 'Ropsten, spuriousDragon >= byzantium (provided) -> false') + st.equal( + c.hardforkGteHardfork('constantinople', 'byzantium'), + true, + 'Ropsten, constantinople >= byzantium (provided) -> true', + ) + st.equal( + c.hardforkGteHardfork('constantinople', 'byzantium', { + onlyActive: true, + }), + false, + 'Ropsten, constantinople >= byzantium (provided), onlyActive -> fale', + ) + st.equal( + c.hardforkGteHardfork('byzantium', 'byzantium'), + true, + 'Ropsten, byzantium >= byzantium (provided) -> true', + ) + st.equal( + c.hardforkGteHardfork('spuriousDragon', 'byzantium'), + false, + 'Ropsten, spuriousDragon >= byzantium (provided) -> false', + ) c = new Common('ropsten', 'byzantium') - st.equal(c.hardforkGteHardfork(null, 'spuriousDragon'), true, 'Ropsten, byzantium (set) >= spuriousDragon -> true') - st.equal(c.gteHardfork('spuriousDragon'), true, 'Ropsten, byzantium (set) >= spuriousDragon -> true (alias function)') - st.equal(c.hardforkGteHardfork(null, 'spuriousDragon', { onlyActive: true }), true, 'Ropsten, byzantium (set) >= spuriousDragon, onlyActive -> true') - st.equal(c.hardforkGteHardfork(null, 'byzantium'), true, 'Ropsten, byzantium (set) >= byzantium -> true') - st.equal(c.hardforkGteHardfork(null, 'constantinople'), false, 'Ropsten, byzantium (set) >= constantinople -> false') + st.equal( + c.hardforkGteHardfork(null, 'spuriousDragon'), + true, + 'Ropsten, byzantium (set) >= spuriousDragon -> true', + ) + st.equal( + c.gteHardfork('spuriousDragon'), + true, + 'Ropsten, byzantium (set) >= spuriousDragon -> true (alias function)', + ) + st.equal( + c.hardforkGteHardfork(null, 'spuriousDragon', { onlyActive: true }), + true, + 'Ropsten, byzantium (set) >= spuriousDragon, onlyActive -> true', + ) + st.equal( + c.hardforkGteHardfork(null, 'byzantium'), + true, + 'Ropsten, byzantium (set) >= byzantium -> true', + ) + st.equal( + c.hardforkGteHardfork(null, 'constantinople'), + false, + 'Ropsten, byzantium (set) >= constantinople -> false', + ) st.end() }) - t.test('hardforkIsActiveOnChain()', function (st) { + t.test('hardforkIsActiveOnChain()', function(st: tape.Test) { let c = new Common('ropsten') - st.equal(c.hardforkIsActiveOnChain('byzantium'), true, 'should return true for byzantium (provided) on Ropsten') - st.equal(c.hardforkIsActiveOnChain('dao'), false, 'should return false for dao (provided) on Ropsten') - st.equal(c.hardforkIsActiveOnChain('constantinople'), false, 'should return false for constantinople (provided) on Ropsten') - st.equal(c.hardforkIsActiveOnChain('notexistinghardfork'), false, 'should return false for a non-existing HF (provided) on Ropsten') - st.doesNotThrow(function () { c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true }) }, /unsupported hardfork$/, 'should not throw with unsupported Hf (provided) and onlySupported set to false') // eslint-disable-line no-new + st.equal( + c.hardforkIsActiveOnChain('byzantium'), + true, + 'should return true for byzantium (provided) on Ropsten', + ) + st.equal( + c.hardforkIsActiveOnChain('dao'), + false, + 'should return false for dao (provided) on Ropsten', + ) + st.equal( + c.hardforkIsActiveOnChain('constantinople'), + false, + 'should return false for constantinople (provided) on Ropsten', + ) + st.equal( + c.hardforkIsActiveOnChain('notexistinghardfork'), + false, + 'should return false for a non-existing HF (provided) on Ropsten', + ) + st.doesNotThrow( + function() { + c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true }) + }, + /unsupported hardfork$/, + 'should not throw with unsupported Hf (provided) and onlySupported set to false', + ) // eslint-disable-line no-new c = new Common('ropsten', 'byzantium') st.equal(c.hardforkIsActiveOnChain(), true, 'should return true for byzantium (set) on Ropsten') c = new Common('ropsten', null, ['byzantium', 'constantinople']) - st.throws(function () { c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true }) }, /not set as supported in supportedHardforks$/, 'should throw with unsupported Hf and onlySupported set to true') // eslint-disable-line no-new + st.throws( + function() { + c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true }) + }, + /not set as supported in supportedHardforks$/, + 'should throw with unsupported Hf and onlySupported set to true', + ) // eslint-disable-line no-new st.end() }) - t.test('consensus()/finality()', function (st) { - let c = new Common('mainnet') + t.test('consensus()/finality()', function(st: tape.Test) { + const c = new Common('mainnet') st.equal(c.consensus('byzantium'), 'pow', 'should return pow for byzantium consensus') st.equal(c.consensus('constantinople'), 'pow', 'should return pow for constantinople consensus') st.equal(c.finality('byzantium'), null, 'should return null for byzantium finality') diff --git a/tests/params.ts b/tests/params.ts index 8426af8..3bcc4df 100644 --- a/tests/params.ts +++ b/tests/params.ts @@ -1,10 +1,14 @@ -const tape = require('tape') -const Common = require('../index.js') +import * as tape from 'tape' +import Common from '../src/' -tape('[Common]: Parameter access', function (t) { - t.test('Basic usage', function (st) { - let c = new Common('mainnet') - st.equal(c.param('gasPrices', 'ecAdd', 'byzantium'), 500, 'Should return correct value when HF directly provided') +tape('[Common]: Parameter access', function(t: tape.Test) { + t.test('Basic usage', function(st: tape.Test) { + const c = new Common('mainnet') + st.equal( + c.param('gasPrices', 'ecAdd', 'byzantium'), + 500, + 'Should return correct value when HF directly provided', + ) c.setHardfork('byzantium') st.equal(c.param('gasPrices', 'ecAdd'), 500, 'Should return correct value for HF set in class') @@ -12,38 +16,94 @@ tape('[Common]: Parameter access', function (t) { st.end() }) - t.test('Error cases', function (st) { + t.test('Error cases', function(st: tape.Test) { let c = new Common('mainnet') - st.throws(function () { c.param('gasPrices', 'ecAdd') }, /neither a hardfork set nor provided by param$/, 'Should throw when no hardfork set or provided') - st.throws(function () { c.param('gasPrizes', 'ecAdd', 'byzantium') }, /Topic gasPrizes not defined$/, 'Should throw when called with non-existing topic') - st.throws(function () { c.param('gasPrices', 'notexistingvalue', 'byzantium') }, /value for notexistingvalue not found$/, 'Should throw when called with non-existing value') + st.throws( + function() { + c.param('gasPrices', 'ecAdd') + }, + /neither a hardfork set nor provided by param$/, + 'Should throw when no hardfork set or provided', + ) + st.throws( + function() { + c.param('gasPrizes', 'ecAdd', 'byzantium') + }, + /Topic gasPrizes not defined$/, + 'Should throw when called with non-existing topic', + ) + st.throws( + function() { + c.param('gasPrices', 'notexistingvalue', 'byzantium') + }, + /value for notexistingvalue not found$/, + 'Should throw when called with non-existing value', + ) c.setHardfork('byzantium') st.equal(c.param('gasPrices', 'ecAdd'), 500, 'Should return correct value for HF set in class') c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople']) - st.throws(function () { c.param('gasPrices', 'expByte', 'spuriousDragon') }, /supportedHardforks$/, 'Should throw when calling param() with an unsupported hardfork') - st.throws(function () { c.paramByBlock('gasPrices', 'expByte', 0) }, /supportedHardforks$/, 'Should throw when calling paramByBlock() with an unsupported hardfork') + st.throws( + function() { + c.param('gasPrices', 'expByte', 'spuriousDragon') + }, + /supportedHardforks$/, + 'Should throw when calling param() with an unsupported hardfork', + ) + st.throws( + function() { + c.paramByBlock('gasPrices', 'expByte', 0) + }, + /supportedHardforks$/, + 'Should throw when calling paramByBlock() with an unsupported hardfork', + ) st.end() }) - t.test('Parameter updates', function (st) { - let c = new Common('mainnet') - st.throws(function () { c.param('gasPrices', 'ecAdd', 'spuriousDragon') }, /value for ecAdd not found$/, 'Should throw for a value set on a later HF') + t.test('Parameter updates', function(st: tape.Test) { + const c = new Common('mainnet') + st.throws( + function() { + c.param('gasPrices', 'ecAdd', 'spuriousDragon') + }, + /value for ecAdd not found$/, + 'Should throw for a value set on a later HF', + ) - st.equal(c.param('pow', 'minerReward', 'chainstart'), '5000000000000000000', 'Should return correct value for chain start') - st.equal(c.param('pow', 'minerReward', 'byzantium'), '3000000000000000000', 'Should reflect HF update changes') - st.equal(c.param('gasPrices', 'netSstoreNoopGas', 'constantinople'), 200, 'Should return updated sstore gas prices for constantinople') + st.equal( + c.param('pow', 'minerReward', 'chainstart'), + '5000000000000000000', + 'Should return correct value for chain start', + ) + st.equal( + c.param('pow', 'minerReward', 'byzantium'), + '3000000000000000000', + 'Should reflect HF update changes', + ) + st.equal( + c.param('gasPrices', 'netSstoreNoopGas', 'constantinople'), + 200, + 'Should return updated sstore gas prices for constantinople', + ) st.end() }) - t.test('Access by block number, paramByBlock()', function (st) { - let c = new Common('mainnet', 'byzantium') + t.test('Access by block number, paramByBlock()', function(st: tape.Test) { + const c = new Common('mainnet', 'byzantium') - st.equal(c.paramByBlock('pow', 'minerReward', 4370000), '3000000000000000000', 'Should correctly translate block numbers into HF states (updated value)') - st.equal(c.paramByBlock('pow', 'minerReward', 4369999), '5000000000000000000', 'Should correctly translate block numbers into HF states (original value)') + st.equal( + c.paramByBlock('pow', 'minerReward', 4370000), + '3000000000000000000', + 'Should correctly translate block numbers into HF states (updated value)', + ) + st.equal( + c.paramByBlock('pow', 'minerReward', 4369999), + '5000000000000000000', + 'Should correctly translate block numbers into HF states (original value)', + ) st.end() }) From f3e235f2255e83e65076e9fe136452ecb59205e1 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Tue, 8 Jan 2019 13:46:56 +0100 Subject: [PATCH 9/9] Regenerated docs with TSDoc, updated README --- CHANGELOG.md | 67 ++-- README.md | 99 ++--- docs/README.md | 15 + docs/classes/common.md | 566 +++++++++++++++++++++++++++ docs/index.md | 310 --------------- docs/interfaces/chainstype.md | 35 ++ docs/interfaces/genesisstatestype.md | 35 ++ docs/interfaces/hardforkoptions.md | 42 ++ 8 files changed, 780 insertions(+), 389 deletions(-) create mode 100644 docs/README.md create mode 100644 docs/classes/common.md delete mode 100644 docs/index.md create mode 100644 docs/interfaces/chainstype.md create mode 100644 docs/interfaces/genesisstatestype.md create mode 100644 docs/interfaces/hardforkoptions.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 798d71f..0341a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,81 +1,88 @@ # Changelog + All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -(modification: no type change headlines) and this project adheres to +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +(modification: no type change headlines) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - ## [0.6.1] - 2018-11-28 -- Experimental support for the [Goerli](https://github.com/goerli/testnet) cross-client ``PoA`` testnet (``chains/goerli.json``), see PR [#31](https://github.com/ethereumjs/ethereumjs-common/pull/31) -- Unified hex-prefixing (so always prefixing with ``0x``) of account addresses in genesis files (fixes an issue with state root computation on other libraries), see PR [#32](https://github.com/ethereumjs/ethereumjs-common/issues/32) + +- Experimental support for the [Goerli](https://github.com/goerli/testnet) cross-client `PoA` testnet (`chains/goerli.json`), see PR [#31](https://github.com/ethereumjs/ethereumjs-common/pull/31) +- Unified hex-prefixing (so always prefixing with `0x`) of account addresses in genesis files (fixes an issue with state root computation on other libraries), see PR [#32](https://github.com/ethereumjs/ethereumjs-common/issues/32) [0.6.1]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.6.0...v0.6.1 ## [0.6.0] - 2018-10-11 -Parameter support for the ``Constantinople`` hardfork (see ``hardforks/constantinople.json``): -- Added ``SSTORE`` gas/refund prices (``EIP-1283``), PR [#27](https://github.com/ethereumjs/ethereumjs-common/pull/27) -- Added Block Reward Adjustment (``EIP-1234``), PR [#26](https://github.com/ethereumjs/ethereumjs-common/pull/26) + +Parameter support for the `Constantinople` hardfork (see `hardforks/constantinople.json`): + +- Added `SSTORE` gas/refund prices (`EIP-1283`), PR [#27](https://github.com/ethereumjs/ethereumjs-common/pull/27) +- Added Block Reward Adjustment (`EIP-1234`), PR [#26](https://github.com/ethereumjs/ethereumjs-common/pull/26) [0.6.0]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.5.0...v0.6.0 ## [0.5.0] - 2018-08-27 -- Introduces **support for private chains** by allowing to pass a custom dictionary as the ``chain`` parameter - in the constructor or the ``setChain()`` method as an alternative to just passing one of the predefined - ``chain`` ``String`` names (e.g. ``mainnet``, ``ropsten``), PR [#24](https://github.com/ethereumjs/ethereumjs-common/pull/24) + +- Introduces **support for private chains** by allowing to pass a custom dictionary as the `chain` parameter + in the constructor or the `setChain()` method as an alternative to just passing one of the predefined + `chain` `String` names (e.g. `mainnet`, `ropsten`), PR [#24](https://github.com/ethereumjs/ethereumjs-common/pull/24) [0.5.0]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.4.1...v0.5.0 ## [0.4.1] - 2018-08-13 -- Added ``timestamp`` field to genesis definitions in chain files, set for ``Rinkeby`` and ``null`` for other chains, PR [#21](https://github.com/ethereumjs/ethereumjs-common/pull/21) -- Updated ``Ropsten`` bootstrap nodes, PR [#20](https://github.com/ethereumjs/ethereumjs-common/pull/20) + +- Added `timestamp` field to genesis definitions in chain files, set for `Rinkeby` and `null` for other chains, PR [#21](https://github.com/ethereumjs/ethereumjs-common/pull/21) +- Updated `Ropsten` bootstrap nodes, PR [#20](https://github.com/ethereumjs/ethereumjs-common/pull/20) [0.4.1]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.4.0...v0.4.1 ## [0.4.0] - 2018-06-20 -- Remove leftover ...Gas postfix for some gas prices (e.g. ``ecAddGas`` -> ``ecAdd``) to + +- Remove leftover ...Gas postfix for some gas prices (e.g. `ecAddGas` -> `ecAdd`) to be consistent with overall gas price naming [0.4.0]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.3.1...v0.4.0 ## [0.3.1] - 2018-05-28 -- Added two alias functions ``activeOnBlock()`` and ``gteHardfork()`` when hardfork is set for convenience, PR [#15](https://github.com/ethereumjs/ethereumjs-common/pull/15) -- Added option to dynamically choose genesis state (see ``README``), PR [#15](https://github.com/ethereumjs/ethereumjs-common/pull/15) + +- Added two alias functions `activeOnBlock()` and `gteHardfork()` when hardfork is set for convenience, PR [#15](https://github.com/ethereumjs/ethereumjs-common/pull/15) +- Added option to dynamically choose genesis state (see `README`), PR [#15](https://github.com/ethereumjs/ethereumjs-common/pull/15) [0.3.1]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.3.0...v0.3.1 ## [0.3.0] - 2018-05-25 -- Allow functions like ``hardforkIsActiveOnBlock()`` - where hardfork is provided as param - also to be run on hardfork set for greater flexibility/comfort, PR [#13](https://github.com/ethereumjs/ethereumjs-common/pull/13) -- New ``hardforkGteHardfork()`` method for HF order comparisons, PR [#13](https://github.com/ethereumjs/ethereumjs-common/pull/13) + +- Allow functions like `hardforkIsActiveOnBlock()` - where hardfork is provided as param - also to be run on hardfork set for greater flexibility/comfort, PR [#13](https://github.com/ethereumjs/ethereumjs-common/pull/13) +- New `hardforkGteHardfork()` method for HF order comparisons, PR [#13](https://github.com/ethereumjs/ethereumjs-common/pull/13) [0.3.0]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.2.0...v0.3.0 ## [0.2.0] - 2018-05-14 -- New optional initialization parameter ``allowedHardforks``, this allows for cleaner client -library implementations by preventing undefined behaviour, PR [#10](https://github.com/ethereumjs/ethereumjs-common/pull/10) -- Added ``activeHardfork()`` function to get latest active HF for chain or block, PR [#11](https://github.com/ethereumjs/ethereumjs-common/pull/11) + +- New optional initialization parameter `allowedHardforks`, this allows for cleaner client + library implementations by preventing undefined behaviour, PR [#10](https://github.com/ethereumjs/ethereumjs-common/pull/10) +- Added `activeHardfork()` function to get latest active HF for chain or block, PR [#11](https://github.com/ethereumjs/ethereumjs-common/pull/11) [0.2.0]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.1.1...v0.2.0 ## [0.1.1] - 2018-05-09 + - Remove dynamic require to prevent browserify issue, PR [#8](https://github.com/ethereumjs/ethereumjs-common/pull/8) [0.1.1]: https://github.com/ethereumjs/ethereumjs-common/compare/v0.1.0...v0.1.1 ## [0.1.0] - 2018-05-09 + - Initial version, this library succeeds the [ethereum/common](https://github.com/ethereumjs/common/issues/12) library, being more future-proof through a better structured design - + Features: + - Easy chain-/HF-based parameter access -- No parameter changes on library updates (``c.param('gasPrices', 'ecAddGas', 'byzantium')`` will always return the same value) -- Ease experimentation/research by allowing to include future HF parameters (already included as draft: ``constantinople`` and ``hybridCasper``) without breaking current installations -- Improved structure for parameter access (mainly through topics like ``gasPrices``, ``pow``, ``sharding``) for better readability/developer overview +- No parameter changes on library updates (`c.param('gasPrices', 'ecAddGas', 'byzantium')` will always return the same value) +- Ease experimentation/research by allowing to include future HF parameters (already included as draft: `constantinople` and `hybridCasper`) without breaking current installations +- Improved structure for parameter access (mainly through topics like `gasPrices`, `pow`, `sharding`) for better readability/developer overview - See [README](https://github.com/ethereumjs/ethereumjs-common) and [API Docs](https://github.com/ethereumjs/ethereumjs-common/blob/master/docs/index.md) for a more in-depth feature overview and usage instructions [0.1.0]: https://github.com/ethereumjs/ethereumjs-common/compare/6d0df89...v0.1.0 - - - - - diff --git a/README.md b/README.md index 2fdd1c2..3a570fa 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,20 @@ [![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs.svg?style=flat-square)]() # ETHEREUMJS-COMMON + Resources common to all Ethereum implementations Succeeds the old [ethereum/common](https://github.com/ethereumjs/common/) library. # INSTALL + `npm install ethereumjs-common` # USAGE -All parameters can be accessed through the ``Common`` class which can be required through the -main package and instantiated either with just the ``chain`` (e.g. 'mainnet') or the ``chain`` -together with a specific ``hardfork`` provided. +All parameters can be accessed through the `Common` class which can be required through the +main package and instantiated either with just the `chain` (e.g. 'mainnet') or the `chain` +together with a specific `hardfork` provided. Here are some simple usage examples: @@ -39,8 +41,8 @@ c.genesis().hash // 0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1 c.bootstrapNodes() // Array with current nodes ``` -It is encouraged to also explicitly set the ``supportedHardforks`` if the initializing library -only supports a certain range of ``hardforks``: +It is encouraged to also explicitly set the `supportedHardforks` if the initializing library +only supports a certain range of `hardforks`: ```javascript let c = new Common('ropsten', null, ['byzantium', 'constantinople']) @@ -53,83 +55,81 @@ like this prevents unpredicted behaviour. See the API documentation for a full list of functions for accessing specific chain and depending hardfork parameters. There are also additional helper functions like -``paramByBlock (topic, name, blockNumber)`` or ``hardforkIsActiveOnBlock (hardfork, blockNumber)`` -to ease ``blockNumber`` based access to parameters. - -- [API Docs](./docs/index.md) +`paramByBlock (topic, name, blockNumber)` or `hardforkIsActiveOnBlock (hardfork, blockNumber)` +to ease `blockNumber` based access to parameters. +- [API Docs](./docs/Readme.md) # Hardfork Params There are currently parameter changes by the following past and future hardfork by the library supported: -- ``chainstart`` -- ``homestead`` -- ``dao`` -- ``tangerineWhistle`` -- ``spuriousDragon`` -- ``byzantium`` -- ``constantinople`` - - -For hardfork-specific parameter access with the ``param()`` and ``paramByBlock()`` functions -you can use the following ``topics``: - -- ``gasConfig`` -- ``gasPrices`` -- ``vm`` -- ``pow`` -- ``casper`` -- ``sharding`` - -See one of the hardfork files like ``byzantium.json`` in the ``hardforks`` directory -for an overview. For consistency, the chain start (``chainstart``) is considered an own +- `chainstart` +- `homestead` +- `dao` +- `tangerineWhistle` +- `spuriousDragon` +- `byzantium` +- `constantinople` + +For hardfork-specific parameter access with the `param()` and `paramByBlock()` functions +you can use the following `topics`: + +- `gasConfig` +- `gasPrices` +- `vm` +- `pow` +- `casper` +- `sharding` + +See one of the hardfork files like `byzantium.json` in the `hardforks` directory +for an overview. For consistency, the chain start (`chainstart`) is considered an own hardfork. -The hardfork-specific json files only contain the deltas from ``chainstart`` and +The hardfork-specific json files only contain the deltas from `chainstart` and shouldn't be accessed directly until you have a specific reason for it. -Note: The list of ``gasPrices`` and gas price changes on hardforks is consistent +Note: The list of `gasPrices` and gas price changes on hardforks is consistent but not complete, so there are currently gas price values missing (PRs welcome!). # Chain Params Supported chains: -- ``mainnet`` -- ``ropsten`` -- ``rinkeby`` -- ``kovan`` -- ``goerli`` (EXPERIMENTAL) +- `mainnet` +- `ropsten` +- `rinkeby` +- `kovan` +- `goerli` (EXPERIMENTAL) - Private/custom chain parameters The following chain-specific parameters are provided: -- ``name`` -- ``chainId`` -- ``networkId`` -- ``genesis`` block header values -- ``hardforks`` block numbers -- ``bootstrapNodes`` list +- `name` +- `chainId` +- `networkId` +- `genesis` block header values +- `hardforks` block numbers +- `bootstrapNodes` list To get an overview of the different parameters have a look at one of the chain-specifc -files like ``mainnet.json`` in the ``chains`` directory. +files like `mainnet.json` in the `chains` directory. If you want to set up a common instance with parameters for a **private/custom chain** you can pass a dictionary - conforming to the parameter format described above - with your custom values in -the constructor or the ``setChain()`` method for the ``chain`` parameter. +the constructor or the `setChain()` method for the `chain` parameter. # Bootstrap Nodes -There is no separate config file for bootstrap nodes like in the old ``ethereum-common`` library. -Instead use the ``common.bootstrapNodes()`` function to get nodes for a specific chain/network. +There is no separate config file for bootstrap nodes like in the old `ethereum-common` library. +Instead use the `common.bootstrapNodes()` function to get nodes for a specific chain/network. # Genesis States -Network-specific genesis files are located in the ``genesisStates`` folder. +Network-specific genesis files are located in the `genesisStates` folder. -Due to the large file sizes genesis states are not directly included in the ``index.js`` file +Due to the large file sizes genesis states are not directly included in the `index.js` file but have to be accessed directly, e.g.: ```javascript @@ -145,4 +145,5 @@ const mainnetGenesisState = genesisStates[genesisStates['names'][1]] // alternat ``` # LICENSE + [MIT](https://opensource.org/licenses/MIT) diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..c97c225 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,15 @@ +# ethereumjs-common + +## Index + +### Classes + +- [Common](classes/common.md) + +### Interfaces + +- [chainsType](interfaces/chainstype.md) +- [genesisStatesType](interfaces/genesisstatestype.md) +- [hardforkOptions](interfaces/hardforkoptions.md) + +--- diff --git a/docs/classes/common.md b/docs/classes/common.md new file mode 100644 index 0000000..399f292 --- /dev/null +++ b/docs/classes/common.md @@ -0,0 +1,566 @@ +[ethereumjs-common](../README.md) > [Common](../classes/common.md) + +# Class: Common + +Common class to access chain and hardfork parameters + +## Hierarchy + +**Common** + +## Index + +### Constructors + +- [constructor](common.md#constructor) + +### Methods + +- [\_chooseHardfork](common.md#_choosehardfork) +- [\_getHardfork](common.md#_gethardfork) +- [\_isSupportedHardfork](common.md#_issupportedhardfork) +- [activeHardfork](common.md#activehardfork) +- [activeHardforks](common.md#activehardforks) +- [activeOnBlock](common.md#activeonblock) +- [bootstrapNodes](common.md#bootstrapnodes) +- [chainId](common.md#chainid) +- [chainName](common.md#chainname) +- [consensus](common.md#consensus) +- [finality](common.md#finality) +- [genesis](common.md#genesis) +- [gteHardfork](common.md#gtehardfork) +- [hardfork](common.md#hardfork) +- [hardforkBlock](common.md#hardforkblock) +- [hardforkGteHardfork](common.md#hardforkgtehardfork) +- [hardforkIsActiveOnBlock](common.md#hardforkisactiveonblock) +- [hardforkIsActiveOnChain](common.md#hardforkisactiveonchain) +- [hardforks](common.md#hardforks) +- [isHardforkBlock](common.md#ishardforkblock) +- [networkId](common.md#networkid) +- [param](common.md#param) +- [paramByBlock](common.md#parambyblock) +- [setChain](common.md#setchain) +- [setHardfork](common.md#sethardfork) + +--- + +## Constructors + + + +### constructor + +⊕ **new Common**(chain: _`string` | `number` | `object`_, hardfork?: _`string` | `null`_, supportedHardforks?: _`Array`<`string`>_): [Common](common.md) + +_Defined in [index.ts:17](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L17)_ + +_**constructor**_: + +**Parameters:** + +| Name | Type | Description | +| ----------------------------- | ----------------- | --------------------------------------------------------- | +| chain | `string` | `number` | `object` | String ('mainnet') or Number (1) chain | +| `Optional` hardfork | `string` | `null` | String identifier ('byzantium') for hardfork (optional) | +| `Optional` supportedHardforks | `Array`<`string`> | Limit parameter returns to the given hardforks (optional) | + +**Returns:** [Common](common.md) + +--- + +## Methods + + + +### \_chooseHardfork + +▸ **\_chooseHardfork**(hardfork?: _`string` | `null`_, onlySupported?: _`undefined` | `false` | `true`_): `string` + +_Defined in [index.ts:96](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L96)_ + +Internal helper function to choose between hardfork set and hardfork provided as param + +**Parameters:** + +| Name | Type | Description | +| ------------------------ | ----------- | ----------- | +| `Optional` hardfork | `string` | `null` | Hardfork given to function as a parameter | +| `Optional` onlySupported | `undefined` | `false` | `true` | + +**Returns:** `string` +Hardfork chosen to be used + +--- + + + +### \_getHardfork + +▸ **\_getHardfork**(hardfork: _`string`_): `any` + +_Defined in [index.ts:115](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L115)_ + +Internal helper function, returns the params for the given hardfork for the chain set + +**Parameters:** + +| Name | Type | Description | +| -------- | -------- | ------------- | +| hardfork | `string` | Hardfork name | + +**Returns:** `any` +Dictionary with hardfork params + +--- + + + +### \_isSupportedHardfork + +▸ **\_isSupportedHardfork**(hardfork: _`string` | `null`_): `boolean` + +_Defined in [index.ts:128](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L128)_ + +Internal helper function to check if a hardfork is set to be supported by the library + +**Parameters:** + +| Name | Type | Description | +| -------- | -------- | ----------- | +| hardfork | `string` | `null` | Hardfork name | + +**Returns:** `boolean` +True if hardfork is supported + +--- + + + +### activeHardfork + +▸ **activeHardfork**(blockNumber?: _`number` | `null`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `string` + +_Defined in [index.ts:292](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L292)_ + +Returns the latest active hardfork name for chain or block or throws if unavailable + +**Parameters:** + +| Name | Type | Description | +| ---------------------- | --------------------------------------------------- | ------------------------------------ | +| `Optional` blockNumber | `number` | `null` | up to block if provided, otherwise for the whole chain | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options (onlyActive unused) | + +**Returns:** `string` +Hardfork name + +--- + + + +### activeHardforks + +▸ **activeHardforks**(blockNumber?: _`number` | `null`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `Array`<`any`> + +_Defined in [index.ts:272](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L272)_ + +Returns the active hardfork switches for the current chain + +**Parameters:** + +| Name | Type | Description | +| ---------------------- | --------------------------------------------------- | ------------------------------------ | +| `Optional` blockNumber | `number` | `null` | up to block if provided, otherwise for the whole chain | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options (onlyActive unused) | + +**Returns:** `Array`<`any`> +Array with hardfork arrays + +--- + + + +### activeOnBlock + +▸ **activeOnBlock**(blockNumber: _`number`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `boolean` + +_Defined in [index.ts:202](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L202)_ + +Alias to hardforkIsActiveOnBlock when hardfork is set + +**Parameters:** + +| Name | Type | Description | +| --------------- | --------------------------------------------------- | ------------------------------------ | +| blockNumber | `number` | \- | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options (onlyActive unused) | + +**Returns:** `boolean` +True if HF is active on block number + +--- + + + +### bootstrapNodes + +▸ **bootstrapNodes**(): `any` + +_Defined in [index.ts:367](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L367)_ + +Returns bootstrap nodes for the current chain + +**Returns:** `any` +Dict with bootstrap nodes + +--- + + + +### chainId + +▸ **chainId**(): `number` + +_Defined in [index.ts:383](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L383)_ + +Returns the Id of current chain + +**Returns:** `number` +chain Id + +--- + + + +### chainName + +▸ **chainName**(): `string` + +_Defined in [index.ts:391](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L391)_ + +Returns the name of current chain + +**Returns:** `string` +chain name (lower case) + +--- + + + +### consensus + +▸ **consensus**(hardfork?: _`undefined` | `string`_): `string` + +_Defined in [index.ts:332](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L332)_ + +Provide the consensus type for the hardfork set or provided as param + +**Parameters:** + +| Name | Type | Description | +| ------------------- | ----------- | ----------- | +| `Optional` hardfork | `undefined` | `string` | Hardfork name, optional if hardfork set | + +**Returns:** `string` +Consensus type (e.g. 'pow', 'poa') + +--- + + + +### finality + +▸ **finality**(hardfork?: _`undefined` | `string`_): `string` + +_Defined in [index.ts:342](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L342)_ + +Provide the finality type for the hardfork set or provided as param + +**Parameters:** + +| Name | Type | Description | +| ------------------- | ----------- | ----------- | +| `Optional` hardfork | `undefined` | `string` | Hardfork name, optional if hardfork set | + +**Returns:** `string` +Finality type (e.g. 'pos', null of no finality) + +--- + + + +### genesis + +▸ **genesis**(): `any` + +_Defined in [index.ts:351](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L351)_ + +Returns the Genesis parameters of current chain + +**Returns:** `any` +Genesis dictionary + +--- + + + +### gteHardfork + +▸ **gteHardfork**(hardfork: _`string`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `boolean` + +_Defined in [index.ts:246](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L246)_ + +Alias to hardforkGteHardfork when hardfork is set + +**Parameters:** + +| Name | Type | Description | +| --------------- | --------------------------------------------------- | ---------------- | +| hardfork | `string` | Hardfork name | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options | + +**Returns:** `boolean` +True if hardfork set is greater than hardfork provided + +--- + + + +### hardfork + +▸ **hardfork**(): `string` | `null` + +_Defined in [index.ts:375](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L375)_ + +Returns the hardfork set + +**Returns:** `string` | `null` +Hardfork name + +--- + + + +### hardforkBlock + +▸ **hardforkBlock**(hardfork?: _`undefined` | `string`_): `number` + +_Defined in [index.ts:307](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L307)_ + +Returns the hardfork change block for hardfork provided or set + +**Parameters:** + +| Name | Type | Description | +| ------------------- | ----------- | ----------- | +| `Optional` hardfork | `undefined` | `string` | Hardfork name, optional if HF set | + +**Returns:** `number` +Block number + +--- + + + +### hardforkGteHardfork + +▸ **hardforkGteHardfork**(hardfork1: _`string` | `null`_, hardfork2: _`string`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `boolean` + +_Defined in [index.ts:213](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L213)_ + +Sequence based check if given or set HF1 is greater than or equal HF2 + +**Parameters:** + +| Name | Type | Description | +| --------------- | --------------------------------------------------- | ---------------- | +| hardfork1 | `string` | `null` | Hardfork name or null (if set) | +| hardfork2 | `string` | Hardfork name | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options | + +**Returns:** `boolean` +True if HF1 gte HF2 + +--- + + + +### hardforkIsActiveOnBlock + +▸ **hardforkIsActiveOnBlock**(hardfork: _`string` | `null`_, blockNumber: _`number`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `boolean` + +_Defined in [index.ts:183](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L183)_ + +Checks if set or provided hardfork is active on block number + +**Parameters:** + +| Name | Type | Description | +| --------------- | --------------------------------------------------- | ------------------------------------ | +| hardfork | `string` | `null` | Hardfork name or null (for HF set) | +| blockNumber | `number` | \- | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options (onlyActive unused) | + +**Returns:** `boolean` +True if HF is active on block number + +--- + + + +### hardforkIsActiveOnChain + +▸ **hardforkIsActiveOnChain**(hardfork?: _`string` | `null`_, opts?: _[hardforkOptions](../interfaces/hardforkoptions.md)_): `boolean` + +_Defined in [index.ts:256](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L256)_ + +Checks if given or set hardfork is active on the chain + +**Parameters:** + +| Name | Type | Description | +| ------------------- | --------------------------------------------------- | ------------------------------------ | +| `Optional` hardfork | `string` | `null` | Hardfork name, optional if HF set | +| `Optional` opts | [hardforkOptions](../interfaces/hardforkoptions.md) | Hardfork options (onlyActive unused) | + +**Returns:** `boolean` +True if hardfork is active on the chain + +--- + + + +### hardforks + +▸ **hardforks**(): `any` + +_Defined in [index.ts:359](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L359)_ + +Returns the hardforks for current chain + +**Returns:** `any` +Array with arrays of hardforks + +--- + + + +### isHardforkBlock + +▸ **isHardforkBlock**(blockNumber: _`number`_, hardfork?: _`undefined` | `string`_): `boolean` + +_Defined in [index.ts:318](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L318)_ + +True if block number provided is the hardfork (given or set) change block of the current chain + +**Parameters:** + +| Name | Type | Description | +| ------------------- | ----------- | ---------------------------- | +| blockNumber | `number` | Number of the block to check | +| `Optional` hardfork | `undefined` | `string` | Hardfork name, optional if HF set | + +**Returns:** `boolean` +True if blockNumber is HF block + +--- + + + +### networkId + +▸ **networkId**(): `number` + +_Defined in [index.ts:399](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L399)_ + +Returns the Id of current network + +**Returns:** `number` +network Id + +--- + + + +### param + +▸ **param**(topic: _`string`_, name: _`string`_, hardfork?: _`undefined` | `string`_): `any` + +_Defined in [index.ts:145](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L145)_ + +Returns the parameter corresponding to a hardfork + +**Parameters:** + +| Name | Type | Description | +| ------------------- | ----------- | ----------------------------------------------------------------------------- | +| topic | `string` | Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') | +| name | `string` | Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) | +| `Optional` hardfork | `undefined` | `string` | Hardfork name, optional if hardfork set | + +**Returns:** `any` + +--- + + + +### paramByBlock + +▸ **paramByBlock**(topic: _`string`_, name: _`string`_, blockNumber: _`number`_): `any` + +_Defined in [index.ts:170](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L170)_ + +Returns a parameter for the hardfork active on block number + +**Parameters:** + +| Name | Type | Description | +| ----------- | -------- | --------------- | +| topic | `string` | Parameter topic | +| name | `string` | Parameter name | +| blockNumber | `number` | Block number | + +**Returns:** `any` + +--- + + + +### setChain + +▸ **setChain**(chain: _`string` | `number` | `object`_): `any` + +_Defined in [index.ts:44](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L44)_ + +Sets the chain + +**Parameters:** + +| Name | Type | Description | +| ----- | -------- | ----------- | +| chain | `string` | `number` | `object` | String ('mainnet') or Number (1) chain representation. Or, a Dictionary of chain parameters for a private network. | + +**Returns:** `any` +The dictionary with parameters set as chain + +--- + + + +### setHardfork + +▸ **setHardfork**(hardfork: _`string` | `null`_): `void` + +_Defined in [index.ts:75](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L75)_ + +Sets the hardfork to get params for + +**Parameters:** + +| Name | Type | Description | +| -------- | -------- | ----------- | +| hardfork | `string` | `null` | String identifier ('byzantium') | + +**Returns:** `void` + +--- diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 2d970ce..0000000 --- a/docs/index.md +++ /dev/null @@ -1,310 +0,0 @@ - - -### Table of Contents - -- [Common][1] - - [setChain][2] - - [setHardfork][3] - - [\_chooseHardfork][4] - - [\_getHardfork][5] - - [\_isSupportedHardfork][6] - - [param][7] - - [paramByBlock][8] - - [hardforkIsActiveOnBlock][9] - - [activeOnBlock][10] - - [hardforkGteHardfork][11] - - [gteHardfork][12] - - [hardforkIsActiveOnChain][13] - - [activeHardforks][14] - - [activeHardfork][15] - - [hardforkBlock][16] - - [isHardforkBlock][17] - - [consensus][18] - - [finality][19] - - [genesis][20] - - [hardforks][21] - - [bootstrapNodes][22] - - [hardfork][23] - - [chainId][24] - - [chainName][25] - - [networkId][26] - -## Common - -Common class to access chain and hardfork parameters - -**Parameters** - -- `chain` **([String][27] \| [Number][28] | Dictionary)** String ('mainnet') or Number (1) chain -- `hardfork` **[String][27]** String identifier ('byzantium') for hardfork (optional) -- `supportedHardforks` **[Array][29]** Limit parameter returns to the given hardforks (optional) - -### setChain - -Sets the chain - -**Parameters** - -- `chain` **([String][27] \| [Number][28] | Dictionary)** String ('mainnet') or Number (1) chain - representation. Or, a Dictionary of chain parameters for a private network. - -### setHardfork - -Sets the hardfork to get params for - -**Parameters** - -- `hardfork` **[String][27]** String identifier ('byzantium') - -### \_chooseHardfork - -Internal helper function to choose between hardfork set and hardfork provided as param - -**Parameters** - -- `hardfork` **[String][27]** Hardfork given to function as a parameter -- `onlySupported` - -Returns **[String][27]** Hardfork chosen to be used - -### \_getHardfork - -Internal helper function, returns the params for the given hardfork for the chain set - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name - -Returns **Dictionary** - -### \_isSupportedHardfork - -Internal helper function to check if a hardfork is set to be supported by the library - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name - -Returns **[Boolean][30]** True if hardfork is supported - -### param - -Returns the parameter corresponding to a hardfork - -**Parameters** - -- `topic` **[String][27]** Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') -- `name` **[String][27]** Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) -- `hardfork` **[String][27]** Hardfork name, optional if hardfork set - -### paramByBlock - -Returns a parameter for the hardfork active on block number - -**Parameters** - -- `topic` **[String][27]** Parameter topic -- `name` **[String][27]** Parameter name -- `blockNumber` **[Number][28]** Block number - -### hardforkIsActiveOnBlock - -Checks if set or provided hardfork is active on block number - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name or null (for HF set) -- `blockNumber` **[Number][28]** -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) - -Returns **[Boolean][30]** - -### activeOnBlock - -Alias to hardforkIsActiveOnBlock when hardfork is set - -**Parameters** - -- `blockNumber` **[Number][28]** -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) - -Returns **[Boolean][30]** - -### hardforkGteHardfork - -Sequence based check if given or set HF1 is greater than or equal HF2 - -**Parameters** - -- `hardfork1` **[String][27]** Hardfork name or null (if set) -- `hardfork2` **[String][27]** Hardfork name -- `opts` **[Array][29]** - - `opts.onlyActive` **Array.Boolean** optional, only active HFs (default: false) - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) - -Returns **[Boolean][30]** - -### gteHardfork - -Alias to hardforkGteHardfork when hardfork is set - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name -- `opts` **[Array][29]** - - `opts.onlyActive` **Array.Boolean** optional, only active HFs (default: false) - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) - -Returns **[Boolean][30]** - -### hardforkIsActiveOnChain - -Checks if given or set hardfork is active on the chain - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name, optional if HF set -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false) - -Returns **[Boolean][30]** - -### activeHardforks - -Returns the active hardfork switches for the current chain - -**Parameters** - -- `blockNumber` **[Number][28]** up to block if provided, otherwise for the whole chain -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false) - -Returns **[Array][29]** Array with hardfork arrays - -### activeHardfork - -Returns the latest active hardfork name for chain or block or throws if unavailable - -**Parameters** - -- `blockNumber` **[Number][28]** up to block if provided, otherwise for the whole chain -- `opts` **[Array][29]** - - `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false) - -Returns **[String][27]** Hardfork name - -### hardforkBlock - -Returns the hardfork change block for hardfork provided or set - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name, optional if HF set - -Returns **[Number][28]** Block number - -### isHardforkBlock - -True if block number provided is the hardfork (given or set) change block of the current chain - -**Parameters** - -- `blockNumber` **[Number][28]** Number of the block to check -- `hardfork` **[String][27]** Hardfork name, optional if HF set - -Returns **[Boolean][30]** - -### consensus - -Provide the consensus type for the hardfork set or provided as param - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name, optional if hardfork set - -Returns **[String][27]** Consensus type (e.g. 'pow', 'poa') - -### finality - -Provide the finality type for the hardfork set or provided as param - -**Parameters** - -- `hardfork` **[String][27]** Hardfork name, optional if hardfork set - -Returns **[String][27]** Finality type (e.g. 'pos', null of no finality) - -### genesis - -Returns the Genesis parameters of current chain - -Returns **Dictionary** Genesis dict - -### hardforks - -Returns the hardforks for current chain - -Returns **[Array][29]** Array with arrays of hardforks - -### bootstrapNodes - -Returns bootstrap nodes for the current chain - -Returns **Dictionary** Dict with bootstrap nodes - -### hardfork - -Returns the hardfork set - -Returns **[String][27]** Hardfork name - -### chainId - -Returns the Id of current chain - -Returns **[Number][28]** chain Id - -### chainName - -Returns the name of current chain - -Returns **[String][27]** chain name (lower case) - -### networkId - -Returns the Id of current network - -Returns **[Number][28]** network Id - -[1]: #common -[2]: #setchain -[3]: #sethardfork -[4]: #_choosehardfork -[5]: #_gethardfork -[6]: #_issupportedhardfork -[7]: #param -[8]: #parambyblock -[9]: #hardforkisactiveonblock -[10]: #activeonblock -[11]: #hardforkgtehardfork -[12]: #gtehardfork -[13]: #hardforkisactiveonchain -[14]: #activehardforks -[15]: #activehardfork -[16]: #hardforkblock -[17]: #ishardforkblock -[18]: #consensus -[19]: #finality -[20]: #genesis -[21]: #hardforks -[22]: #bootstrapnodes -[23]: #hardfork -[24]: #chainid -[25]: #chainname -[26]: #networkid -[27]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number -[29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array -[30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean diff --git a/docs/interfaces/chainstype.md b/docs/interfaces/chainstype.md new file mode 100644 index 0000000..c8db0db --- /dev/null +++ b/docs/interfaces/chainstype.md @@ -0,0 +1,35 @@ +[ethereumjs-common](../README.md) > [chainsType](../interfaces/chainstype.md) + +# Interface: chainsType + +## Hierarchy + +**chainsType** + +## Indexable + +\[key: `string`\]: `__type` + +## Index + +### Properties + +- [names](chainstype.md#names) + +--- + +## Properties + + + +### names + +**● names**: _`object`_ + +_Defined in [types.ts:9](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/types.ts#L9)_ + +#### Type declaration + +[key: `string`]: `string` + +--- diff --git a/docs/interfaces/genesisstatestype.md b/docs/interfaces/genesisstatestype.md new file mode 100644 index 0000000..f07da85 --- /dev/null +++ b/docs/interfaces/genesisstatestype.md @@ -0,0 +1,35 @@ +[ethereumjs-common](../README.md) > [genesisStatesType](../interfaces/genesisstatestype.md) + +# Interface: genesisStatesType + +## Hierarchy + +**genesisStatesType** + +## Indexable + +\[key: `string`\]: `__type` + +## Index + +### Properties + +- [names](genesisstatestype.md#names) + +--- + +## Properties + + + +### names + +**● names**: _`object`_ + +_Defined in [types.ts:2](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/types.ts#L2)_ + +#### Type declaration + +[key: `string`]: `string` + +--- diff --git a/docs/interfaces/hardforkoptions.md b/docs/interfaces/hardforkoptions.md new file mode 100644 index 0000000..6de892f --- /dev/null +++ b/docs/interfaces/hardforkoptions.md @@ -0,0 +1,42 @@ +[ethereumjs-common](../README.md) > [hardforkOptions](../interfaces/hardforkoptions.md) + +# Interface: hardforkOptions + +## Hierarchy + +**hardforkOptions** + +## Index + +### Properties + +- [onlyActive](hardforkoptions.md#onlyactive) +- [onlySupported](hardforkoptions.md#onlysupported) + +--- + +## Properties + + + +### `` onlyActive + +**● onlyActive**: _`undefined` | `false` | `true`_ + +_Defined in [index.ts:8](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L8)_ + +optional, only active HFs (default: false) + +--- + + + +### `` onlySupported + +**● onlySupported**: _`undefined` | `false` | `true`_ + +_Defined in [index.ts:6](https://github.com/ethereumjs/ethereumjs-common/blob/12f6f69/src/index.ts#L6)_ + +optional, only allow supported HFs (default: false) + +---