Skip to content

Commit

Permalink
Merge branch '4.x' into ok/5562-Stress-Tests-1---QA-Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Nov 27, 2023
2 parents 425359b + 3bda14d commit 5b7cd0c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 46 deletions.
1 change: 1 addition & 0 deletions packages/web3-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"dependencies": {
"web3-errors": "^1.1.4",
"web3-eth-iban": "^4.0.7",
"web3-eth-accounts": "^4.1.0",
"web3-providers-http": "^4.1.0",
"web3-providers-ws": "^4.0.7",
"web3-types": "^1.3.1",
Expand Down
84 changes: 42 additions & 42 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
// eslint-disable-next-line max-classes-per-file
import { ExistingPluginNamespaceError } from 'web3-errors';
import {
Web3APISpec,
Web3BaseWallet,
Web3BaseWalletAccount,
Web3AccountProvider,
SupportedProviders,
HexString,
EthExecutionAPI,
Web3BaseProvider,
Transaction,
HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet,
Web3BaseWalletAccount
} from 'web3-types';
import { isNullish } from 'web3-utils';
import { ExistingPluginNamespaceError } from 'web3-errors';

import { BaseTransaction, TransactionFactory } from 'web3-eth-accounts';
import { isSupportedProvider } from './utils.js';
// eslint-disable-next-line import/no-cycle
import { ExtensionObject } from './types.js';
import { Web3BatchRequest } from './web3_batch_request.js';
// eslint-disable-next-line import/no-cycle
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config.js';
import { Web3RequestManager } from './web3_request_manager.js';
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';
import { Web3SubscriptionManager } from './web3_subscription_manager.js';
import { Web3BatchRequest } from './web3_batch_request.js';
import { ExtensionObject } from './types.js';

// To avoid circular dependencies, we need to export type from here.
export type Web3ContextObject<
Expand Down Expand Up @@ -395,16 +390,6 @@ export class Web3Context<
}
}

// To avoid cycle dependency declare this type in this file
export type TransactionBuilder<API extends Web3APISpec = unknown> = <
ReturnType = Transaction,
>(options: {
transaction: Transaction;
web3Context: Web3Context<API>;
privateKey?: HexString | Uint8Array;
fillGasPrice?: boolean;
}) => Promise<ReturnType>;

/**
* Extend this class when creating a plugin that either doesn't require {@link EthExecutionAPI},
* or interacts with a RPC node that doesn't fully implement {@link EthExecutionAPI}.
Expand All @@ -422,29 +407,44 @@ export type TransactionBuilder<API extends Web3APISpec = unknown> = <
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
export abstract class Web3PluginBase<
API extends Web3APISpec = Web3APISpec,
export abstract class Web3PluginBase<
API extends Web3APISpec = Web3APISpec,
> extends Web3Context<API> {
public abstract pluginNamespace: string;
public abstract pluginNamespace: string;

// eslint-disable-next-line class-methods-use-this
protected registerNewTransactionType<NewTxTypeClass extends typeof BaseTransaction<unknown>>(type: Numbers, txClass: NewTxTypeClass): void {
TransactionFactory.registerTransactionType(type, txClass);
}
}

/**
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
* Extend this class when creating a plugin that makes use of {@link EthExecutionAPI},
* or depends on other Web3 packages (such as `web3-eth-contract`) that depend on {@link EthExecutionAPI}.
*
* To add type support for RPC methods to the {@link Web3RequestManager} (in addition to {@link EthExecutionAPI}),
* define a {@link Web3APISpec} and pass it as a generic to Web3PluginBase like so:
*
* @example
* ```ts
* type CustomRpcApi = {
* custom_rpc_method: () => string;
* custom_rpc_method_with_parameters: (parameter1: string, parameter2: number) => string;
* };
*
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
* ```
*/
export abstract class Web3EthPluginBase<API extends Web3APISpec = unknown> extends Web3PluginBase<
API & EthExecutionAPI
API & EthExecutionAPI
> {}

// To avoid cycle dependency declare this type in this file
export type TransactionBuilder<API extends Web3APISpec = unknown> = <
ReturnType = Transaction,
>(options: {
transaction: Transaction;
web3Context: Web3Context<API>;
privateKey?: HexString | Uint8Array;
fillGasPrice?: boolean;
}) => Promise<ReturnType>;
6 changes: 5 additions & 1 deletion packages/web3/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,8 @@ Documentation:

- Dependencies updated ( details are in root changelog )

## [Unreleased]
## [Unreleased]

### Added

- Added methods (privateKeyToAddress, parseAndValidatePrivateKey, and privateKeyToPublicKey) to web3.eth.accounts (#6620)
8 changes: 7 additions & 1 deletion packages/web3/src/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import {
signTransaction,
sign,
Wallet,
privateKeyToAddress,
parseAndValidatePrivateKey,
privateKeyToPublicKey,
} from 'web3-eth-accounts';

/**
Expand Down Expand Up @@ -99,5 +102,8 @@ export const initAccountsForContext = (context: Web3Context<EthExecutionAPI>) =>
recover,
encrypt,
wallet,
};
privateKeyToAddress,
parseAndValidatePrivateKey,
privateKeyToPublicKey,
}
};
4 changes: 2 additions & 2 deletions packages/web3/test/integration/web3-plugin-add-tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

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

import { Transaction, TransactionFactory, Web3Account } from 'web3-eth-accounts';
import { Transaction, Web3Account } from 'web3-eth-accounts';
import { SupportedProviders, Web3, Web3PluginBase } from '../../src';
import {
createAccount,
Expand All @@ -31,7 +31,7 @@ class Eip4844Plugin extends Web3PluginBase {
public pluginNamespace = 'txType3';
public constructor() {
super();
TransactionFactory.registerTransactionType(TRANSACTION_TYPE, SomeNewTxTypeTransaction);
this.registerNewTransactionType(TRANSACTION_TYPE, SomeNewTxTypeTransaction);
}
}

Expand Down

0 comments on commit 5b7cd0c

Please sign in to comment.