From 7c851457170699065a612f1ea6c2296189f002e7 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Wed, 29 Jun 2022 17:36:11 +0000 Subject: [PATCH 1/2] Update endpoints ws is now /ws and all rest apis are /api/* --- pyth-common-js/src/PriceServiceConnection.ts | 8 +++----- pyth-common-js/src/examples/PriceServiceClient.ts | 7 ------- pyth-common-js/src/utils.ts | 14 ++------------ 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index bb9d4c9..0509f12 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -9,8 +9,6 @@ import { makeWebsocketUrl } from "./utils"; export type DurationInMs = number; export type PriceServiceConnectionConfig = { - /* Optional websocket endpoint of the price service if it has host/port other than the endpoint. */ - wsEndpoint?: string; /* Timeout of each request (for all of retries). Default: 5000ms */ timeout?: DurationInMs; /** @@ -82,7 +80,7 @@ export class PriceServiceConnection { this.logger?.error(error); }; - this.wsEndpoint = config?.wsEndpoint || makeWebsocketUrl(endpoint); + this.wsEndpoint = makeWebsocketUrl(endpoint); } /** @@ -99,7 +97,7 @@ export class PriceServiceConnection { return []; } - const response = await this.httpClient.get("/latest_price_feeds", { + const response = await this.httpClient.get("/api/latest_price_feeds", { params: { ids: priceIds, }, @@ -122,7 +120,7 @@ export class PriceServiceConnection { * @returns Array of base64 encoded VAAs. */ protected async getLatestVaas(priceIds: HexString[]): Promise { - const response = await this.httpClient.get("/latest_vaas", { + const response = await this.httpClient.get("/api/latest_vaas", { params: { ids: priceIds, }, diff --git a/pyth-common-js/src/examples/PriceServiceClient.ts b/pyth-common-js/src/examples/PriceServiceClient.ts index a7f1360..2f2a3cf 100644 --- a/pyth-common-js/src/examples/PriceServiceClient.ts +++ b/pyth-common-js/src/examples/PriceServiceClient.ts @@ -14,12 +14,6 @@ const argv = yargs(hideBin(process.argv)) type: "string", required: true, }) - .option("wsEndpoint", { - description: - "Optional web socket endpoint for the price service if it's different than endpoint. e.g: wss://endpoint/example", - type: "string", - required: false, - }) .option("price-ids", { description: "Space separated price feed ids (in hex without leading 0x) to fetch." + @@ -33,7 +27,6 @@ const argv = yargs(hideBin(process.argv)) async function run() { const connection = new PriceServiceConnection(argv.endpoint, { - wsEndpoint: argv.wsEndpoint, logger: console, // Providing logger will allow the connection to log it's events. }); diff --git a/pyth-common-js/src/utils.ts b/pyth-common-js/src/utils.ts index cdad955..ed02be1 100644 --- a/pyth-common-js/src/utils.ts +++ b/pyth-common-js/src/utils.ts @@ -1,24 +1,14 @@ /** * Convert http(s) endpoint to ws(s) endpoint. * - * @param endpoint Http(s) protocol endpoint + * @param endpoint Http(s) protocol endpoint. * @returns Ws(s) protocol endpoint of the same address */ export function makeWebsocketUrl(endpoint: string) { - const url = new URL(endpoint); + const url = new URL("ws", endpoint); const useHttps = url.protocol === "https:"; url.protocol = useHttps ? "wss:" : "ws:"; - url.host = ""; - // Only shift the port by +1 as a convention for ws(s) only if given endpoint - // is explictly specifying the endpoint port (HTTP-based RPC), assuming - // we're directly trying to connect to solana-validator's ws listening port. - // When the endpoint omits the port, we're connecting to the protocol - // default ports: http(80) or https(443) and it's assumed we're behind a reverse - // proxy which manages WebSocket upgrade and backend port redirection. - if (url.port !== "") { - url.port = String(Number(url.port) + 1); - } return url.toString(); } From 36d09e54d3776f60206c79869f6de4e491682a26 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Thu, 30 Jun 2022 14:05:13 +0000 Subject: [PATCH 2/2] Improve docs --- pyth-common-js/src/PriceServiceConnection.ts | 2 +- pyth-common-js/src/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index 0509f12..2e4922f 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -61,7 +61,7 @@ export class PriceServiceConnection { /** * Constructs a new Connection. * - * @param endpoint endpoint URL to the price service. Example: https://website/example + * @param endpoint endpoint URL to the price service. Example: https://website/example/ * @param config Optional PriceServiceConnectionConfig for custom configurations. */ constructor(endpoint: string, config?: PriceServiceConnectionConfig) { diff --git a/pyth-common-js/src/utils.ts b/pyth-common-js/src/utils.ts index ed02be1..0bba9ca 100644 --- a/pyth-common-js/src/utils.ts +++ b/pyth-common-js/src/utils.ts @@ -1,7 +1,7 @@ /** * Convert http(s) endpoint to ws(s) endpoint. * - * @param endpoint Http(s) protocol endpoint. + * @param endpoint Http(s) protocol endpoint * @returns Ws(s) protocol endpoint of the same address */ export function makeWebsocketUrl(endpoint: string) {