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

fix add_feed_ids bug #55

Merged
merged 1 commit into from
Feb 22, 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
11 changes: 8 additions & 3 deletions pythclient/hermes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ async def get_price_feed_ids(self) -> list[str]:
return data

def add_feed_ids(self, feed_ids: list[str]):
self.feed_ids += feed_ids
self.feed_ids = list(set(self.feed_ids))
self.pending_feed_ids += feed_ids
# convert feed_ids to a set to remove any duplicates from the input
new_feed_ids_set = set(feed_ids)

# update self.feed_ids; convert to set for union operation, then back to list
self.feed_ids = list(set(self.feed_ids).union(new_feed_ids_set))

# update self.pending_feed_ids with only those IDs that are truly new
self.pending_feed_ids = list(set(self.pending_feed_ids).union(new_feed_ids_set))
Copy link
Contributor

Choose a reason for hiding this comment

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

i guess this is just making sure no duplicates in pending_feed_ids? I don't think it matters too much bc there's an implicit redundancy check at the rust websocket level, but this is fine


@staticmethod
def extract_price_feed_v1(data: dict) -> PriceFeed:
Expand Down
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.23',
version='0.1.24',
packages=['pythclient'],
author='Pyth Developers',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hermes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def test_hermes_add_feed_ids(hermes_client: HermesClient, mock_get_price_f

assert len(set(hermes_client.feed_ids)) == len(hermes_client.feed_ids)
assert set(hermes_client.feed_ids) == set(feed_ids_pre + feed_ids)
assert set(hermes_client.pending_feed_ids) == set(pending_feed_ids_pre + feed_ids)
assert len(hermes_client.pending_feed_ids) == len(set(pending_feed_ids_pre + feed_ids))

def test_hermes_extract_price_feed_v1(hermes_client: HermesClient, data_v1: dict):
price_feed = hermes_client.extract_price_feed_v1(data_v1)
Expand Down
Loading