-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from InjectiveLabs/fix/pagination_next_key
Fix/pagination next key
- Loading branch information
Showing
9 changed files
with
564 additions
and
488 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import asyncio | ||
|
||
from pyinjective.async_client import AsyncClient | ||
from pyinjective.client.model.pagination import PaginationOption | ||
from pyinjective.core.network import Network | ||
|
||
|
||
async def main() -> None: | ||
network = Network.testnet() | ||
client = AsyncClient(network) | ||
pagination = PaginationOption( | ||
limit=10, | ||
count_total=True, | ||
) | ||
first_result = await client.fetch_total_supply( | ||
pagination=pagination, | ||
) | ||
print(f"First result:\n{first_result}") | ||
|
||
next_page_key = first_result["pagination"]["nextKey"] | ||
|
||
for i in range(5): | ||
if next_page_key == "": | ||
break | ||
|
||
next_request_pagination = PaginationOption( | ||
limit=pagination.limit, | ||
count_total=pagination.count_total, | ||
encoded_page_key=next_page_key, | ||
) | ||
|
||
next_result = await client.fetch_total_supply( | ||
pagination=next_request_pagination, | ||
) | ||
print(f"Page {i+2} result:\n{next_result}") | ||
|
||
next_page_key = next_result["pagination"]["nextKey"] | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.get_event_loop().run_until_complete(main()) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "injective-py" | ||
version = "1.5.2" | ||
version = "1.5.3" | ||
description = "Injective Python SDK, with Exchange API Client" | ||
authors = ["Injective Labs <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
This file contains 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
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import base64 | ||
|
||
from pyinjective.client.model.pagination import PaginationOption | ||
|
||
|
||
class TestPaginationOption: | ||
def test_create_pagination_request(self): | ||
next_page_key = b"next page key" | ||
encoded_next_page_key = base64.b64encode(next_page_key).decode() | ||
pagination_option = PaginationOption( | ||
encoded_page_key=encoded_next_page_key, | ||
skip=5, | ||
limit=10, | ||
start_time=3, | ||
end_time=4, | ||
reverse=False, | ||
count_total=True, | ||
from_number=105, | ||
to_number=135, | ||
) | ||
|
||
page_request = pagination_option.create_pagination_request() | ||
assert page_request.key == next_page_key | ||
assert page_request.offset == pagination_option.skip | ||
assert page_request.limit == pagination_option.limit | ||
assert not page_request.reverse | ||
assert page_request.count_total | ||
|
||
def test_next_key_is_none_for_empty_encoded_page_key(self): | ||
pagination_option = PaginationOption( | ||
encoded_page_key="", | ||
) | ||
page_request = pagination_option.create_pagination_request() | ||
|
||
assert page_request.key == b"" |