Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
agora/client: add app-index header
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 9a92b972ea71d399a2d1fa691bd30e209933ccc5
  • Loading branch information
kikengineering committed May 18, 2021
1 parent 9a17a98 commit fbdb884
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion agora/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __init__(
LimitStrategy(retry_config.max_nonce_refreshes + 1)
]

self._internal_client = InternalClient(self._grpc_channel, self._internal_retry_strategies)
self._internal_client = InternalClient(self._grpc_channel, self._internal_retry_strategies, self._app_index)

self._default_commitment = default_commitment

Expand Down
17 changes: 12 additions & 5 deletions agora/client/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,25 @@ class InternalClient:
"""

def __init__(
self, grpc_channel: grpc.Channel, retry_strategies: List[Strategy],
self, grpc_channel: grpc.Channel, retry_strategies: List[Strategy], app_index: int = 0,
):
self._account_stub_v4 = account_pb_grpc.AccountStub(grpc_channel)
self._transaction_stub_v4 = tx_pb_grpc.TransactionStub(grpc_channel)
self._airdrop_stub_v4 = airdrop_pb_grpc.AirdropStub(grpc_channel)

self._retry_strategies = retry_strategies

self._metadata = (
user_agent(VERSION),
('kin-version', "4"),
)
if app_index > 0:
self._metadata = (
user_agent(VERSION),
('kin-version', "4"),
('app-index', str(app_index)),
)
else:
self._metadata = (
user_agent(VERSION),
('kin-version', "4"),
)

# Currently only service config is cached, so limit to 1 entry
self._response_cache = LRUCache(300, 1)
Expand Down
2 changes: 1 addition & 1 deletion tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def _assert_user_agent(md):

@staticmethod
def _assert_kin_4_md(md: Tuple[Tuple, ...]):
assert len(md) == 3
assert len(md) >= 3
assert md[0] == user_agent(VERSION)
assert md[1] == ('kin-version', '4')

Expand Down
5 changes: 4 additions & 1 deletion tests/client/test_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,12 @@ def _set_get_min_balance_response(

@staticmethod
def _assert_metadata(md: Tuple[Tuple, ...]):
assert len(md) == 3
assert len(md) >= 3
assert md[0] == user_agent(VERSION)
assert md[1] == ('kin-version', '4')
if len(md) == 4:
assert md[2] == ('app-index', '1')


@staticmethod
def _gen_tx():
Expand Down

0 comments on commit fbdb884

Please sign in to comment.