Skip to content
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

Added type annotation to some functions to make the code more readable. #51

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions pythclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Library-wide settings.
"""

backoff_max_value = 16
backoff_max_tries = 8
BACKOFF_MAX_VALUE = 16
BACKOFF_MAX_TRIES = 8

# The following getter functions are passed to the backoff decorators

def get_backoff_max_value():
return backoff_max_value
def get_backoff_max_value() -> int:
return BACKOFF_MAX_VALUE

def get_backoff_max_tries():
return backoff_max_tries
def get_backoff_max_tries() -> int:
return BACKOFF_MAX_TRIES
12 changes: 6 additions & 6 deletions pythclient/price_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class Price:
def __init__(self, conf, expo, price, publish_time):
def __init__(self, conf, expo, price, publish_time) -> None:
self.conf = conf
self.expo = expo
self.price = price
Expand All @@ -38,7 +38,7 @@ def to_dict(self):


class PriceUpdate:
def __init__(self, ema_price, price_id, price):
def __init__(self, ema_price, price_id, price) -> None:
self.ema_price = ema_price
self.id = price_id
self.price = price
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(
last_attested_publish_time,
price_feed,
emitter_chain_id,
):
) -> None:
self.seq_num = seq_num
self.vaa = vaa
self.publish_time = publish_time
Expand Down Expand Up @@ -117,7 +117,7 @@ def to_dict(self, verbose=False, vaa_format=DEFAULT_VAA_ENCODING):
class MerkleUpdate:
def __init__(
self, message_size: int, message: bytes, proof_size: int, proof: List[bytes]
):
) -> None:
self.message_size = message_size
self.message = message
self.proof_size = proof_size
Expand All @@ -142,7 +142,7 @@ def __init__(
vaa: bytes,
num_updates: int,
updates: List[MerkleUpdate],
):
) -> None:
self.magic = magic
self.major_version = major_version
self.minor_version = minor_version
Expand Down Expand Up @@ -195,7 +195,7 @@ def encode_vaa_for_chain(vaa: str, vaa_format: str, buffer=False) -> Union[bytes


# Referenced from https://github.com/wormhole-foundation/wormhole/blob/main/sdk/js/src/vaa/wormhole.ts#L26-L56
def parse_vaa(vaa, encoding):
def parse_vaa(vaa: str, encoding: str) -> dict:
vaa = cast(bytes, encode_vaa_for_chain(vaa, encoding, buffer=True))

num_signers = vaa[5]
Expand Down
2 changes: 1 addition & 1 deletion pythclient/pythaccounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _read_attribute_string(buffer: bytes, offset: int) -> Tuple[Optional[str], i
return data.decode('utf8', 'replace'), data_end


def _parse_header(buffer: bytes, offset: int = 0, *, key: SolanaPublicKeyOrStr):
def _parse_header(buffer: bytes, offset: int = 0, *, key: SolanaPublicKeyOrStr) -> Tuple[PythAccountType, int, int]:
if len(buffer) - offset < _ACCOUNT_HEADER_BYTES:
raise ValueError("Pyth account data too short")

Expand Down