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

Commit 7a9875e

Browse files
authored
Merge pull request #84 from pyth-network/get-vaa
add getVaa function
2 parents 5cf8e66 + ea26e6c commit 7a9875e

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

pyth-common-js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyth-common-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-common-js",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Pyth Network Common Utils in JS",
55
"author": {
66
"name": "Pyth Data Association"

pyth-common-js/src/PriceServiceConnection.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,31 @@ export class PriceServiceConnection {
149149
return response.data;
150150
}
151151

152+
/**
153+
* Fetch the earliest VAA of the given price id that is published since the given publish time.
154+
* This will throw an error if the given publish time is in the future, or if the publish time
155+
* is old and the price service endpoint does not have a db backend for historical requests.
156+
* This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id)
157+
*
158+
* This function is coupled to wormhole implemntation.
159+
*
160+
* @param priceId Hex-encoded price id.
161+
* @param publishTime Epoch timestamp in seconds.
162+
* @returns Tuple of VAA and publishTime.
163+
*/
164+
async getVaa(
165+
priceId: HexString,
166+
publishTime: EpochTimeStamp
167+
): Promise<[string, EpochTimeStamp]> {
168+
const response = await this.httpClient.get("/api/get_vaa", {
169+
params: {
170+
id: priceId,
171+
publish_time: publishTime,
172+
},
173+
});
174+
return [response.data.vaa, response.data.publishTime];
175+
}
176+
152177
/**
153178
* Fetch the list of available price feed ids.
154179
* This will throw an axios error if there is a network problem or the price service returns a non-ok response.

0 commit comments

Comments
 (0)