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

Add guide for the breaking changes for Iban and IpcProvider #5899

Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f8483b3
pass `_socketOptions` from IpcProvider constructor to the underlying …
Muhammad-Altabba Mar 6, 2023
9ba98e2
move a comment to its correct position at `SocketProvider`
Muhammad-Altabba Mar 6, 2023
7e96e84
expose the getter of `SocketConnection` from `SocketProvider`.
Muhammad-Altabba Mar 6, 2023
e450485
update CHANGELOG.md files
Muhammad-Altabba Mar 6, 2023
fd9dd2c
add extremely simple unit test for SocketProvider
Muhammad-Altabba Mar 6, 2023
9800deb
removed unused import at a test
Muhammad-Altabba Mar 6, 2023
b74a281
use `MaxAttemptsReachedOnReconnectingError` similar to v1.x
Muhammad-Altabba Mar 6, 2023
6e84af7
modify CHANGELOG.md
Muhammad-Altabba Mar 6, 2023
9e1d763
Merge branch 'feature/5887/the-options-passed-to-the-ipcprovider-is-n…
Muhammad-Altabba Mar 6, 2023
ca63a2a
add guide for `IpcProvider`
Muhammad-Altabba Mar 7, 2023
70dc237
add migration guid for Iban
Muhammad-Altabba Mar 7, 2023
2c29fea
rearrange sidebar_position for iban guide
Muhammad-Altabba Mar 7, 2023
604f98a
Merge branch '4.x' into feature/5737/guide-breaking-changes-documenat…
Muhammad-Altabba Mar 7, 2023
a3b8624
revert changes in order to be done in another MR
Muhammad-Altabba Mar 7, 2023
d249f25
Merge branch 'feature/5737/guide-breaking-changes-documenation-for-ib…
Muhammad-Altabba Mar 7, 2023
03500ee
Revert "modify CHANGELOG.md"
Muhammad-Altabba Mar 8, 2023
82f76c4
Revert "use `MaxAttemptsReachedOnReconnectingError` similar to v1.x"
Muhammad-Altabba Mar 8, 2023
a5ee8da
Merge branch '4.x' into feature/5737/guide-breaking-changes-documenat…
Muhammad-Altabba Mar 9, 2023
305c581
Merge branch '4.x' into feature/5737/guide-breaking-changes-documenat…
Muhammad-Altabba Mar 9, 2023
a60c0ba
Update docs/docs/guides/web3_migration_guide/web3_eth_iban.md
Muhammad-Altabba Mar 9, 2023
36083b4
Merge remote-tracking branch 'origin/4.x' into feature/5737/guide-bre…
Muhammad-Altabba Mar 9, 2023
6b16f84
Merge branch 'feature/5737/guide-breaking-changes-documenation-for-ib…
Muhammad-Altabba Mar 9, 2023
7bebe26
update and correct providers guides and give more samples
Muhammad-Altabba Mar 10, 2023
c0a7818
Merge branch '4.x' into feature/5737/guide-breaking-changes-documenat…
Muhammad-Altabba Mar 10, 2023
ea1027f
remove un-needed comment
Muhammad-Altabba Mar 11, 2023
adb105e
set the type for reconnectOptions at SocketProvider constructor
Muhammad-Altabba Mar 11, 2023
76dbe86
improve SocketProvider, WebSocketProvider and IpcProvider constructor…
Muhammad-Altabba Mar 13, 2023
d586feb
few edits at providers guides
Muhammad-Altabba Mar 13, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 9
sidebar_position: 10
sidebar_label: web3.*.net
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 7
sidebar_position: 8
sidebar_label: web3.eth.personal
---

Expand Down
131 changes: 128 additions & 3 deletions docs/docs/guides/web3_migration_guide/providers_migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ interface ReconnectOptions {
}
```

In 4.x, the options object is of type `ClientRequestArgs` or of `ClientOptions`. See [here](https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_http_d_._http_.clientrequestargs.html) for `ClientRequestArgs` and [here](https://github.com/websockets/ws) for `ClientOptions`.
In 4.x, the `socketOptions` parameter is of type `ClientRequestArgs` or of `ClientOptions`. See [here](https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_http_d_._http_.clientrequestargs.html) for `ClientRequestArgs` and [here](https://github.com/websockets/ws) for `ClientOptions`.

In 4.x a second option parameter can be given regarding auto-reconnecting, delay and max tries attempts. And here is its type:
In 4.x the `reconnectOptions` parameter can be given to control: auto-reconnecting, delay and max tries attempts. And here is its type:

```ts
// this is the same options interface used for both WebSocketProvider and IpcProvider
type ReconnectOptions = {
autoReconnect: boolean; // default: `true`
delay: number; // default: `5000`
Expand Down Expand Up @@ -165,6 +166,130 @@ const reconnectOptions: ReconnectOptions = {
};
```

And here is a sample instantiation for the `WebSocketProvider`:

```ts
const provider = new WebSocketProvider(
`ws://localhost:8545`,
{
headers: {
// to provide the API key if the Node requires the key to be inside the `headers` for example:
'x-api-key': '<Api key>',
},
},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

The second and the third parameters are both optional. And you can for example, the second parameter could be an empty object or undefined, like in the following example:

```ts
const provider = new WebSocketProvider(
`ws://localhost:8545`,
{},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

#### IpcProvider

The IPC provider is used in node.js dapps when running a local node. And it provide the most secure connection.

In 1.x, it used to accept the path and an instance of net.Server as in the following example:

```ts
import * as net from 'net';

const ipcProvider = new IpcProvider('/Users/myuser/Library/Ethereum/geth.ipc', new net.Server());
```

In 4.x, it accepts a second parameter called `socketOptions`. And, its type is `SocketConstructorOpts`. See [here](https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_net_d_._net_.socketconstructoropts.html) for full details. And here is its interface:

```ts
interface SocketConstructorOpts {
fd?: number | undefined;
allowHalfOpen?: boolean | undefined;
readable?: boolean | undefined;
writable?: boolean | undefined;
signal?: AbortSignal;
}
```

In 4.x the third parameter is called `reconnectOptions` that is of the type `ReconnectOptions`. It can be given to control: auto-reconnecting, delay and max tries attempts. And here its type:

```ts
// this is the same options interface used for both WebSocketProvider and IpcProvider
export type ReconnectOptions = {
autoReconnect: boolean;
delay: number;
maxAttempts: number;
};
```

##### Options examples

Below is an example for the passed options for each version:

```ts
// in 1.x
var net = require('net');

new Web3.providers.IpcProvider('/Users/myuser/Library/Ethereum/geth.ipc', net); // mac os path
// on windows the path is: "\\\\.\\pipe\\geth.ipc"
// on linux the path is: "/users/myuser/.ethereum/geth.ipc"

// in 4.x
let clientOptions: SocketConstructorOpts = {
allowHalfOpen: false;
readable: true;
writable: true;
};

const reconnectOptions: ReconnectOptions = {
autoReconnect: true,
delay: 5000,
maxAttempts: 5,
};
```

And here is a sample instantiation for the `IpcProvider`:

```ts
const provider = new IpcProvider(
`path.ipc`,
{
writable: false,
},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

The second and the third parameters are both optional. And, for example, the second parameter could be an empty object or undefined.

```ts
const provider = new IpcProvider(
`path.ipc`,
{},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

#### Error message for reconnect attempts

:::note
Expand All @@ -187,4 +312,4 @@ provider.on('error', error => {
// the `maxAttempts` is equal to the provided value by the user, or the default value `5`.
}
});
```
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 8
sidebar_position: 9
sidebar_label: web3.eth.subscribe
---

Expand Down
40 changes: 40 additions & 0 deletions docs/docs/guides/web3_migration_guide/web3_eth_iban.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
sidebar_position: 7
sidebar_label: web3.eth.iban
---

# web3.eth.iban Migration Guide

## Breaking Changes

### Iban class

#### The Iban contractor

##### In version 1.x

It used to just accept the passed string without any check.

##### In version 4.x

If the provided string was not of either the length of a direct IBAN (34 or 35), or the length of an indirect IBAN (20), an Error will be thrown. The error will contain the message `'Invalid IBAN was provided'`

#### Calling `toAddress` on an Iban that is not Direct

##### In version 1.x

It used to behave differently, if it was called on an instance of IBAN, from if it was called as a static method. However, this used to happen only if the provided address was not a Direct IBAN. More specifically, if the instance method `new Iban(address).toAddress()` was called, it will return an empty string (`''`) for that non Direct IBAN. And if the static method `Iban.toAddress(address)` was called, it used to throw an Error with the message `'IBAN is indirect and can\'t be converted'`, for that non Direct IBAN.

##### In version 4.x

If the provided IBAN was not a Direct one, an error will be thrown which contains the message: `'Iban is indirect and cannot be converted. Must be length of 34 or 35'`. And this behavior is now the same for the instance method `new Iban(address).toAddress()` and the static method `Iban.toAddress(address)`.

#### Calling `fromAddress` on an invalid address

##### In version 1.x

If the provided IBAN was not a valid Ethereum Address, an error used be thrown which contains the message `'Provided address is not a valid address: '+ address`.

##### In version 4.x

If the provided IBAN was not a valid Ethereum Address, an error object will be thrown which contains the message: `'Invalid value given "${address}". Error: 'invalid ethereum address'` and the code `1005`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 10
sidebar_position: 11
sidebar_label: web3.utils
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ web3.provider.on('chainChanged',()=>{
})

// it is possible to catch errors that could happen in the underlying connection Socket with the `error` event
// and it is also used to catch the error when max connection attempts exceeded
// and it is also used to catch the error when max reconnection attempts exceeded
// as in section: /docs/guides/web3_providers_guide/#error-message
web3.provider.on('error',()=>{
// ...
Expand Down
112 changes: 111 additions & 1 deletion docs/docs/guides/web3_providers_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ const httpOptions = {

#### WebSocketProvider

Use WebSocketProvider to connect to a Node using a WebSocket connection, i.e. over the `ws` or `wss` protocol.

The options object is of type `ClientRequestArgs` or of `ClientOptions`. See [here](https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_http_d_._http_.clientrequestargs.html) for `ClientRequestArgs` and [here](https://github.com/websockets/ws) for `ClientOptions`.

The second option parameter can be given regarding reconnecting. And here is its type:
Expand All @@ -166,6 +168,39 @@ provider.on('error', errorMessage => {
});
```

And here is a sample instantiation for the `WebSocketProvider`:

```ts
const provider = new WebSocketProvider(
`ws://localhost:8545`,
{
headers: {
// to provide the API key if the Node requires the key to be inside the `headers` for example:
'x-api-key': '<Api key>',
},
},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

The second and the third parameters are both optional. And, for example, the second parameter could be an empty object or undefined, like in the following example:

```ts
const provider = new WebSocketProvider(
`ws://localhost:8545`,
{},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

:::

##### Options example
Expand All @@ -188,6 +223,81 @@ const reconnectOptions: ReconnectOptions = {
};
```

### IpcProvider

The IPC Provider could be used in node.js dapps when running a local node. And it provide the most secure connection.

It accepts a second parameter called `socketOptions`. And, its type is `SocketConstructorOpts`. See [here](https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_net_d_._net_.socketconstructoropts.html) for full details. And here is its interface:

```ts
// for more check: https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules__types_node_net_d_._net_.socketconstructoropts.html
interface SocketConstructorOpts {
fd?: number | undefined;
allowHalfOpen?: boolean | undefined;
readable?: boolean | undefined;
writable?: boolean | undefined;
}
```

And, the third parameter is called `reconnectOptions` that is of the type `ReconnectOptions`. It can be given to control: auto-reconnecting, delay and max tries attempts. And here its type:

```ts
// this is the same options interface used for both WebSocketProvider and IpcProvider
export type ReconnectOptions = {
autoReconnect: boolean;
delay: number;
maxAttempts: number;
};
```

##### Options examples

Below is an example for the passed options for each version:

```ts
let clientOptions: SocketConstructorOpts = {
allowHalfOpen: false;
readable: true;
writable: true;
};

const reconnectOptions: ReconnectOptions = {
autoReconnect: true,
delay: 5000,
maxAttempts: 5,
};
```

And here is a sample instantiation for the `IpcProvider`:

```ts
const provider = new IpcProvider(
`path.ipc`,
{
writable: false,
},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

The second and the third parameters are both optional. And, for example, the second parameter could be an empty object or undefined.

```ts
const provider = new IpcProvider(
`path.ipc`,
{},
{
delay: 500,
autoReconnect: true,
maxAttempts: 10,
},
);
```

#### Error message for reconnect attempts

:::note
Expand All @@ -207,4 +317,4 @@ provider.on('error', error => {
// the `maxAttempts` is equal to the provided value by the user, or the default value `5`.
}
});
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ describe('parseTransactionError', () => {
},
]);

expect(() => parseTransactionError(error)).toThrowError(error);
expect(() => parseTransactionError(error)).toThrow(error);
});
});
Loading