Skip to content

Modules: loadModules and register functions instead of classes#4156

Open
MicahMaphet wants to merge 9 commits into
bitpay:masterfrom
MicahMaphet:load-modules
Open

Modules: loadModules and register functions instead of classes#4156
MicahMaphet wants to merge 9 commits into
bitpay:masterfrom
MicahMaphet:load-modules

Conversation

@MicahMaphet
Copy link
Copy Markdown
Contributor

@MicahMaphet MicahMaphet commented May 5, 2026

Description

The Modules class logic was unnecessarily coupled. Made modules logic more isolated by replacing the Modules singleton with the loadModules function and removing convoluted inheritance. Modules no longer export classes, but instead export register functions.

The goal is entirely readability. The module classes had no need for internal state, all they do is call a few functions once.

Changelog

  • Single loadModules function instead of Modules singleton
  • Instead of the modules being classes, they export register functions
  • Import P2P, Libs, CSP, and Verification from modules instead of passing from Modules
  • Blew away RippleEventAdapter
  • Blew away effectively unused interface IService and unused class BaseModule
  • Updated tests accordingly
  • test/unit/modules.test.ts verifyModules was redone to account for loosing Modules internal state

Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

@MicahMaphet MicahMaphet changed the title Standalone loadModules function Modules: loadModules and register functions instead of classes May 6, 2026
@kajoseph kajoseph requested a review from Copilot May 8, 2026 17:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() with loadModules() across workers, test helpers, and verification scripts.
  • Converted chain modules from BaseModule subclasses to register({ 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.

Comment thread packages/bitcore-node/src/modules/index.ts Outdated
Comment thread packages/bitcore-node/src/modules/index.ts Outdated
Comment thread packages/bitcore-node/test/unit/modules.test.ts Outdated
Comment thread packages/bitcore-node/src/modules/bitcoin-cash/index.ts Outdated
MicahMaphet and others added 2 commits May 11, 2026 12:20
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants