@@ -15,28 +15,23 @@ You should have received a copy of the GNU Lesser General Public License
15
15
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
16
*/
17
17
// eslint-disable-next-line max-classes-per-file
18
+ import { ExistingPluginNamespaceError } from 'web3-errors' ;
18
19
import {
19
- Web3APISpec ,
20
- Web3BaseWallet ,
21
- Web3BaseWalletAccount ,
22
- Web3AccountProvider ,
23
- SupportedProviders ,
24
- HexString ,
25
20
EthExecutionAPI ,
26
- Web3BaseProvider ,
27
- Transaction ,
21
+ HexString , Numbers , SupportedProviders , Transaction , Web3AccountProvider , Web3APISpec , Web3BaseProvider , Web3BaseWallet ,
22
+ Web3BaseWalletAccount
28
23
} from 'web3-types' ;
29
24
import { isNullish } from 'web3-utils' ;
30
- import { ExistingPluginNamespaceError } from 'web3-errors' ;
31
-
25
+ import { BaseTransaction , TransactionFactory } from 'web3-eth-accounts' ;
32
26
import { isSupportedProvider } from './utils.js' ;
33
27
// 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
34
31
import { Web3Config , Web3ConfigEvent , Web3ConfigOptions } from './web3_config.js' ;
35
32
import { Web3RequestManager } from './web3_request_manager.js' ;
36
33
import { Web3SubscriptionConstructor } from './web3_subscriptions.js' ;
37
34
import { Web3SubscriptionManager } from './web3_subscription_manager.js' ;
38
- import { Web3BatchRequest } from './web3_batch_request.js' ;
39
- import { ExtensionObject } from './types.js' ;
40
35
41
36
// To avoid circular dependencies, we need to export type from here.
42
37
export type Web3ContextObject <
@@ -395,16 +390,6 @@ export class Web3Context<
395
390
}
396
391
}
397
392
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
-
408
393
/**
409
394
* Extend this class when creating a plugin that either doesn't require {@link EthExecutionAPI},
410
395
* or interacts with a RPC node that doesn't fully implement {@link EthExecutionAPI}.
@@ -422,29 +407,44 @@ export type TransactionBuilder<API extends Web3APISpec = unknown> = <
422
407
* class CustomPlugin extends Web3PluginBase<CustomRpcApi> {...}
423
408
* ```
424
409
*/
425
- export abstract class Web3PluginBase <
426
- API extends Web3APISpec = Web3APISpec ,
410
+ export abstract class Web3PluginBase <
411
+ API extends Web3APISpec = Web3APISpec ,
427
412
> 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
+ }
429
419
}
430
420
431
421
/**
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
+ */
448
438
export abstract class Web3EthPluginBase < API extends Web3APISpec = unknown > extends Web3PluginBase <
449
- API & EthExecutionAPI
439
+ API & EthExecutionAPI
450
440
> { }
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 > ;
0 commit comments