Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct web3-eth2- packages types #3865

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
54da486
Wrap function params in object
spacesailor24 Jan 19, 2021
254ef3b
Wrap function params in object
spacesailor24 Jan 19, 2021
78f4a57
Export needed typings in web3-eth2-core. Export class definition in w…
spacesailor24 Jan 19, 2021
d4ed3ac
Replace interface type with class
spacesailor24 Jan 19, 2021
77cd2e3
Remove addBlockExplorerApi from class type
spacesailor24 Jan 19, 2021
dc4fd22
linter errors. Add ETH2Core class export
spacesailor24 Jan 19, 2021
dc95602
Linter errors
spacesailor24 Jan 19, 2021
d8456a9
Merge branch '1.x' into wyatt/beaconchain-types-fix
spacesailor24 Jan 20, 2021
4d52138
Merge branch '1.x' into wyatt/beaconchain-types-fix
spacesailor24 Jan 21, 2021
9cf8675
Update changelog
spacesailor24 Jan 21, 2021
acbe4dd
Merge conflict
spacesailor24 Jan 21, 2021
5b2bdd7
Replace index.d.ts files with types.ts
spacesailor24 Jan 21, 2021
faa53e2
Update type declaration files, update dependencies for web3-eth2-core
spacesailor24 Jan 21, 2021
6792884
remove dtslint commands
spacesailor24 Jan 21, 2021
b877123
Add dtslint npm command - I think lerna needs it to report a success
spacesailor24 Jan 21, 2021
8665966
Remove dtslint command
spacesailor24 Jan 21, 2021
b14978c
dtslint debug
spacesailor24 Jan 21, 2021
3ae1f54
dtslint debug
spacesailor24 Jan 21, 2021
2de2dfa
Remove dtslint from devDependencies and remove dtslint npm command
spacesailor24 Jan 22, 2021
81ae5bf
Remove dtslint with npm remove
spacesailor24 Jan 22, 2021
ef342cc
Update types file path
spacesailor24 Jan 22, 2021
77d754e
Debug
spacesailor24 Jan 22, 2021
a59690d
Debug
spacesailor24 Jan 22, 2021
6fd8762
Debug
spacesailor24 Jan 22, 2021
063b302
Debug
spacesailor24 Jan 22, 2021
7b77fd7
Merge conflicts
spacesailor24 Jan 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,14 @@ Released with 1.0.0-beta.37 code base.
- Grammar changes to inputAddressFormatter error message
- Fixed vulnerable dependencies

## [Unreleased]

## [1.3.2]

### Fixed

- Fix EIP-1193 provider subscriptions (#3864)

## [Unreleased]

## [1.3.3]

### Changed
Expand All @@ -326,7 +326,19 @@ Released with 1.0.0-beta.37 code base.
- Rename `web3-eth2-base` to `web3-eth2-core` and `web3-eth2-beacon` to `web3-eth2-beaconchain`
- Bump `ts-node` from version `^8.10.2` to `^9.0.0`
- Ran `npm audit fix` which fixed 4 vulnerabilities
- Correct `web3-eth2-beaconchain` type declarations
- Correct `web3-eth2-beaconchain` type declarations (#3859) and (#3865)
- Move interfaces `IBaseAPISchema` and `IBaseAPIMethodSchema` to `index.d.ts` for `web3-eth2-core`
- Removes `IETH2BeaconChain` interface in favor of exporting a class type: `ETH2BeaconChain`
- Remove `index.d.ts` files in favor of `types.ts` for `web3-eth2-core` and `web3-eth2-beaconchain`
- Update dependencies for `web3-eth2-core`

### Removed

- `schema.ts` from `web3-eth2-core`

### Added
- Deprecation of bzz warning

- Add `ETH2Core` class export to `index.d.ts` for `web3-eth2-core`
- Deprecation of bzz warning

## [1.3.4]
18,238 changes: 4,440 additions & 13,798 deletions packages/web3-eth2-beaconchain/package-lock.json

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions packages/web3-eth2-beaconchain/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// @ts-ignore - types not full implemented yet
import { ETH2Core } from 'web3-eth2-core'
import { ETH2Core, BaseAPISchema, ETH2BaseOpts } from 'web3-eth2-core'
import { DefaultSchema } from './schema'

import { IETH2BeaconChain } from '../types/index'
// @ts-ignore - types not full implemented yet
import { IBaseAPISchema } from 'web3-eth2-core'
// @ts-ignore - types not full implemented yet
import { ETH2BaseOpts } from 'web3-eth2-core'
import { ETH2BeaconChain as IETH2BeaconChain } from '../types'

// @ts-ignore - ETH2BeaconChain incorrectly implements interface IETH2BeaconChain
// because methods are added during runtime
export class ETH2BeaconChain extends ETH2Core implements IETH2BeaconChain {
constructor(
provider: string,
schema: IBaseAPISchema = DefaultSchema,
schema: BaseAPISchema = DefaultSchema,
opts: ETH2BaseOpts = { protectProvider: true }) {
super(provider, schema, opts)
}
Expand Down
75 changes: 17 additions & 58 deletions packages/web3-eth2-beaconchain/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,21 @@
{
"compilerOptions": {
/* Basic Options */
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
// "declarationDir": "lib" /* Output directory for generated declaration files. */
"declaration": true,
"outDir": "lib",
"strict": true,
"esModuleInterop": true,
"module": "commonjs",
"lib": ["es6"],
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true,
"allowSyntheticDefaultImports": false,
"baseUrl": ".",
"paths": {
"web3-eth2-beaconchain": ["."]
}
}
}
47 changes: 47 additions & 0 deletions packages/web3-eth2-beaconchain/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
Slot,
Root,
Genesis,
Fork,
FinalityCheckpoints,
Validator,
ValidatorResponse,
ValidatorBalance,
Epoch,
BeaconCommitteeResponse,
SignedBeaconHeaderResponse,
Attestation,
CommitteeIndex,
IndexedAttestation,
ProposerSlashing,
SignedVoluntaryExit
} from '@chainsafe/lodestar-types'

export type StateId = 'head' | 'genesis' | 'finalized' | 'justified' | Slot | Root
export type BlockId = 'head' | 'genesis' | 'finalized' | Slot | Root

export interface ETH2BeaconChain {
getGenesis(): Promise<Genesis | null>
getHashRoot(params: {stateId: StateId}): Promise<{ root: Root }>
getForkData(params: {stateId: StateId}): Promise<Fork>
getFinalityCheckpoint(params: {stateId: StateId}): Promise<FinalityCheckpoints>
getValidators(params: {stateId: StateId}): Promise<Validator[]>
getValidatorById(params: {stateId: StateId, validatorId: string}): Promise<ValidatorResponse>
getValidatorBalances(params: {stateId: StateId}): Promise<ValidatorBalance>
getEpochCommittees(params: {stateId: StateId, epoch: Epoch}): Promise<BeaconCommitteeResponse>
getBlockHeaders(): Promise<SignedBeaconHeaderResponse[]>
getBlockHeader(params: {blockId: BlockId}): Promise<SignedBeaconHeaderResponse>
publishSignedBlock(): Promise<void>
getBlock(params: {blockId: BlockId}): Promise<SignedBeaconHeaderResponse>
getBlockRoot(params: {blockId: BlockId}): Promise<Root>
getBlockAttestations(params: {blockId: BlockId}): Promise<Attestation>
getAttestationsFromPool(params: {slot: Slot, committee_index: CommitteeIndex}): Promise<Attestation[]>
submitAttestation(): Promise<void>
getAttesterSlashings(): Promise<{ [index: string]: IndexedAttestation }>
submitAttesterSlashings(): Promise<void>
getProposerSlashings(): Promise<ProposerSlashing[]>
submitProposerSlashings(): Promise<void>
getSignedVoluntaryExits(): Promise<SignedVoluntaryExit[]>
submitVoluntaryExit(): Promise<void>
}

46 changes: 0 additions & 46 deletions packages/web3-eth2-beaconchain/types/index.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/web3-eth2-beaconchain/types/tsconfig.json

This file was deleted.

21 changes: 17 additions & 4 deletions packages/web3-eth2-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/web3-eth2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
"main": "lib/index.js",
"dependencies": {
"axios": "^0.20.0"
"axios": "^0.21.1"
},
"devDependencies": {
"@types/jest": "^26.0.14",
"@types/node": "^14.11.8",
"@types/node": "^14.14.22",
"dtslint": "^3.4.1",
"jest": "^26.5.3",
"ts-jest": "^26.4.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/web3-eth2-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import Axios, {AxiosInstance} from 'axios'

Axios.defaults.adapter = require('axios/lib/adapters/http');

import { ETH2BaseOpts, ETH2Function } from '../types/index'
import { IBaseAPISchema } from './schema'
import { ETH2BaseOpts, ETH2Function, BaseAPISchema } from '../types'

export class ETH2Core {
private _httpClient: AxiosInstance
Expand All @@ -14,7 +13,7 @@ export class ETH2Core {
provider: string
protectProvider: boolean // Protects from global overwrite when using .use functionality

constructor(provider: string, schema: IBaseAPISchema, opts: ETH2BaseOpts = {}) {
constructor(provider: string, schema: BaseAPISchema, opts: ETH2BaseOpts = {}) {
this.name = schema.packageName
this.setProvider(`${provider}${schema.routePrefix}`)
this.protectProvider = opts.protectProvider || false
Expand Down Expand Up @@ -63,13 +62,14 @@ export class ETH2Core {
}
}

private buildAPIWrappersFromSchema(schema: IBaseAPISchema) {
private buildAPIWrappersFromSchema(schema: BaseAPISchema) {
for (const method of schema.methods) {
this[method.name] = async (routeParameters: any, queryParameters: any = {}): Promise<any> => {
try {
if (method.inputFormatter) queryParameters = method.inputFormatter(queryParameters)

const computedRoute = this.routeBuilder(method.route, routeParameters)
// @ts-ignore
let {data} = await this._httpClient[method.restMethod](computedRoute, { params: queryParameters })
if (data.data) data = data.data

Expand Down
16 changes: 0 additions & 16 deletions packages/web3-eth2-core/src/schema.ts

This file was deleted.

18 changes: 15 additions & 3 deletions packages/web3-eth2-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
"outDir": "./lib",
"module": "commonjs",
"lib": ["es6"],
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true,
"allowSyntheticDefaultImports": false,
"baseUrl": ".",
"paths": {
"web3-eth2-core": ["."]
}
},
"include": [
"src"
]
, "types.ts" ]
}
Loading