diff --git a/packages/protocol/src/protocol/Protocol.ts b/packages/protocol/src/protocol/Protocol.ts index 13c21a24e..772bb90ab 100644 --- a/packages/protocol/src/protocol/Protocol.ts +++ b/packages/protocol/src/protocol/Protocol.ts @@ -27,10 +27,16 @@ import { ProvableTransactionHook } from "./ProvableTransactionHook"; import { ProtocolEnvironment } from "./ProtocolEnvironment"; import { ProvableBlockHook } from "./ProvableBlockHook"; +/** + * This is a mapping of abstract classes to their respective injection tokens. + * Keys are the abstract classes names, which need to be set dynamically + * and can't be hardcoded since producing optimized builds may mangle the + * class names, making them different from the ones in the source code. + */ const PROTOCOL_INJECTION_TOKENS: Record = { - ProvableTransactionHook: "ProvableTransactionHook", - ProvableBlockHook: "ProvableBlockHook", - ProvableSettlementHook: "ProvableSettlementHook", + [ProvableTransactionHook.name]: "ProvableTransactionHook", + [ProvableBlockHook.name]: "ProvableBlockHook", + [ProvableSettlementHook.name]: "ProvableSettlementHook", }; export type ProtocolModulesRecord = ModulesRecord< @@ -161,7 +167,7 @@ export class Protocol< implementingModules.forEach(([key]) => { this.container.register( - abstractType.name, + newInjectionToken, { useToken: key }, { lifecycle: Lifecycle.ContainerScoped } ); @@ -174,7 +180,7 @@ export class Protocol< // Register default (noop) version this.container.register( - abstractType.name, + newInjectionToken, { useClass: defaultType }, { lifecycle: Lifecycle.ContainerScoped } );