|
| 1 | +import logging |
1 | 2 | import os
|
| 3 | +import json |
2 | 4 | import socketserver
|
3 | 5 | import subprocess
|
4 | 6 | import sys
|
| 7 | +from http.client import HTTPConnection |
5 | 8 |
|
6 | 9 | # Settings specific to local devnet Pyth instance
|
7 | 10 | PYTH = os.environ.get("PYTH", "./pyth")
|
|
17 | 20 | # How long to sleep between mock Pyth price updates
|
18 | 21 | PYTH_PUBLISHER_INTERVAL_SECS = float(os.environ.get("PYTH_PUBLISHER_INTERVAL_SECS", "5"))
|
19 | 22 | PYTH_TEST_SYMBOL_COUNT = int(os.environ.get("PYTH_TEST_SYMBOL_COUNT", "11"))
|
| 23 | +PYTH_DYNAMIC_SYMBOL_COUNT = int(os.environ.get("PYTH_DYNAMIC_SYMBOL_COUNT", "3")) |
20 | 24 |
|
21 | 25 | # If above 0, adds a new test symbol periodically, waiting at least
|
22 | 26 | # the given number of seconds in between
|
23 | 27 | #
|
24 | 28 | # NOTE: the new symbols are added in the HTTP endpoint used by the
|
25 | 29 | # p2w-attest service in Tilt. You may need to wait to see p2w-attest
|
26 | 30 | # pick up brand new symbols
|
27 |
| -PYTH_NEW_SYMBOL_INTERVAL_SECS = int(os.environ.get("PYTH_NEW_SYMBOL_INTERVAL_SECS", "120")) |
| 31 | +PYTH_NEW_SYMBOL_INTERVAL_SECS = int(os.environ.get("PYTH_NEW_SYMBOL_INTERVAL_SECS", "30")) |
28 | 32 |
|
29 | 33 | PYTH_MAPPING_KEYPAIR = os.environ.get(
|
30 | 34 | "PYTH_MAPPING_KEYPAIR", f"{PYTH_KEY_STORE}/mapping_key_pair.json"
|
@@ -108,6 +112,24 @@ def sol_run_or_die(subcommand, args=[], **kwargs):
|
108 | 112 | return run_or_die(["solana", subcommand] + args + ["--url", SOL_RPC_URL], **kwargs)
|
109 | 113 |
|
110 | 114 |
|
| 115 | +def get_json(host, port, path): |
| 116 | + conn = HTTPConnection(host, port) |
| 117 | + conn.request("GET", path) |
| 118 | + res = conn.getresponse() |
| 119 | + |
| 120 | + # starstwith because the header value may include optional fields after (like charset) |
| 121 | + if res.getheader("Content-Type").startswith("application/json"): |
| 122 | + return json.load(res) |
| 123 | + else: |
| 124 | + logging.error(f"Error getting {host}:{port}{path} : Content-Type was not application/json") |
| 125 | + logging.error(f"HTTP response code: {res.getcode()}") |
| 126 | + logging.error(f"HTTP headers: {res.getheaders()}") |
| 127 | + logging.error(f"Message: {res.msg}") |
| 128 | + sys.exit(1) |
| 129 | + |
| 130 | +def get_pyth_accounts(host, port): |
| 131 | + return get_json(host, port, "/") |
| 132 | + |
111 | 133 | class ReadinessTCPHandler(socketserver.StreamRequestHandler):
|
112 | 134 | def handle(self):
|
113 | 135 | """TCP black hole"""
|
|
0 commit comments