Skip to content

Commit

Permalink
Format repo, add new rules (#7226)
Browse files Browse the repository at this point in the history
* format all files and fix formatter so it runs on commit

* update eslint

* pre commit will run prettier on commited files

* update

* remove prepush
  • Loading branch information
luu-alex authored Sep 9, 2024
1 parent 27155ea commit b86d8ca
Show file tree
Hide file tree
Showing 222 changed files with 5,731 additions and 5,318 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ module.exports = {
typescript: {}, // this loads tsconfig.json to eslint
},
},
overrides: [
{
files: ['*.test.ts'],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['*.ts'],
rules: {
'default-param-last': 'off',
},
},
],
};
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
4 changes: 0 additions & 4 deletions .husky/pre-push

This file was deleted.

35 changes: 17 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-errors

- Added `InvalidIntegerError` error for fromWei and toWei (#7052)
- Added `InvalidIntegerError` error for fromWei and toWei (#7052)

#### web3-eth

Expand All @@ -2484,8 +2484,8 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-utils

- `toWei` add warning when using large numbers or large decimals that may cause precision loss (#6908)
- `toWei` and `fromWei` now supports integers as a unit. (#7053)
- `toWei` add warning when using large numbers or large decimals that may cause precision loss (#6908)
- `toWei` and `fromWei` now supports integers as a unit. (#7053)

### Fixed

Expand All @@ -2495,13 +2495,13 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-utils

- `toWei` support numbers in scientific notation (#6908)
- `toWei` and `fromWei` trims according to ether unit successfuly (#7044)
- `toWei` support numbers in scientific notation (#6908)
- `toWei` and `fromWei` trims according to ether unit successfuly (#7044)

#### web3-validator

- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981)
- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015)
- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981)
- `browser` entry point that was pointing to an non-existing bundle file was removed from `package.json` (#7015)

#### web3-core

Expand Down Expand Up @@ -2600,7 +2600,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-eth-accounts

- baseTransaction method updated (#7095)
- baseTransaction method updated (#7095)

#### web3-providers-ws

Expand All @@ -2612,7 +2612,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-rpc-providers

- Change request return type `Promise<ResultType>` to `Promise<JsonRpcResponseWithResult<ResultType>>` (#7102)
- Change request return type `Promise<ResultType>` to `Promise<JsonRpcResponseWithResult<ResultType>>` (#7102)

### Added

Expand All @@ -2623,7 +2623,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-rpc-providers

- When error is returned with code 429, throw rate limit error (#7102)
- When error is returned with code 429, throw rate limit error (#7102)

#### web3

Expand All @@ -2635,7 +2635,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-errors

- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)

#### web3-eth

Expand All @@ -2646,7 +2646,6 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

- Remove redundant constructor of contractBuilder (#7150)


## [4.12.0]

### Fixed
Expand All @@ -2657,7 +2656,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-eth-accounts

- Fix `TransactionFactory.registerTransactionType` not working, if there is a version mistatch between `web3-eth` and `web3-eth-accounts` by saving `extraTxTypes` at `globals`. (#7197)
- Fix `TransactionFactory.registerTransactionType` not working, if there is a version mistatch between `web3-eth` and `web3-eth-accounts` by saving `extraTxTypes` at `globals`. (#7197)

### Added

Expand All @@ -2667,11 +2666,11 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-eth-contract

- Added `populateTransaction` to the `contract.deploy(...)` properties. (#7197)
- Added `populateTransaction` to the `contract.deploy(...)` properties. (#7197)

#### web3-providers-http

- Added `statusCode` of response in ResponseError, `statusCode` is optional property in ResponseError.
- Added `statusCode` of response in ResponseError, `statusCode` is optional property in ResponseError.

#### web3-rpc-providers

Expand All @@ -2680,22 +2679,22 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-errors

- Added optional `statusCode` property of response in ResponseError.
- Added optional `statusCode` property of response in ResponseError.

### Changed

#### web3-eth-contract

- The returnred properties of `contract.deploy(...)` are structured with a newly created class named `DeployerMethodClass`. (#7197)
- Add a missed accepted type for the `abi` parameter, at `dataInputEncodeMethodHelper` and `getSendTxParams`. (#7197)
- Add a missed accepted type for the `abi` parameter, at `dataInputEncodeMethodHelper` and `getSendTxParams`. (#7197)

## [4.12.1]

### Fixed

#### web3-eth-accounts

- Revert `TransactionFactory.registerTransactionType` if there is a version mistatch between `web3-eth` and `web3-eth-accounts` and fix nextjs problem. (#7216)
- Revert `TransactionFactory.registerTransactionType` if there is a version mistatch between `web3-eth` and `web3-eth-accounts` and fix nextjs problem. (#7216)

#### web3

Expand Down
128 changes: 63 additions & 65 deletions docs/docs/guides/advanced/custom_RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ This will give your plugin access to [requestManager](/api/web3-core/class/Web3C

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

//highlight-start
class CustomRpcMethodsPlugin extends Web3PluginBase {
// step 1
// ...
// step 1
// ...
}
//highlight-end

Expand All @@ -56,8 +56,8 @@ import { Web3PluginBase } from 'web3';

//highlight-start
export default class CustomRpcMethodsPlugin extends Web3PluginBase {
// step 1
// ...
// step 1
// ...
}
//highlight-end
```
Expand All @@ -69,19 +69,18 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {

2. After that add public `pluginNamespace` property. This will be used to access your plugin, as mentioned in step number 5 code example.


<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

class CustomRpcMethodsPlugin extends Web3PluginBase {
//highlight-start
pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
//highlight-start
pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
}

module.exports = CustomRpcMethodsPlugin;
Expand All @@ -96,40 +95,39 @@ module.exports = CustomRpcMethodsPlugin;
import { Web3PluginBase } from 'web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
//highlight-start
public pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
//highlight-start
public pluginNamespace = 'customRpcMethods'; // step 2
//highlight-end
}
```

</TabItem>
</Tabs>


### Step 3: Creating Custom RPC Methods in the Plugin Class

3. Once plugin class is created using above mentioned steps, its very easy to add new RPC methods like:

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

class CustomRpcMethodsPlugin extends Web3PluginBase {
pluginNamespace = 'customRpcMethods';
pluginNamespace = 'customRpcMethods';

//highlight-start
async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
//highlight-end
}

Expand All @@ -145,18 +143,18 @@ module.exports = CustomRpcMethodsPlugin;
import { Web3PluginBase } from 'web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';

//highlight-start
public async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
//highlight-end
public pluginNamespace = 'customRpcMethods';

//highlight-start
public async customRpcMethod() {
// step 3
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
//highlight-end
}
```

Expand All @@ -169,22 +167,22 @@ export default class CustomRpcMethodsPlugin extends Web3PluginBase {

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3PluginBase } = require('web3');

class CustomRpcMethodsPlugin extends Web3PluginBase {
pluginNamespace = 'customRpcMethods';

async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
pluginNamespace = 'customRpcMethods';

async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
}

module.exports = CustomRpcMethodsPlugin;
Expand All @@ -199,25 +197,25 @@ module.exports = CustomRpcMethodsPlugin;
import { Web3PluginBase } from 'web3';

export default class CustomRpcMethodsPlugin extends Web3PluginBase {
public pluginNamespace = 'customRpcMethods';

public async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
public pluginNamespace = 'customRpcMethods';

public async customRpcMethod() {
return this.requestManager.send({
// plugin has access to web3.js internal features like request manager
method: 'custom_rpc_method',
params: [],
});
}
}

//highlight-start
// Module Augmentation
declare module 'web3' {
// step 4
// step 4

interface Web3Context {
customRpcMethods: CustomRpcMethodsPlugin;
}
interface Web3Context {
customRpcMethods: CustomRpcMethodsPlugin;
}
}
//highlight-end
```
Expand All @@ -237,8 +235,8 @@ Once plugin is registered its custom methods will be available to use.

<Tabs groupId='prog-lang' queryString>

<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>
<TabItem value='javascript' label='JavaScript'
attributes={{className: 'javascript-tab'}}>

```javascript
const { Web3 } = require('web3');
Expand Down
Loading

1 comment on commit b86d8ca

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: b86d8ca Previous: 27155ea Ratio
processingTx 22440 ops/sec (±7.06%) 21492 ops/sec (±7.89%) 0.96
processingContractDeploy 38564 ops/sec (±7.90%) 40035 ops/sec (±5.14%) 1.04
processingContractMethodSend 16696 ops/sec (±7.81%) 15323 ops/sec (±10.31%) 0.92
processingContractMethodCall 27650 ops/sec (±7.82%) 28246 ops/sec (±6.49%) 1.02
abiEncode 44651 ops/sec (±6.88%) 43024 ops/sec (±7.13%) 0.96
abiDecode 30424 ops/sec (±7.61%) 29932 ops/sec (±7.74%) 0.98
sign 1574 ops/sec (±0.58%) 1509 ops/sec (±3.19%) 0.96
verify 365 ops/sec (±2.65%) 367 ops/sec (±0.55%) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.