Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit b0bce09

Browse files
committed
Merge branch '4.x' into ok/6500-Errors-not-caught-in-4.x
2 parents 681bcdc + 20cc5da commit b0bce09

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

packages/web3-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"dependencies": {
4545
"web3-errors": "^1.1.4",
4646
"web3-eth-iban": "^4.0.7",
47+
"web3-eth-accounts": "^4.1.0",
4748
"web3-providers-http": "^4.1.0",
4849
"web3-providers-ws": "^4.0.7",
4950
"web3-types": "^1.3.1",

packages/web3-core/src/web3_context.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,23 @@ You should have received a copy of the GNU Lesser General Public License
1515
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
// eslint-disable-next-line max-classes-per-file
18+
import { ExistingPluginNamespaceError } from 'web3-errors';
1819
import {
19-
Web3APISpec,
20-
Web3BaseWallet,
21-
Web3BaseWalletAccount,
22-
Web3AccountProvider,
23-
SupportedProviders,
24-
HexString,
2520
EthExecutionAPI,
26-
Web3BaseProvider,
27-
Transaction,
21+
HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet,
22+
Web3BaseWalletAccount
2823
} from 'web3-types';
2924
import { isNullish } from 'web3-utils';
30-
import { ExistingPluginNamespaceError } from 'web3-errors';
31-
25+
import { BaseTransaction, TransactionFactory } from 'web3-eth-accounts';
3226
import { isSupportedProvider } from './utils.js';
3327
// eslint-disable-next-line import/no-cycle
28+
import { ExtensionObject } from './types.js';
29+
import { Web3BatchRequest } from './web3_batch_request.js';
30+
// eslint-disable-next-line import/no-cycle
3431
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config.js';
3532
import { Web3RequestManager } from './web3_request_manager.js';
3633
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';
3734
import { Web3SubscriptionManager } from './web3_subscription_manager.js';
38-
import { Web3BatchRequest } from './web3_batch_request.js';
39-
import { ExtensionObject } from './types.js';
4035

4136
// To avoid circular dependencies, we need to export type from here.
4237
export type Web3ContextObject<
@@ -395,16 +390,6 @@ export class Web3Context<
395390
}
396391
}
397392

398-
// To avoid cycle dependency declare this type in this file
399-
export type TransactionBuilder<API extends Web3APISpec = unknown> = <
400-
ReturnType = Transaction,
401-
>(options: {
402-
transaction: Transaction;
403-
web3Context: Web3Context<API>;
404-
privateKey?: HexString | Uint8Array;
405-
fillGasPrice?: boolean;
406-
}) => Promise<ReturnType>;
407-
408393
/**
409394
* Extend this class when creating a plugin that either doesn't require {@link EthExecutionAPI},
410395
* or interacts with a RPC node that doesn't fully implement {@link EthExecutionAPI}.
@@ -422,29 +407,44 @@ export type TransactionBuilder<API extends Web3APISpec = unknown> = <
422407
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
423408
* ```
424409
*/
425-
export abstract class Web3PluginBase<
426-
API extends Web3APISpec = Web3APISpec,
410+
export abstract class Web3PluginBase<
411+
API extends Web3APISpec = Web3APISpec,
427412
> extends Web3Context<API> {
428-
public abstract pluginNamespace: string;
413+
public abstract pluginNamespace: string;
414+
415+
// eslint-disable-next-line class-methods-use-this
416+
protected registerNewTransactionType<NewTxTypeClass extends typeof BaseTransaction<unknown>>(type: Numbers, txClass: NewTxTypeClass): void {
417+
TransactionFactory.registerTransactionType(type, txClass);
418+
}
429419
}
430420

431421
/**
432-
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
433-
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
434-
*
435-
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
436-
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
437-
*
438-
* @example
439-
* ```ts
440-
* type CustomRpcApi = {
441-
* custom_rpc_method: () => string;
442-
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
443-
* };
444-
*
445-
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
446-
* ```
447-
*/
422+
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
423+
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
424+
*
425+
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
426+
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
427+
*
428+
* @example
429+
* ```ts
430+
* type CustomRpcApi = {
431+
* custom_rpc_method: () => string;
432+
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
433+
* };
434+
*
435+
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
436+
* ```
437+
*/
448438
export abstract class Web3EthPluginBase<API extends Web3APISpec = unknown> extends Web3PluginBase<
449-
API & EthExecutionAPI
439+
API & EthExecutionAPI
450440
> {}
441+
442+
// To avoid cycle dependency declare this type in this file
443+
export type TransactionBuilder<API extends Web3APISpec = unknown> = <
444+
ReturnType = Transaction,
445+
>(options: {
446+
transaction: Transaction;
447+
web3Context: Web3Context<API>;
448+
privateKey?: HexString | Uint8Array;
449+
fillGasPrice?: boolean;
450+
}) => Promise<ReturnType>;

packages/web3-utils/test/unit/socket_provider.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe('SocketProvider', () => {
323323

324324
// @ts-expect-error run protected method
325325
expect(provider._sentRequestsQueue.size).toBe(1);
326-
expect(provider.getSentRequestsQueueSize).toBe(1);
326+
expect(provider.getSentRequestsQueueSize()).toBe(1);
327327

328328
provider.on('error', () => {
329329
// nothing
@@ -335,7 +335,7 @@ describe('SocketProvider', () => {
335335
expect(provider.getPendingRequestQueueSize()).toBe(0);
336336
// @ts-expect-error run protected method
337337
expect(provider._sentRequestsQueue.size).toBe(0);
338-
expect(provider.getSentRequestsQueueSize).toBe(0);
338+
expect(provider.getSentRequestsQueueSize()).toBe(0);
339339
});
340340
});
341341
});

packages/web3/test/integration/web3-plugin-add-tx.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1717

1818
/* eslint-disable @typescript-eslint/no-magic-numbers */
1919

20-
import { Transaction, TransactionFactory, Web3Account } from 'web3-eth-accounts';
20+
import { Transaction, Web3Account } from 'web3-eth-accounts';
2121
import { SupportedProviders, Web3, Web3PluginBase } from '../../src';
2222
import {
2323
createAccount,
@@ -31,7 +31,7 @@ class Eip4844Plugin extends Web3PluginBase {
3131
public pluginNamespace = 'txType3';
3232
public constructor() {
3333
super();
34-
TransactionFactory.registerTransactionType(TRANSACTION_TYPE, SomeNewTxTypeTransaction);
34+
this.registerNewTransactionType(TRANSACTION_TYPE, SomeNewTxTypeTransaction);
3535
}
3636
}
3737

0 commit comments

Comments
 (0)