Modules: loadModules and register functions instead of classes#4156
Open
MicahMaphet wants to merge 9 commits into
Open
Modules: loadModules and register functions instead of classes#4156MicahMaphet wants to merge 9 commits into
MicahMaphet wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors bitcore-node module initialization by removing the Modules singleton/class-based modules and replacing them with a functional loadModules() entrypoint, with each chain module exporting a register function that directly registers services/providers/routes.
Changes:
- Replaced
Modules.loadConfigured()withloadModules()across workers, test helpers, and verification scripts. - Converted chain modules from
BaseModulesubclasses toregister({ chain, network })functions and removed unused/disabled Ripple event adapter code. - Updated unit/integration tests to reflect the new module-loading behavior.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/bitcore-node/test/verification/prune-fork.ts | Switches from Modules.loadConfigured() to loadModules(). |
| packages/bitcore-node/test/verification/db-verify.ts | Switches from Modules.loadConfigured() to loadModules(). |
| packages/bitcore-node/test/verification/db-verify-headers.ts | Switches from Modules.loadConfigured() to loadModules() and trims whitespace. |
| packages/bitcore-node/test/verification/db-repair.ts | Switches from Modules.loadConfigured() to loadModules(). |
| packages/bitcore-node/test/unit/modules.test.ts | Updates module-loading assertions to reflect function-based registration. |
| packages/bitcore-node/test/helpers/unit.ts | Loads modules via loadModules() in unit test setup helper. |
| packages/bitcore-node/test/helpers/integration.ts | Loads modules via loadModules() in integration test setup helper. |
| packages/bitcore-node/src/workers/p2p.ts | Uses loadModules({ chain, network }) instead of singleton. |
| packages/bitcore-node/src/workers/api.ts | Uses loadModules() instead of singleton. |
| packages/bitcore-node/src/workers/all.ts | Uses loadModules() instead of singleton. |
| packages/bitcore-node/src/modules/solana/index.ts | Converts Solana module to a register function. |
| packages/bitcore-node/src/modules/ripple/index.ts | Converts Ripple module to a register function and removes adapter wiring. |
| packages/bitcore-node/src/modules/ripple/api/event-adapter.ts | Removes the Ripple websocket adapter implementation file. |
| packages/bitcore-node/src/modules/multiProvider/index.ts | Converts MultiProvider module to a register function. |
| packages/bitcore-node/src/modules/moralis/index.ts | Converts Moralis module to a register function. |
| packages/bitcore-node/src/modules/matic/index.ts | Converts Matic module to a register function. |
| packages/bitcore-node/src/modules/litecoin/index.ts | Converts Litecoin module to a register function. |
| packages/bitcore-node/src/modules/index.ts | Replaces ModuleManager/Modules singleton with loadModules() implementation. |
| packages/bitcore-node/src/modules/ethereum/index.ts | Converts Ethereum module to a register function (and fixes prior import path). |
| packages/bitcore-node/src/modules/dogecoin/index.ts | Converts Dogecoin module to a register function. |
| packages/bitcore-node/src/modules/bitcoin/index.ts | Converts Bitcoin module to a register function. |
| packages/bitcore-node/src/modules/bitcoin-cash/index.ts | Converts Bitcoin Cash module to a register function. |
| packages/bitcore-client/test/unit/wallet.test.ts | Updates wallet tests to call loadModules() from bitcore-node build output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kajoseph
reviewed
May 8, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
Modulesclass logic was unnecessarily coupled. Made modules logic more isolated by replacing theModulessingleton with theloadModulesfunction and removing convoluted inheritance. Modules no longer export classes, but instead exportregisterfunctions.The goal is entirely readability. The module classes had no need for internal state, all they do is call a few functions once.
Changelog
loadModulesfunction instead ofModulessingletonregisterfunctionsP2P,Libs,CSP, and Verification from modules instead of passing fromModulesRippleEventAdapterIServiceand unused classBaseModuletest/unit/modules.test.tsverifyModuleswas redone to account for loosingModulesinternal stateChecklist