-
Notifications
You must be signed in to change notification settings - Fork 32
support pythtest-conformance and pythtest-crosschain #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,42 @@ | ||
| import ast | ||
| import dns.resolver | ||
cctdaniel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from loguru import logger | ||
| from typing import Optional | ||
|
|
||
| from loguru import logger | ||
cctdaniel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| DEFAULT_VERSION = "v2" | ||
|
|
||
|
|
||
| # Retrieving keys via DNS TXT records should not be considered secure and is provided as a convenience only. | ||
cctdaniel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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": | ||
cctdaniel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
|
|
||
| setup( | ||
| name='pythclient', | ||
| version='0.1.19', | ||
| version='0.1.20', | ||
| packages=['pythclient'], | ||
| author='Pyth Developers', | ||
| author_email='[email protected]', | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?