import { WatcherProxy, WebsocketPayload } from "../interfaces"; import { Observable } from "rxjs"; /** * @description Watcher Proxy decorator * This class can be use to route different request to different Watcher Proxy instance depending on the network of the request */ export class CombinedWatcherProxy implements WatcherProxy { private select(network: string) { const { proxy } = this.proxyConfigs.find((x) => !!x.supportedNetwork.find((net) => net.toUpperCase() === network.toUpperCase())) || { proxy: undefined }; if (proxy) { return proxy; } else { throw new Error(`[CombinedWatcherProxy]: Unsupported network: ${network}`); } } watch(transactionId: string, address: string, network: string, nbConf: number): Observable { const proxy = this.select(network); return proxy.watch(transactionId, address, network, nbConf); } unwatch(transactionId: string, address: string, network: string, nbConf: number): Observable { const proxy = this.select(network); return proxy.unwatch(transactionId, address, network, nbConf); } constructor(private proxyConfigs: { supportedNetwork: string[], proxy: WatcherProxy }[]) { } }