Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit ee23266

Browse files
authored
Update endpoints (#15)
* Update endpoints ws is now /ws and all rest apis are /api/* * Improve docs
1 parent 492e2c9 commit ee23266

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

pyth-common-js/src/PriceServiceConnection.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { makeWebsocketUrl } from "./utils";
99
export type DurationInMs = number;
1010

1111
export type PriceServiceConnectionConfig = {
12-
/* Optional websocket endpoint of the price service if it has host/port other than the endpoint. */
13-
wsEndpoint?: string;
1412
/* Timeout of each request (for all of retries). Default: 5000ms */
1513
timeout?: DurationInMs;
1614
/**
@@ -63,7 +61,7 @@ export class PriceServiceConnection {
6361
/**
6462
* Constructs a new Connection.
6563
*
66-
* @param endpoint endpoint URL to the price service. Example: https://website/example
64+
* @param endpoint endpoint URL to the price service. Example: https://website/example/
6765
* @param config Optional PriceServiceConnectionConfig for custom configurations.
6866
*/
6967
constructor(endpoint: string, config?: PriceServiceConnectionConfig) {
@@ -82,7 +80,7 @@ export class PriceServiceConnection {
8280
this.logger?.error(error);
8381
};
8482

85-
this.wsEndpoint = config?.wsEndpoint || makeWebsocketUrl(endpoint);
83+
this.wsEndpoint = makeWebsocketUrl(endpoint);
8684
}
8785

8886
/**
@@ -99,7 +97,7 @@ export class PriceServiceConnection {
9997
return [];
10098
}
10199

102-
const response = await this.httpClient.get("/latest_price_feeds", {
100+
const response = await this.httpClient.get("/api/latest_price_feeds", {
103101
params: {
104102
ids: priceIds,
105103
},
@@ -122,7 +120,7 @@ export class PriceServiceConnection {
122120
* @returns Array of base64 encoded VAAs.
123121
*/
124122
protected async getLatestVaas(priceIds: HexString[]): Promise<string[]> {
125-
const response = await this.httpClient.get("/latest_vaas", {
123+
const response = await this.httpClient.get("/api/latest_vaas", {
126124
params: {
127125
ids: priceIds,
128126
},

pyth-common-js/src/examples/PriceServiceClient.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ const argv = yargs(hideBin(process.argv))
1414
type: "string",
1515
required: true,
1616
})
17-
.option("wsEndpoint", {
18-
description:
19-
"Optional web socket endpoint for the price service if it's different than endpoint. e.g: wss://endpoint/example",
20-
type: "string",
21-
required: false,
22-
})
2317
.option("price-ids", {
2418
description:
2519
"Space separated price feed ids (in hex without leading 0x) to fetch." +
@@ -33,7 +27,6 @@ const argv = yargs(hideBin(process.argv))
3327

3428
async function run() {
3529
const connection = new PriceServiceConnection(argv.endpoint, {
36-
wsEndpoint: argv.wsEndpoint,
3730
logger: console, // Providing logger will allow the connection to log it's events.
3831
});
3932

pyth-common-js/src/utils.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@
55
* @returns Ws(s) protocol endpoint of the same address
66
*/
77
export function makeWebsocketUrl(endpoint: string) {
8-
const url = new URL(endpoint);
8+
const url = new URL("ws", endpoint);
99
const useHttps = url.protocol === "https:";
1010

1111
url.protocol = useHttps ? "wss:" : "ws:";
12-
url.host = "";
1312

14-
// Only shift the port by +1 as a convention for ws(s) only if given endpoint
15-
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
16-
// we're directly trying to connect to solana-validator's ws listening port.
17-
// When the endpoint omits the port, we're connecting to the protocol
18-
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
19-
// proxy which manages WebSocket upgrade and backend port redirection.
20-
if (url.port !== "") {
21-
url.port = String(Number(url.port) + 1);
22-
}
2313
return url.toString();
2414
}

0 commit comments

Comments
 (0)