InjectiveLabs / sdk-python

Injective Exchange API for Python clients
Apache License 2.0
41 stars 29 forks source link

feat/add_ibc_transfer_support #317

Closed aarmoa closed 7 months ago

aarmoa commented 7 months ago

Solves CHAIN-74

Summary by CodeRabbit

coderabbitai[bot] commented 7 months ago

Walkthrough

This update significantly enhances the capabilities of the platform by integrating comprehensive support for IBC Transfer module queries, alongside the existing support for the 'tendermint' module. It streamlines the cookies management logic for gRPC calls and introduces a suite of functionalities for handling token transfers, querying denomination traces, hashes, and escrow information within the Injective Protocol environment.

Changes

File Path Change Summary
CHANGELOG.md Added support for IBC Transfer module queries; refactored cookies management.
examples/chain_client/ibc/transfer/1_MsgTransfer.py
examples/chain_client/ibc/transfer/query/...
Introduced scripts for token transfers and querying denomination traces, hashes, escrow addresses, and total escrow amounts in Injective Protocol.
pyinjective/async_client.py
pyinjective/composer.py
pyinjective/core/tx/grpc/ibc_transfer_grpc_api.py
Enhanced async client with IBC Transfer module functionalities; added methods for interacting with the IBCTransferGrpcApi.
tests/core/tx/grpc/...
tests/test_composer.py
Added tests for IBC Transfer module functionalities, including denom traces, hashes, escrow addresses, and message creation.

🐰✨
In the digital fields where data streams flow,
A rabbit hopped in, its eyes aglow.
With a flick and a hop, new paths it weaved,
Through IBC transfers, much was achieved.
"To the moon!" it cheered, with no delay,
As it bounded off, leading the way.
🚀🌕


Recent Review Details **Configuration used: .coderabbit.yaml**
Commits Files that changed from the base of the PR and between 1fae35f43ddbfa710c22073289890dfb21b4ab1c and 3d9761d37457d9ebddb18c31dbef9679d28e2309.
Files selected for processing (13) * CHANGELOG.md (1 hunks) * examples/chain_client/ibc/transfer/1_MsgTransfer.py (1 hunks) * examples/chain_client/ibc/transfer/query/1_DenomTrace.py (1 hunks) * examples/chain_client/ibc/transfer/query/2_DenomTraces.py (1 hunks) * examples/chain_client/ibc/transfer/query/3_DenomHash.py (1 hunks) * examples/chain_client/ibc/transfer/query/4_EscrowAddress.py (1 hunks) * examples/chain_client/ibc/transfer/query/5_TotalEscrowForDenom.py (1 hunks) * pyinjective/async_client.py (3 hunks) * pyinjective/composer.py (3 hunks) * pyinjective/core/tx/grpc/ibc_transfer_grpc_api.py (1 hunks) * tests/core/tx/grpc/configurable_ibc_transfer_query_servicer.py (1 hunks) * tests/core/tx/grpc/test_ibc_transfer_grpc_api.py (1 hunks) * tests/test_composer.py (1 hunks)
Additional comments not posted (17)
examples/chain_client/ibc/transfer/query/5_TotalEscrowForDenom.py (1)
`3-3`: Consider removing the unused `symbol_database` import to clean up the code.
examples/chain_client/ibc/transfer/query/4_EscrowAddress.py (1)
`3-3`: Consider removing the unused `symbol_database` import to clean up the code.
examples/chain_client/ibc/transfer/query/3_DenomHash.py (1)
`3-3`: Consider removing the unused `symbol_database` import to clean up the code.
examples/chain_client/ibc/transfer/query/2_DenomTraces.py (1)
`3-3`: Consider removing the unused `symbol_database` import to clean up the code.
examples/chain_client/ibc/transfer/query/1_DenomTrace.py (1)
`3-3`: Consider removing the unused `symbol_database` import to clean up the code.
tests/core/tx/grpc/configurable_ibc_transfer_query_servicer.py (1)
`1-37`: LGTM! The mock gRPC servicer implementation for IBC transfer queries is well-structured and serves its intended purpose effectively.
examples/chain_client/ibc/transfer/1_MsgTransfer.py (1)
`1-61`: LGTM! The script for creating and broadcasting an IBC transfer message is well-structured and demonstrates the intended functionality effectively.
pyinjective/core/tx/grpc/ibc_transfer_grpc_api.py (1)
`1-58`: LGTM! The `IBCTransferGrpcApi` class implementation is well-structured and provides a clean interface for interacting with the IBC Transfer module via gRPC.
tests/core/tx/grpc/test_ibc_transfer_grpc_api.py (4)
`15-17`: Consider using a more descriptive name for the fixture. A more descriptive name for the `ibc_transfer_servicer` fixture could improve readability. For example, `mock_ibc_transfer_servicer` would immediately convey that this is a mock object used for testing. --- `44-70`: Validate input parameters in `test_fetch_denom_trace`. It's important to ensure that the `hash` parameter passed to `api.fetch_denom_trace` is validated or sanitized before use, especially since it interacts with external systems or libraries. Consider adding a check or a note to verify that this is handled appropriately upstream. --- `72-116`: Optimize pagination handling in `test_fetch_denom_traces`. The pagination handling in `test_fetch_denom_traces` could be optimized by abstracting the pagination logic into a utility function or class. This would improve code reuse and maintainability, especially if pagination is a common pattern in your tests or application logic. --- `138-156`: Review error handling in `test_fetch_escrow_address`. Ensure that the `test_fetch_escrow_address` method properly handles errors or exceptions that may arise from the `api.fetch_escrow_address` call. This is crucial for resilience and reliability, especially in network-related operations.
CHANGELOG.md (2)
Line range hint `63-63`: Clarify the addition of logic for Client Order ID. The entry for version 1.0 mentions "Added logic to support use of Client Order ID (CID) new identifier in OrderInfo". It would be helpful to briefly explain why this addition is significant or how it improves the project, enhancing the changelog's informativeness. --- Line range hint `71-71`: Clarify the removal of `aiocron` dependency. The entry for version 1.0 mentions the removal of the `aiocron` dependency. Expanding on the reason for this removal and its impact on the project could provide valuable context to the readers of the changelog.
tests/test_composer.py (1)
`1434-1472`: The new test method `test_msg_ibc_transfer` is correctly implemented and thoroughly tests the IBC transfer message creation.
pyinjective/composer.py (1)
`2148-2175`: Consider adding a docstring to `msg_ibc_transfer`. The `msg_ibc_transfer` method lacks a docstring, which is crucial for understanding the purpose, parameters, and expected behavior of the method, especially for such a critical functionality as IBC transfers. Adding a comprehensive docstring would improve code maintainability and readability.
pyinjective/async_client.py (1)
`3021-3036`: Consider adding error handling for IBC Transfer module methods. The newly added methods for interacting with the IBC Transfer module (`fetch_denom_trace`, `fetch_denom_traces`, `fetch_denom_hash`, `fetch_escrow_address`, `fetch_total_escrow_for_denom`) currently do not include explicit error handling. It's advisable to implement error handling to manage potential exceptions or errors that may arise during the execution of these methods, ensuring the robustness and reliability of the application.
---
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.