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

Add params for client/api #163

Merged
merged 4 commits into from
Jun 17, 2022
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
10 changes: 6 additions & 4 deletions terra_sdk/client/lcd/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
from typing import Optional, Union

from ..params import APIParams
from terra_sdk.core import AccAddress
from terra_sdk.core.auth import (
Account,
Expand All @@ -16,7 +17,7 @@

class AsyncAuthAPI(BaseAsyncAPI):
async def account_info(
self, address: AccAddress
self, address: AccAddress, params: Optional[APIParams] = None
) -> Union[
BaseAccount,
ContinuousVestingAccount,
Expand All @@ -27,18 +28,19 @@ async def account_info(

Args:
address (AccAddress): account address
params (APIParams): optional parameters

Returns:
Union[BaseAccount, ContinuousVestingAccount, DelayedVestingAccount, PeriodicVestingAccount]: account information
"""
result = await self._c._get(f"/cosmos/auth/v1beta1/accounts/{address}")
result = await self._c._get(f"/cosmos/auth/v1beta1/accounts/{address}", params)
return Account.from_data(result["account"])


class AuthAPI(AsyncAuthAPI):
@sync_bind(AsyncAuthAPI.account_info)
def account_info(
self, address: AccAddress
self, address: AccAddress, params: Optional[APIParams] = None
) -> Union[
BaseAccount,
ContinuousVestingAccount,
Expand Down
4 changes: 2 additions & 2 deletions terra_sdk/client/lcd/api/bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def balance(
balance.__doc__ = AsyncBankAPI.balance.__doc__

@sync_bind(AsyncBankAPI.total)
def total(self) -> (Coins, dict):
def total(self, params: Optional[APIParams] = None) -> (Coins, dict):
pass

@sync_bind(AsyncBankAPI.spendable_balances)
def spendable_balances(self) -> (Coins, dict):
def spendable_balances(self, params: Optional[APIParams] = None) -> (Coins, dict):
pass

balance.__doc__ = AsyncBankAPI.balance.__doc__
Expand Down
44 changes: 27 additions & 17 deletions terra_sdk/client/lcd/api/distribution.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Dict
from typing import Dict, Optional

import attr

from terra_sdk.core import AccAddress, Coins, ValAddress

from ..params import APIParams
from ._base import BaseAsyncAPI, sync_bind

__all__ = ["AsyncDistributionAPI", "DistributionAPI", "Rewards"]
Expand All @@ -19,17 +19,19 @@ class Rewards:


class AsyncDistributionAPI(BaseAsyncAPI):
async def rewards(self, delegator: AccAddress) -> Rewards:
async def rewards(self, delegator: AccAddress, params: Optional[APIParams] = None) -> Rewards:
"""Fetches the staking reward data for a delegator.

Args:
delegator (AccAddress): delegator account address
params (APIParams): optional parameters

Returns:
Rewards: delegator rewards
"""
res = await self._c._get(
f"/cosmos/distribution/v1beta1/delegators/{delegator}/rewards"
f"/cosmos/distribution/v1beta1/delegators/{delegator}/rewards",
params
)
return Rewards(
rewards={
Expand All @@ -39,81 +41,89 @@ async def rewards(self, delegator: AccAddress) -> Rewards:
total=Coins.from_data(res["total"]),
)

async def validator_commission(self, validator: ValAddress) -> Coins:
async def validator_commission(self, validator: ValAddress, params: Optional[APIParams] = None) -> Coins:
"""Fetches the commission reward data for a validator.

Args:
validator (ValAddress): validator operator address
params (APIParams): optional parameters

Returns:
ValidatorCommission: validator rewards
"""
res = await self._c._get(
f"/cosmos/distribution/v1beta1/validators/{validator}/commission"
f"/cosmos/distribution/v1beta1/validators/{validator}/commission",
params
)
commission = res["commission"]
return Coins.from_data(commission["commission"])

async def withdraw_address(self, delegator: AccAddress) -> AccAddress:
async def withdraw_address(self, delegator: AccAddress, params: Optional[APIParams] = None) -> AccAddress:
"""Fetches the withdraw address associated with a delegator.

Args:
delegator (AccAddress): delegator account address
params (APIParams): optional parameters

Returns:
AccAddress: withdraw address
"""
res = await self._c._get(
f"/cosmos/distribution/v1beta1/delegators/{delegator}/withdraw_address"
f"/cosmos/distribution/v1beta1/delegators/{delegator}/withdraw_address",
params
)
return res.get("withdraw_address")

async def community_pool(self) -> Coins:
async def community_pool(self, params: Optional[APIParams] = None) -> Coins:
"""Fetches the community pool.
Args:
params (APIParams): optional parameters

Returns:
Coins: community pool
"""
res = await self._c._get("/cosmos/distribution/v1beta1/community_pool")
res = await self._c._get("/cosmos/distribution/v1beta1/community_pool",params)
return Coins.from_data(res.get("pool"))

async def parameters(self) -> dict:
async def parameters(self, params: Optional[APIParams] = None) -> dict:
"""Fetches the Distribution module parameters.
Args:
params (APIParams): optional parameters

Returns:
dict: Distribution module parameters
"""
res = await self._c._get("/cosmos/distribution/v1beta1/params")
res = await self._c._get("/cosmos/distribution/v1beta1/params", params)
return res.get("params")


class DistributionAPI(AsyncDistributionAPI):
@sync_bind(AsyncDistributionAPI.rewards)
def rewards(self, delegator: AccAddress) -> Rewards:
def rewards(self, delegator: AccAddress, params: Optional[APIParams] = None) -> Rewards:
pass

rewards.__doc__ = AsyncDistributionAPI.rewards.__doc__

@sync_bind(AsyncDistributionAPI.validator_commission)
def validator_commission(self, validator: ValAddress) -> Coins:
def validator_commission(self, validator: ValAddress, params: Optional[APIParams] = None) -> Coins:
pass

validator_commission.__doc__ = AsyncDistributionAPI.validator_commission.__doc__

@sync_bind(AsyncDistributionAPI.withdraw_address)
def withdraw_address(self, delegator: AccAddress) -> AccAddress:
def withdraw_address(self, delegator: AccAddress, params: Optional[APIParams] = None) -> AccAddress:
pass

withdraw_address.__doc__ = AsyncDistributionAPI.withdraw_address.__doc__

@sync_bind(AsyncDistributionAPI.community_pool)
def community_pool(self) -> Coins:
def community_pool(self, params: Optional[APIParams] = None) -> Coins:
pass

community_pool.__doc__ = AsyncDistributionAPI.community_pool.__doc__

@sync_bind(AsyncDistributionAPI.parameters)
def parameters(self) -> dict:
def parameters(self, params: Optional[APIParams] = None) -> dict:
pass

parameters.__doc__ = AsyncDistributionAPI.parameters.__doc__
31 changes: 21 additions & 10 deletions terra_sdk/client/lcd/api/mint.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
from typing import Optional

from terra_sdk.core import Dec, Numeric

from ._base import BaseAsyncAPI, sync_bind

from ..params import APIParams
__all__ = ["AsyncMintAPI", "MintAPI"]


class AsyncMintAPI(BaseAsyncAPI):
async def inflation(self) -> Dec:
async def inflation(self, params: Optional[APIParams] = None) -> Dec:
"""Fetches the current inflation.

Args:
params (APIParams): optional parameters

Returns:
Dec: inflation
"""
res = await self._c._get("/cosmos/mint/v1beta1/inflation")
res = await self._c._get("/cosmos/mint/v1beta1/inflation", params)
return Dec(res.get("inflation"))

async def annual_provisions(self) -> Dec:
async def annual_provisions(self, params: Optional[APIParams] = None) -> Dec:
"""Fetches the annual provisions.

Args:
params (APIParams): optional parameters

Returns:
Dec: annual provisions
"""
res = await self._c._get("/cosmos/mint/v1beta1/annual_provisions")
res = await self._c._get("/cosmos/mint/v1beta1/annual_provisions", params)
return Dec(res.get("annual_provisions"))

async def parameters(self) -> dict:
async def parameters(self, params: Optional[APIParams] = None) -> dict:
"""Fetches the Mint module's parameters.

Args:
params (APIParams): optional parameters

Returns:
dict: Mint module parameters
"""
res = await self._c._get("/cosmos/mint/v1beta1/params")
res = await self._c._get("/cosmos/mint/v1beta1/params", params)
params = res.get("params")
return {
"mint_denom": params["mint_denom"],
Expand All @@ -44,19 +55,19 @@ async def parameters(self) -> dict:

class MintAPI(AsyncMintAPI):
@sync_bind(AsyncMintAPI.inflation)
def inflation(self) -> Dec:
def inflation(self, params: Optional[APIParams] = None) -> Dec:
pass

inflation.__doc__ = AsyncMintAPI.inflation.__doc__

@sync_bind(AsyncMintAPI.annual_provisions)
def annual_provisions(self) -> Dec:
def annual_provisions(self, params: Optional[APIParams] = None) -> Dec:
pass

annual_provisions.__doc__ = AsyncMintAPI.annual_provisions.__doc__

@sync_bind(AsyncMintAPI.parameters)
def parameters(self) -> dict:
def parameters(self, params: Optional[APIParams] = None) -> dict:
pass

parameters.__doc__ = AsyncMintAPI.parameters.__doc__
19 changes: 12 additions & 7 deletions terra_sdk/client/lcd/api/slashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@

class AsyncSlashingAPI(BaseAsyncAPI):
async def signing_info(
self, val_cons_pub_key: ValConsPubKey
self, val_cons_pub_key: ValConsPubKey, params: Optional[APIParams] = None
) -> Union[List[dict], dict]:
"""Fetches signing info for a validator consensus public key.

Args:
val_cons_pub_key (ValConsPubKey): validator consensus public key.
params (APIParams): optional parameters

Returns:
Union[List[dict], dict]: signing info
"""
res = await self._c._get(
f"/cosmos/slashing/v1beta1/signing_infos/{val_cons_pub_key}"
f"/cosmos/slashing/v1beta1/signing_infos/{val_cons_pub_key}",
params
)
info = res["val_signing_info"]
return {
Expand All @@ -42,7 +44,7 @@ async def signing_infos(
"""Fetches all signing info.

Args:
params (APIParams, optional): additional params for the API like pagination
params (APIParams): optional parameters

Returns:
Union[List[dict], dict]: signing infos
Expand All @@ -62,13 +64,16 @@ async def signing_infos(
for info in infos
], res.get("pagination")

async def parameters(self) -> dict:
async def parameters(self, params: Optional[APIParams] = None) -> dict:
"""Fetches Slashing module parameters.

Args:
params (APIParams): optional parameters

Returns:
dict: Slashing module parameters
"""
res = await self._c._get("/cosmos/slashing/v1beta1/params")
res = await self._c._get("/cosmos/slashing/v1beta1/params", params)
params = res.get("params")
return {
"signed_blocks_window": Numeric.parse(params["signed_blocks_window"]),
Expand All @@ -81,7 +86,7 @@ async def parameters(self) -> dict:

class SlashingAPI(AsyncSlashingAPI):
@sync_bind(AsyncSlashingAPI.signing_info)
def signing_info(self, val_cons_pub_key: ValConsPubKey) -> List[dict]:
def signing_info(self, val_cons_pub_key: ValConsPubKey, params: Optional[APIParams] = None) -> List[dict]:
pass

signing_info.__doc__ = AsyncSlashingAPI.signing_info.__doc__
Expand All @@ -95,7 +100,7 @@ def signing_infos(
signing_infos.__doc__ = AsyncSlashingAPI.signing_infos.__doc__

@sync_bind(AsyncSlashingAPI.parameters)
def parameters(self) -> dict:
def parameters(self, params: Optional[APIParams] = None) -> dict:
pass

parameters.__doc__ = AsyncSlashingAPI.parameters.__doc__
Loading