feat: refactor service classes - #14
Conversation
Phase 1 of the service-architecture uniformity refactor. Adds the abstract ChainService base (protected zenon + injected ZenonService, public ctor) that the 7 network services will extend in Phase 2. No consumers yet.
Phase 2 of the service-architecture uniformity refactor. The 7 network services (account/transaction/stake/plasma/pillar/rewards/token) now extend ChainService, dropping their duplicated zenon/zenonService fields, private constructor, and ensureInitialized() in favour of the shared base. Singleton getInstance() machinery and all RPC bodies are unchanged; behaviour preserved.
Phase 3+4 of the service-architecture uniformity refactor. - wallet-service.ts: public defaulted-DI ctor (drop private, default storage to storageService); getInstance() wiring and behaviour unchanged. - chain-service.ts / session-manager.ts / storage-service.ts: document the two-tier convention (Tier A = ChainService base; Tier B = public defaulted-DI ctor, module-const is the prod wrapper). Comments only, no behaviour change.
0x3639
commented
Jun 17, 2026
Findings
Checks
No production behavior regression jumped out; the main issue is that the refactor does not fully deliver the claimed fake-injectable service layer yet. |
0x3639
commented
Jun 17, 2026
Looks good to go. No additional comments! |
Brings in PR digitalSloth#14 (refactor service classes, e1e33bb).
edgepillar
commented
Aug 25, 2026
Hi — I’m considering a small tests-only follow-up to #14 focused on Proposed scope:
The tests would use opaque fake keystore objects. There would be no production-code changes, mnemonic or wallet fixtures, browser-storage tests, or CI workflow changes. I did not find an open issue, pull request, or public branch implementing this scope. Is anyone already working on the test-suite follow-up mentioned in #14? If not, would this be a useful first PR? |
digitalSloth
commented
Aug 25, 2026
@edgepillar Yes please, that would be great if you want to start working on the unit tests for the repo |
Uniform service-layer architecture:
ChainServicebase + Tier-B conventionSummary
Makes the
src/core/service layer architecturally uniform before we add unit tests. Previously the services shared a singleton pattern but diverged in constructor shape; the planned test-friendly refactor would have left them in three different shapes. This collapses that inconsistency into a documented two-tier convention.ChainService) and one DI seam (an injectedZenonService).Net result: −43 lines (56 insertions / 99 deletions), no behavior change, and every service is now constructable with fakes for the upcoming test suite.
Changes
1. Add
ChainServiceabstract baseNew
src/core/chain-service.ts—protected zenon, a public constructor injectingZenonService(defaulted to the prod singleton), andensureInitialized(). The ctor is public so subclasses stay test-constructable;abstractis what prevents direct instantiation.2. Migrate the 7 network services onto it
account / transaction / stake / plasma / pillar / rewards / tokennowextends ChainService, dropping their duplicatedzenon/zenonServicefields, private constructor, andensureInitialized(). Each keeps its ownstatic instance+getInstance()(deliberately not hoisted, to avoid a TS strict static-typing pitfall). No RPC method body changed.3.
WalletServiceTier-B ctor + document the conventionwallet-service.ts: public defaulted-DI ctor (constructor(private storage: StorageAdapter = storageService));getInstance()wiring unchanged.chain-service.ts(canonical home) plus one-line pointers onsession-manager.tsandstorage-service.ts.Behavior preservation
Fully behavior-preserving. Each service's
getInstance()still returns the same singleton wired to the sameZenonService/storageService; the defaulted ctor params reproduce the previous explicit wiring exactly. No composable,background.ts,main.ts, orsrc/core/index.tswas touched — the ~16getInstance()call sites are unchanged.Out of scope
ZenonService(the injected dependency itself),PlasmaBotService(already self-documents its exemption),SessionManager/StorageService, and the storage adapters are intentionally left as-is under the Tier-B convention. No tests are added here — that's the follow-up.Verification
npm run typecheck— 0 errorsnpm run lint— 0 errors (6 pre-existing warnings)npm run buildandnpm run build:extension— both pass