Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file.
### Added
- Added support for all queries in the chain 'tendermint' module

### Changed
- Refactored cookies management logic to use all gRPC calls' responses to update the current cookies

## [1.4.1] - 2024-03-12
### Changed
- Updates example scripts that were still using deprecated methods
Comment on lines 6 to 14
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [51-51]

The term "low level API components" is correctly used in the context of software development. However, when used as a compound adjective before a noun, it's typically hyphenated. Consider revising for clarity.

- Added low level API components for all modules
+ Added low-level API components for all modules

Expand Down
190 changes: 48 additions & 142 deletions pyinjective/async_client.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_auction_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.injective.auction.v1beta1 import (
query_pb2 as auction_query_pb,
query_pb2_grpc as auction_query_grpc,
Expand All @@ -10,9 +11,9 @@


class ChainGrpcAuctionApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = auction_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_module_params(self) -> Dict[str, Any]:
request = auction_query_pb.QueryAuctionParamsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.cosmos.auth.v1beta1 import query_pb2 as auth_query_pb, query_pb2_grpc as auth_query_grpc
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant


class ChainGrpcAuthApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = auth_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_module_params(self) -> Dict[str, Any]:
request = auth_query_pb.QueryParamsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_authz_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.cosmos.authz.v1beta1 import query_pb2 as authz_query, query_pb2_grpc as authz_query_grpc
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant


class ChainGrpcAuthZApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = authz_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_grants(
self,
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_bank_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.cosmos.bank.v1beta1 import query_pb2 as bank_query_pb, query_pb2_grpc as bank_query_grpc
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant


class ChainGrpcBankApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = bank_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_module_params(self) -> Dict[str, Any]:
request = bank_query_pb.QueryParamsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_distribution_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.cosmos.distribution.v1beta1 import (
query_pb2 as distribution_query_pb,
query_pb2_grpc as distribution_query_grpc,
Expand All @@ -11,9 +12,9 @@


class ChainGrpcDistributionApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = distribution_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_module_params(self) -> Dict[str, Any]:
request = distribution_query_pb.QueryParamsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_exchange_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.injective.exchange.v1beta1 import (
query_pb2 as exchange_query_pb,
query_pb2_grpc as exchange_query_grpc,
Expand All @@ -11,9 +12,9 @@


class ChainGrpcExchangeApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = exchange_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_exchange_params(self) -> Dict[str, Any]:
request = exchange_query_pb.QueryExchangeParamsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_token_factory_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.injective.tokenfactory.v1beta1 import (
query_pb2 as token_factory_query_pb,
query_pb2_grpc as token_factory_query_grpc,
Expand All @@ -11,10 +12,10 @@


class ChainGrpcTokenFactoryApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._query_stub = token_factory_query_grpc.QueryStub(channel)
self._tx_stub = token_factory_tx_grpc.MsgStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)
Comment on lines +15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification process aimed to identify instances of ChainGrpcTokenFactoryApi being instantiated without passing the cookie_assistant parameter, as required by the updated __init__ method signature. The initial script found one such instance in pyinjective/async_client.py. A follow-up script was executed to search for any additional instances that might have been missed due to syntax variations or being located in different files, excluding the already identified instance in async_client.py. The follow-up script did not produce any output, indicating that no additional instances were found.

Given this information, it can be concluded that the only instance requiring modification to comply with the updated __init__ method signature of ChainGrpcTokenFactoryApi is the one found in pyinjective/async_client.py. This confirms the validity of the original review comment, highlighting the need to ensure that all instances of ChainGrpcTokenFactoryApi throughout the codebase are updated to pass the CookieAssistant instance.

Based on the verification process and the results obtained, the appropriate tag for this response is , as the review comment is validated by the evidence from the codebase, identifying a specific issue that needs to be addressed.

Analysis chain

The __init__ method of ChainGrpcTokenFactoryApi has been updated to use cookie_assistant instead of metadata_provider. This change aligns with the PR's objective to optimize cookie handling. Ensure that all instances of ChainGrpcTokenFactoryApi throughout the codebase are updated to pass the CookieAssistant instance.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for instances of ChainGrpcTokenFactoryApi being instantiated without cookie_assistant.
rg --type py "ChainGrpcTokenFactoryApi\(" | grep -v "cookie_assistant"

Length of output: 157



Script:

#!/bin/bash
# View the instantiation of ChainGrpcTokenFactoryApi in pyinjective/async_client.py
fd async_client.py --exec cat {}

Length of output: 145365


Script:

#!/bin/bash
# Perform a more nuanced search for ChainGrpcTokenFactoryApi instantiation to catch any instances missed due to syntax variations
rg --type py "ChainGrpcTokenFactoryApi\(" | grep -v "cookie_assistant" | grep -v "async_client.py"

Length of output: 96


async def fetch_module_params(self) -> Dict[str, Any]:
request = token_factory_query_pb.QueryParamsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/chain/grpc/chain_grpc_wasm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.cosmwasm.wasm.v1 import query_pb2 as wasm_query_pb, query_pb2_grpc as wasm_query_grpc
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant


class ChainGrpcWasmApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = wasm_query_grpc.QueryStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_module_params(self) -> Dict[str, Any]:
request = wasm_query_pb.QueryParamsRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.injective.stream.v1beta1 import query_pb2 as chain_stream_pb, query_pb2_grpc as chain_stream_grpc
from pyinjective.utils.grpc_api_stream_assistant import GrpcApiStreamAssistant


class ChainGrpcChainStream:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = chain_stream_grpc.StreamStub(channel)
self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant)

async def stream(
self,
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_accounts_rpc_pb2 as exchange_accounts_pb,
injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc,
Expand All @@ -11,9 +12,9 @@


class IndexerGrpcAccountApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_accounts_grpc.InjectiveAccountsRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_portfolio(self, account_address: str) -> Dict[str, Any]:
request = exchange_accounts_pb.PortfolioRequest(account_address=account_address)
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_auction_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_auction_rpc_pb2 as exchange_auction_pb,
injective_auction_rpc_pb2_grpc as exchange_auction_grpc,
Expand All @@ -10,9 +11,9 @@


class IndexerGrpcAuctionApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_auction_grpc.InjectiveAuctionRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_auction(self, round: int) -> Dict[str, Any]:
request = exchange_auction_pb.AuctionEndpointRequest(round=round)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_derivative_exchange_rpc_pb2 as exchange_derivative_pb,
injective_derivative_exchange_rpc_pb2_grpc as exchange_derivative_grpc,
Expand All @@ -11,9 +12,9 @@


class IndexerGrpcDerivativeApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_derivative_grpc.InjectiveDerivativeExchangeRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_markets(
self,
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_explorer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_explorer_rpc_pb2 as exchange_explorer_pb,
injective_explorer_rpc_pb2_grpc as exchange_explorer_grpc,
Expand All @@ -11,9 +12,9 @@


class IndexerGrpcExplorerApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_explorer_grpc.InjectiveExplorerRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_account_txs(
self,
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_insurance_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_insurance_rpc_pb2 as exchange_insurance_pb,
injective_insurance_rpc_pb2_grpc as exchange_insurance_grpc,
Expand All @@ -10,9 +11,9 @@


class IndexerGrpcInsuranceApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_insurance_grpc.InjectiveInsuranceRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_insurance_funds(self) -> Dict[str, Any]:
request = exchange_insurance_pb.FundsRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_meta_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_meta_rpc_pb2 as exchange_meta_pb,
injective_meta_rpc_pb2_grpc as exchange_meta_grpc,
Expand All @@ -11,9 +12,9 @@


class IndexerGrpcMetaApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_meta_grpc.InjectiveMetaRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_ping(self) -> Dict[str, Any]:
request = exchange_meta_pb.PingRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_oracle_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_oracle_rpc_pb2 as exchange_oracle_pb,
injective_oracle_rpc_pb2_grpc as exchange_oracle_grpc,
Expand All @@ -10,9 +11,9 @@


class IndexerGrpcOracleApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_oracle_grpc.InjectiveOracleRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_oracle_list(self) -> Dict[str, Any]:
request = exchange_oracle_pb.OracleListRequest()
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_portfolio_rpc_pb2 as exchange_portfolio_pb,
injective_portfolio_rpc_pb2_grpc as exchange_portfolio_grpc,
Expand All @@ -10,9 +11,9 @@


class IndexerGrpcPortfolioApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_portfolio_grpc.InjectivePortfolioRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_account_portfolio(self, account_address: str) -> Dict[str, Any]:
request = exchange_portfolio_pb.AccountPortfolioRequest(account_address=account_address)
Expand Down
5 changes: 3 additions & 2 deletions pyinjective/client/indexer/grpc/indexer_grpc_spot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_spot_exchange_rpc_pb2 as exchange_spot_pb,
injective_spot_exchange_rpc_pb2_grpc as exchange_spot_grpc,
Expand All @@ -11,9 +12,9 @@


class IndexerGrpcSpotApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_spot_grpc.InjectiveSpotExchangeRPCStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiRequestAssistant(cookie_assistant=cookie_assistant)

async def fetch_markets(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from grpc.aio import Channel

from pyinjective.core.network import CookieAssistant
from pyinjective.proto.exchange import (
injective_accounts_rpc_pb2 as exchange_accounts_pb,
injective_accounts_rpc_pb2_grpc as exchange_accounts_grpc,
Expand All @@ -10,9 +11,9 @@


class IndexerGrpcAccountStream:
def __init__(self, channel: Channel, metadata_provider: Callable):
def __init__(self, channel: Channel, cookie_assistant: CookieAssistant):
self._stub = self._stub = exchange_accounts_grpc.InjectiveAccountsRPCStub(channel)
self._assistant = GrpcApiStreamAssistant(metadata_provider=metadata_provider)
self._assistant = GrpcApiStreamAssistant(cookie_assistant=cookie_assistant)

async def stream_subaccount_balance(
self,
Expand Down
Loading