Skip to content

Commit 166e0b6

Browse files
authoredJan 16, 2023
Merge pull request #54 from pyth-network/guibescos/support-arbitrary-metadata
Arbitrary product metadata
2 parents ef91b1e + 609db6f commit 166e0b6

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed
 

‎src/PythConnection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class PythConnection {
4646
data: productData,
4747
},
4848
}
49-
if (productData.priceAccountKey.toString() !== ONES) {
49+
if (productData.priceAccountKey) {
5050
this.priceAccountKeyToProductAccountKey[productData.priceAccountKey.toString()] = key.toString()
5151
}
5252
}

‎src/__tests__/Example.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('Mapping', (done) => {
2020
return
2121
}
2222
const { product, priceAccountKey } = parseProductData(accountInfo.data)
23-
connection.getAccountInfo(priceAccountKey).then((accountInfo) => {
23+
connection.getAccountInfo(priceAccountKey!).then((accountInfo) => {
2424
if (!accountInfo) {
2525
done('No price accountInfo')
2626
return

‎src/__tests__/Price.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('Price', (done) => {
2323
connection.getAccountInfo(mapping.productAccountKeys[0]).then((accountInfo) => {
2424
if (accountInfo && accountInfo.data) {
2525
const product = parseProductData(accountInfo.data)
26-
connection.getAccountInfo(product.priceAccountKey).then((accountInfo) => {
26+
connection.getAccountInfo(product.priceAccountKey!).then((accountInfo) => {
2727
if (accountInfo && accountInfo.data) {
2828
const price = parsePriceData(accountInfo.data)
2929
console.log(product.product.symbol)

‎src/index.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,11 @@ export interface MappingData extends Base {
5656
}
5757

5858
export interface Product {
59-
symbol: string
60-
asset_type: string
61-
quote_currency: string
62-
tenor: string
63-
price_account: string
6459
[index: string]: string
6560
}
6661

6762
export interface ProductData extends Base {
68-
priceAccountKey: PublicKey
63+
priceAccountKey: PublicKey | null
6964
product: Product
7065
}
7166

@@ -203,9 +198,9 @@ export const parseProductData = (data: Buffer): ProductData => {
203198
const size = data.readUInt32LE(12)
204199
// first price account in list
205200
const priceAccountBytes = data.slice(16, 48)
206-
const priceAccountKey = new PublicKey(priceAccountBytes)
201+
const priceAccountKey = PKorNull(priceAccountBytes)
207202
const product = {} as Product
208-
product.price_account = priceAccountKey.toBase58()
203+
if (priceAccountKey) product.price_account = priceAccountKey.toBase58()
209204
let idx = 48
210205
while (idx < size) {
211206
const keyLength = data[idx]

0 commit comments

Comments
 (0)
Please sign in to comment.