Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pythclient/solana.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
TESTNET_ENDPOINT = "api.testnet.solana.com"
MAINNET_ENDPOINT = "api.mainnet-beta.solana.com"
PYTHNET_ENDPOINT = "pythnet.rpcpool.com"
PYTHTEST_CROSSCHAIN_ENDPOINT = "api.pythtest.pyth.network"
PYTHTEST_CONFORMANCE_ENDPOINT = "api.pythtest.pyth.network"

SOLANA_DEVNET_WS_ENDPOINT = WS_PREFIX + "://" + DEVNET_ENDPOINT
SOLANA_DEVNET_HTTP_ENDPOINT = HTTP_PREFIX + "://" + DEVNET_ENDPOINT
Expand All @@ -33,6 +35,12 @@
PYTHNET_WS_ENDPOINT = WS_PREFIX + "://" + PYTHNET_ENDPOINT
PYTHNET_HTTP_ENDPOINT = HTTP_PREFIX + "://" + PYTHNET_ENDPOINT

PYTHTEST_CROSSCHAIN_WS_ENDPOINT = WS_PREFIX + "://" + PYTHTEST_CROSSCHAIN_ENDPOINT
PYTHTEST_CROSSCHAIN_HTTP_ENDPOINT = HTTP_PREFIX + "://" + PYTHTEST_CROSSCHAIN_ENDPOINT

PYTHTEST_CONFORMANCE_WS_ENDPOINT = WS_PREFIX + "://" + PYTHTEST_CONFORMANCE_ENDPOINT
PYTHTEST_CONFORMANCE_HTTP_ENDPOINT = HTTP_PREFIX + "://" + PYTHTEST_CONFORMANCE_ENDPOINT

class SolanaPublicKey:
"""
Represents a Solana public key. This class is meant to be immutable.
Expand Down
60 changes: 33 additions & 27 deletions pythclient/utils.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use hardcoded mapping values instead of DNS TXT record since these values dont change that often anyway

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, who is using these dns values?

Copy link
Contributor Author

@cctdaniel cctdaniel Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually dont know who updates these values, maybe @thmzlt has an idea?

Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
import ast
import dns.resolver
from loguru import logger
from typing import Optional

from loguru import logger

DEFAULT_VERSION = "v2"


# Retrieving keys via DNS TXT records should not be considered secure and is provided as a convenience only.
# Accounts should be stored locally and verified before being used for production.
def get_key(network: str, type: str, version: str = DEFAULT_VERSION) -> Optional[str]:
def get_key(network: str, type: str) -> Optional[str]:
"""
Get the program or mapping keys from dns TXT records.
Example dns records:
devnet-program-v2.pyth.network
mainnet-program-v2.pyth.network
testnet-mapping-v2.pyth.network
pythnet-mapping-v2.pyth.network
Get the program or mapping key.
:param network: The network to get the key for. Either "mainnet", "devnet", "testnet", "pythnet", "pythtest-conformance", or "pythtest-crosschain".
:param type: The type of key to get. Either "program" or "mapping".
"""
url = f"{network}-{type}-{version}.pyth.network"
try:
answer = dns.resolver.resolve(url, "TXT")
except dns.resolver.NXDOMAIN:
logger.error("TXT record for {} not found", url)
return ""
if len(answer) != 1:
logger.error("Invalid number of records returned for {}!", url)
return ""
# Example of the raw_key:
# "program=FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH"
raw_key = ast.literal_eval(list(answer)[0].to_text())
# program=FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH"
_, key = raw_key.split("=", 1)
return key
if network == "pythnet":
program_key = "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH"
mapping_key = "AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"
elif network == "mainnet":
program_key = "FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH"
mapping_key = "AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"
elif network == "devnet":
program_key = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s"
mapping_key = "BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2"
elif network == "testnet":
program_key = "8tfDNiaEyrV6Q1U4DEXrEigs9DoDtkugzFbybENEbCDz"
mapping_key = "AFmdnt9ng1uVxqCmqwQJDAYC5cKTkw8gJKSM5PnzuF6z"
elif network == "pythtest-conformance":
program_key = "8tfDNiaEyrV6Q1U4DEXrEigs9DoDtkugzFbybENEbCDz"
mapping_key = "AFmdnt9ng1uVxqCmqwQJDAYC5cKTkw8gJKSM5PnzuF6z"
elif network == "pythtest-crosschain":
program_key = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s"
mapping_key = "BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2"
else:
raise Exception(f"Unknown network: {network}")

if type == "program":
return program_key
elif type == "mapping":
return mapping_key
else:
raise Exception(f"Unknown type: {type}")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='pythclient',
version='0.1.19',
version='0.1.20',
packages=['pythclient'],
author='Pyth Developers',
author_email='[email protected]',
Expand Down