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

Commit 3ce8752

Browse files
refactor: remove config from manager
1 parent 1f8d416 commit 3ce8752

15 files changed

+44
-45
lines changed

packages/web3-core/src/web3_batch_request.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1818
import { JsonRpcBatchResponse, JsonRpcOptionalRequest, JsonRpcRequest } from 'web3-types';
1919
import { jsonRpc, Web3DeferredPromise } from 'web3-utils';
2020
import { OperationAbortError, OperationTimeoutError, ResponseError } from 'web3-errors';
21-
// eslint-disable-next-line import/no-cycle
2221
import { Web3RequestManager } from './web3_request_manager.js';
2322

2423
export const DEFAULT_BATCH_REQUEST_TIMEOUT = 1000;

packages/web3-core/src/web3_config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from 'web3-types';
2626
import { ConfigHardforkMismatchError, ConfigChainMismatchError } from 'web3-errors';
2727
import { isNullish, toHex } from 'web3-utils';
28-
import { ValidationSchemaInput } from 'web3-validator';
28+
import { Schema } from 'web3-validator';
2929
import { TransactionTypeParser } from './types.js';
3030
// eslint-disable-next-line import/no-cycle
3131
import { TransactionBuilder } from './web3_context.js';
@@ -60,7 +60,7 @@ export interface Web3ConfigOptions {
6060
};
6161
transactionBuilder?: TransactionBuilder;
6262
transactionTypeParser?: TransactionTypeParser;
63-
customTransactionSchema?: ValidationSchemaInput;
63+
customTransactionSchema?: Record<string, Schema>;
6464
defaultReturnFormat: DataFormat;
6565
}
6666

@@ -523,11 +523,11 @@ export abstract class Web3Config
523523
this.config.transactionTypeParser = val;
524524
}
525525

526-
public get customTransactionSchema(): ValidationSchemaInput | undefined {
526+
public get customTransactionSchema(): Record<string, Schema> | undefined {
527527
return this.config.customTransactionSchema;
528528
}
529529

530-
public set customTransactionSchema(schema: ValidationSchemaInput | undefined) {
530+
public set customTransactionSchema(schema: Record<string, Schema> | undefined) {
531531
this._triggerConfigChange('customTransactionSchema', schema);
532532
this.config.customTransactionSchema = schema;
533533
}

packages/web3-core/src/web3_context.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import { ExtensionObject, RequestManagerMiddleware } from './types.js';
3636
import { Web3BatchRequest } from './web3_batch_request.js';
3737
// eslint-disable-next-line import/no-cycle
3838
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config.js';
39-
// eslint-disable-next-line import/no-cycle
4039
import { Web3RequestManager } from './web3_request_manager.js';
4140
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';
4241
import { Web3SubscriptionManager } from './web3_subscription_manager.js';

packages/web3-core/src/web3_request_manager.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
} from './utils.js';
5454
import { Web3EventEmitter } from './web3_event_emitter.js';
5555
import { RequestManagerMiddleware } from './types.js';
56-
import { type Web3ConfigOptions } from './web3_config.js';
5756

5857
export enum Web3RequestManagerEvent {
5958
PROVIDER_CHANGED = 'PROVIDER_CHANGED',
@@ -75,19 +74,15 @@ export class Web3RequestManager<
7574
}> {
7675
private _provider?: SupportedProviders<API>;
7776
private readonly useRpcCallSpecification?: boolean;
78-
public config: Partial<Web3ConfigOptions>;
7977
public middleware?: RequestManagerMiddleware<API>;
8078

8179
public constructor(
8280
provider?: SupportedProviders<API> | string,
8381
useRpcCallSpecification?: boolean,
8482
requestManagerMiddleware?: RequestManagerMiddleware<API>,
85-
config?: Partial<Web3ConfigOptions>,
8683
) {
8784
super();
8885

89-
this.config = config ?? {};
90-
9186
if (!isNullish(provider)) {
9287
this.setProvider(provider);
9388
}
@@ -153,10 +148,6 @@ export class Web3RequestManager<
153148
return true;
154149
}
155150

156-
public setConfig(options: Partial<Web3ConfigOptions>) {
157-
Object.assign(this.config, options);
158-
}
159-
160151
public setMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>) {
161152
this.middleware = requestManagerMiddleware;
162153
}

packages/web3-core/src/web3_subscription_manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
import { ProviderError, SubscriptionError } from 'web3-errors';
3030
import { isNullish } from 'web3-utils';
3131
import { isSupportSubscriptions } from './utils.js';
32-
// eslint-disable-next-line import/no-cycle
3332
import { Web3RequestManager, Web3RequestManagerEvent } from './web3_request_manager.js';
3433
// eslint-disable-next-line import/no-cycle
3534
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';

packages/web3-core/src/web3_subscriptions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { jsonRpc } from 'web3-utils';
3434
// eslint-disable-next-line import/no-cycle
3535
import { Web3SubscriptionManager } from './web3_subscription_manager.js';
3636
import { Web3EventEmitter, Web3EventMap } from './web3_event_emitter.js';
37-
// eslint-disable-next-line import/no-cycle
3837
import { Web3RequestManager } from './web3_request_manager.js';
3938

4039
type CommonSubscriptionEvents = {

packages/web3-eth-personal/src/personal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class Personal extends Web3Context<EthPersonalAPI> {
159159
* ```
160160
*/
161161
public async sendTransaction(tx: Transaction, passphrase: string) {
162-
return rpcWrappers.sendTransaction(this.requestManager, tx, passphrase);
162+
return rpcWrappers.sendTransaction(this.requestManager, tx, passphrase, this.config);
163163
}
164164
/**
165165
* Signs a transaction. This account needs to be unlocked.
@@ -204,7 +204,7 @@ export class Personal extends Web3Context<EthPersonalAPI> {
204204
* ```
205205
*/
206206
public async signTransaction(tx: Transaction, passphrase: string) {
207-
return rpcWrappers.signTransaction(this.requestManager, tx, passphrase);
207+
return rpcWrappers.signTransaction(this.requestManager, tx, passphrase, this.config);
208208
}
209209
/**
210210
* Calculates an Ethereum specific signature with:

packages/web3-eth-personal/src/rpc_method_wrappers.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ GNU Lesser General Public License for more details.
1414
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
*/
17-
import { Web3RequestManager } from 'web3-core';
17+
import { Web3RequestManager, Web3ConfigOptions } from 'web3-core';
1818
import { toChecksumAddress, utf8ToHex } from 'web3-utils';
19-
import { formatTransaction } from 'web3-eth';
19+
import { formatTransaction, type CustomTransactionSchema } from 'web3-eth';
2020
import { Address, EthPersonalAPI, ETH_DATA_FORMAT, HexString, Transaction } from 'web3-types';
2121
import { validator, isHexStrict } from 'web3-validator';
2222
import { personalRpcMethods } from 'web3-rpc-methods';
@@ -72,9 +72,10 @@ export const sendTransaction = async (
7272
requestManager: Web3RequestManager<EthPersonalAPI>,
7373
tx: Transaction,
7474
passphrase: string,
75+
config?: Web3ConfigOptions,
7576
) => {
7677
const formattedTx = formatTransaction(tx, ETH_DATA_FORMAT, {
77-
transactionSchema: requestManager.config.customTransactionSchema,
78+
transactionSchema: config?.customTransactionSchema as CustomTransactionSchema,
7879
});
7980

8081
return personalRpcMethods.sendTransaction(requestManager, formattedTx, passphrase);
@@ -84,9 +85,10 @@ export const signTransaction = async (
8485
requestManager: Web3RequestManager<EthPersonalAPI>,
8586
tx: Transaction,
8687
passphrase: string,
88+
config?: Web3ConfigOptions,
8789
) => {
8890
const formattedTx = formatTransaction(tx, ETH_DATA_FORMAT, {
89-
transactionSchema: requestManager.config.customTransactionSchema,
91+
transactionSchema: config?.customTransactionSchema as CustomTransactionSchema,
9092
});
9193

9294
return personalRpcMethods.signTransaction(requestManager, formattedTx, passphrase);

packages/web3-eth/src/rpc_method_wrappers.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
SignatureObjectSchema,
6767
} from './schemas.js';
6868
import {
69+
type CustomTransactionSchema,
6970
SendSignedTransactionEvents,
7071
SendSignedTransactionOptions,
7172
SendTransactionEvents,
@@ -429,7 +430,7 @@ export async function getTransaction<ReturnFormat extends DataFormat>(
429430
return isNullish(response)
430431
? response
431432
: formatTransaction(response, returnFormat, {
432-
transactionSchema: web3Context.config.customTransactionSchema,
433+
transactionSchema: web3Context.config.customTransactionSchema as CustomTransactionSchema,
433434
fillInputAndData: true,
434435
});
435436
}
@@ -449,7 +450,7 @@ export async function getPendingTransactions<ReturnFormat extends DataFormat>(
449450
transaction as unknown as Transaction,
450451
returnFormat ?? web3Context.defaultReturnFormat,
451452
{
452-
transactionSchema: web3Context.config.customTransactionSchema,
453+
transactionSchema: web3Context.config.customTransactionSchema as CustomTransactionSchema,
453454
fillInputAndData: true,
454455
},
455456
),
@@ -490,7 +491,7 @@ export async function getTransactionFromBlock<ReturnFormat extends DataFormat>(
490491
return isNullish(response)
491492
? response
492493
: formatTransaction(response, returnFormat ?? web3Context.defaultReturnFormat, {
493-
transactionSchema: web3Context.config.customTransactionSchema,
494+
transactionSchema: web3Context.config.customTransactionSchema as CustomTransactionSchema,
494495
fillInputAndData: true,
495496
});
496497
}
@@ -610,7 +611,7 @@ export function sendTransaction<
610611
},
611612
ETH_DATA_FORMAT,
612613
{
613-
transactionSchema: web3Context.config.customTransactionSchema,
614+
transactionSchema: web3Context.config.customTransactionSchema as CustomTransactionSchema,
614615
},
615616
);
616617

@@ -854,7 +855,7 @@ export async function signTransaction<ReturnFormat extends DataFormat>(
854855
const response = await ethRpcMethods.signTransaction(
855856
web3Context.requestManager,
856857
formatTransaction(transaction, ETH_DATA_FORMAT, {
857-
transactionSchema: web3Context.config.customTransactionSchema,
858+
transactionSchema: web3Context.config.customTransactionSchema as CustomTransactionSchema,
858859
}),
859860
);
860861
// Some clients only return the encoded signed transaction (e.g. Ganache)
@@ -870,7 +871,7 @@ export async function signTransaction<ReturnFormat extends DataFormat>(
870871
returnFormat,
871872
),
872873
tx: formatTransaction((response as SignedTransactionInfoAPI).tx, returnFormat, {
873-
transactionSchema: web3Context.config.customTransactionSchema,
874+
transactionSchema: web3Context.config.customTransactionSchema as CustomTransactionSchema,
874875
fillInputAndData: true,
875876
}),
876877
};

packages/web3-eth/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
TransactionWithFromLocalWalletIndex,
3838
TransactionWithToLocalWalletIndex,
3939
} from 'web3-types';
40+
import { transactionSchema } from './schemas';
41+
import { Schema } from 'web3-validator';
4042

4143
export type InternalTransaction = FormatType<Transaction, typeof ETH_DATA_FORMAT>;
4244

@@ -105,3 +107,8 @@ export interface TransactionMiddleware {
105107
options?: { [key: string]: unknown },
106108
): Promise<TransactionMiddlewareData>;
107109
}
110+
111+
export type CustomTransactionSchema = {
112+
type: string;
113+
properties: typeof transactionSchema['properties'] & Record<string, Schema>;
114+
};

0 commit comments

Comments
 (0)