Skip to content

Commit

Permalink
Merge pull request #189 from terra-money/feat/terra/4.0.0
Browse files Browse the repository at this point in the history
feat: deprecate terra-sdk
  • Loading branch information
emidev98 authored Sep 25, 2023
2 parents 3d95606 + 23cef71 commit 6489ca3
Show file tree
Hide file tree
Showing 27 changed files with 1,144 additions and 1,149 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021, Terraform Labs PTE. LTD
Copyright (c) 2023, Terraform Labs PTE. LTD

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# DEPRECATED

Terra SDK python library will not be maintained any further by TFL officialy. Alternative options to this library can be found here:

- GoLang [Terra Core](https://github.com/terra-money/core) to interact with Terra's Blockchain throught the gRPC models,
- JavaScript [@terra-money/terra.proto](https://www.npmjs.com/package/@terra-money/feather.js) for web frontend and node backend,
- Rust [terra-proto-rs](https://crates.io/crates/terra-proto-rs) both for smart contracts and for external APIs.

<br/>
<br/>

Expand Down
57 changes: 34 additions & 23 deletions integration_tests/create_vesting_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
# import lcd_tx
from terra_sdk.client.localterra import LocalTerra
from terra_sdk.core import Coin, Coins
from terra_sdk.core.bank import MsgSend
from terra_sdk.core.tx import SignMode
from terra_sdk.key.key import SignOptions
from terra_sdk.key.mnemonic import MnemonicKey
from terra_sdk.core.auth import (
MsgCreatePeriodicVestingAccount,
MsgCreateVestingAccount,
MsgDonateAllVestingTokens,
Period
Period,
)
from terra_sdk.core.bank import MsgSend
from terra_sdk.core.tx import SignMode
from terra_sdk.key.key import SignOptions
from terra_sdk.key.mnemonic import MnemonicKey


def main():
terra = LocalTerra()

Expand All @@ -50,41 +52,50 @@ def main():
key_v.acc_address,
Coins("2000uluna"),
1659130372,
False
False,
)

cpva = MsgCreatePeriodicVestingAccount(
"terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
key_pv.acc_address,
1659130372,
[Period(100, Coins("1000uluna"))]
[Period(100, Coins("1000uluna"))],
)

tx = wallet.create_and_sign_tx(CreateTxOptions(
msgs =[cva, cpva],
))
tx = wallet.create_and_sign_tx(
CreateTxOptions(
msgs=[cva, cpva],
)
)
result = terra.tx.broadcast(tx)

send1 = MsgSend("terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v", key_v.acc_address, Coins("100000uluna"))
send2 = MsgSend("terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v", key_pv.acc_address, Coins("100000uluna"))
send1 = MsgSend(
"terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
key_v.acc_address,
Coins("100000uluna"),
)
send2 = MsgSend(
"terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
key_pv.acc_address,
Coins("100000uluna"),
)

tx = wallet.create_and_sign_tx(CreateTxOptions(
msgs =[send1, send2],
memo= "test from terra.py"
))
tx = wallet.create_and_sign_tx(
CreateTxOptions(msgs=[send1, send2], memo="test from terra.py")
)
result = terra.tx.broadcast(tx)

print("send to vesting and periodic vesting account : ", result)

tx = wallet_v.create_and_sign_tx(CreateTxOptions(msgs=[
MsgDonateAllVestingTokens(key_v.acc_address)
]))
tx = wallet_v.create_and_sign_tx(
CreateTxOptions(msgs=[MsgDonateAllVestingTokens(key_v.acc_address)])
)
result = terra.tx.broadcast(tx)

print("donate all tokens in vesting account : ", result)
tx = wallet_pv.create_and_sign_tx(CreateTxOptions(msgs=[
MsgDonateAllVestingTokens(key_pv.acc_address)
]))
tx = wallet_pv.create_and_sign_tx(
CreateTxOptions(msgs=[MsgDonateAllVestingTokens(key_pv.acc_address)])
)
result = terra.tx.broadcast(tx)
print("donate all tokens in periodic vesting account : ", result)

Expand Down
1,886 changes: 899 additions & 987 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
]
description = "The Python SDK for Terra"
description = "DEPRECATED Python SDK for Terra (check README for alternatives)"
documentation = "https://terra-money.github.io/terra.py/index.html"
homepage = "https://github.com/terra-money/terra.py"
keywords = ["jigu", "blockchain", "terra", "defi", "crypto"]
license = "MIT"
packages = [{ include = "terra_sdk" }]
readme = "README.md"
repository = "https://github.com/terra-money/terra.py"
version = "3.0.1"
version = "4.0.0"

[tool.poetry.dependencies]
aiohttp = "^3.8.1"
Expand All @@ -35,7 +35,7 @@ boltons = "^21.0.0"
nest-asyncio = "^1.5.4"
attrs = "^21.4.0"
wrapt = "^1.13.3"
terra-proto = "2.1.0"
terra-proto = "^4.0.1"

[tool.poetry.dev-dependencies]
aioresponses = "^0.7.2"
Expand Down
2 changes: 1 addition & 1 deletion terra_sdk/client/lcd/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Optional, Union

from ..params import APIParams
from terra_sdk.core import AccAddress
from terra_sdk.core.auth import (
Account,
Expand All @@ -10,6 +9,7 @@
PeriodicVestingAccount,
)

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

__all__ = ["AsyncAuthAPI", "AuthAPI"]
Expand Down
37 changes: 24 additions & 13 deletions terra_sdk/client/lcd/api/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import attr

from terra_sdk.core import AccAddress, Coins, ValAddress

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

Expand All @@ -19,7 +20,9 @@ class Rewards:


class AsyncDistributionAPI(BaseAsyncAPI):
async def rewards(self, delegator: AccAddress, params: Optional[APIParams] = None) -> Rewards:
async def rewards(
self, delegator: AccAddress, params: Optional[APIParams] = None
) -> Rewards:
"""Fetches the staking reward data for a delegator.
Args:
Expand All @@ -30,8 +33,7 @@ async def rewards(self, delegator: AccAddress, params: Optional[APIParams] = No
Rewards: delegator rewards
"""
res = await self._c._get(
f"/cosmos/distribution/v1beta1/delegators/{delegator}/rewards",
params
f"/cosmos/distribution/v1beta1/delegators/{delegator}/rewards", params
)
return Rewards(
rewards={
Expand All @@ -41,7 +43,9 @@ async def rewards(self, delegator: AccAddress, params: Optional[APIParams] = No
total=Coins.from_data(res["total"]),
)

async def validator_commission(self, validator: ValAddress, params: Optional[APIParams] = None) -> Coins:
async def validator_commission(
self, validator: ValAddress, params: Optional[APIParams] = None
) -> Coins:
"""Fetches the commission reward data for a validator.
Args:
Expand All @@ -52,13 +56,14 @@ async def validator_commission(self, validator: ValAddress, params: Optional[AP
ValidatorCommission: validator rewards
"""
res = await self._c._get(
f"/cosmos/distribution/v1beta1/validators/{validator}/commission",
params
f"/cosmos/distribution/v1beta1/validators/{validator}/commission", params
)
commission = res["commission"]
return Coins.from_data(commission["commission"])

async def withdraw_address(self, delegator: AccAddress, params: Optional[APIParams] = None) -> AccAddress:
async def withdraw_address(
self, delegator: AccAddress, params: Optional[APIParams] = None
) -> AccAddress:
"""Fetches the withdraw address associated with a delegator.
Args:
Expand All @@ -70,19 +75,19 @@ async def withdraw_address(self, delegator: AccAddress, params: Optional[APIPar
"""
res = await self._c._get(
f"/cosmos/distribution/v1beta1/delegators/{delegator}/withdraw_address",
params
params,
)
return res.get("withdraw_address")

async def community_pool(self, params: Optional[APIParams] = None) -> 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",params)
res = await self._c._get("/cosmos/distribution/v1beta1/community_pool", params)
return Coins.from_data(res.get("pool"))

async def parameters(self, params: Optional[APIParams] = None) -> dict:
Expand All @@ -99,19 +104,25 @@ async def parameters(self, params: Optional[APIParams] = None) -> dict:

class DistributionAPI(AsyncDistributionAPI):
@sync_bind(AsyncDistributionAPI.rewards)
def rewards(self, delegator: AccAddress, params: Optional[APIParams] = None) -> 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, params: Optional[APIParams] = None) -> 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, params: Optional[APIParams] = None) -> AccAddress:
def withdraw_address(
self, delegator: AccAddress, params: Optional[APIParams] = None
) -> AccAddress:
pass

withdraw_address.__doc__ = AsyncDistributionAPI.withdraw_address.__doc__
Expand Down
16 changes: 11 additions & 5 deletions terra_sdk/client/lcd/api/feegrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ async def allowances_by_granter(
Returns:
Allowance: granted allowance
"""
res = await self._c._get(
f"cosmos/feegrant/v1beta1/issued/{granter}", params
)
res = await self._c._get(f"cosmos/feegrant/v1beta1/issued/{granter}", params)
res = res.get("allowance")
return {
"granter": res.get("granter"),
"allowance": Allowance.from_data(res.get("allowance")),
}


class FeeGrantAPI(AsyncFeeGrantAPI):
@sync_bind(AsyncFeeGrantAPI.allowances)
def allowances(
Expand All @@ -95,13 +94,20 @@ def allowances(
allowances.__doc__ = AsyncFeeGrantAPI.allowances.__doc__

@sync_bind(AsyncFeeGrantAPI.allowance)
def allowance(self, granter: AccAddress, grantee: AccAddress, params: Optional[APIParams] = None) -> Allowance:
def allowance(
self,
granter: AccAddress,
grantee: AccAddress,
params: Optional[APIParams] = None,
) -> Allowance:
pass

allowance.__doc__ = AsyncFeeGrantAPI.allowance.__doc__

@sync_bind(AsyncFeeGrantAPI.allowance)
def allowances_by_granter(self, granter: AccAddress, params: Optional[APIParams] = None) -> Allowance:
def allowances_by_granter(
self, granter: AccAddress, params: Optional[APIParams] = None
) -> Allowance:
pass

allowances_by_granter.__doc__ = AsyncFeeGrantAPI.allowances_by_granter.__doc__
4 changes: 3 additions & 1 deletion terra_sdk/client/lcd/api/gov.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ async def parameters(self) -> dict:

class GovAPI(AsyncGovAPI):
@sync_bind(AsyncGovAPI.proposals)
def proposals(self, params: Optional[APIParams] = None) -> Tuple[List[Proposal], dict]:
def proposals(
self, params: Optional[APIParams] = None
) -> Tuple[List[Proposal], dict]:
pass

proposals.__doc__ = AsyncGovAPI.proposals.__doc__
Expand Down
3 changes: 2 additions & 1 deletion terra_sdk/client/lcd/api/mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from terra_sdk.core import Dec, Numeric

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

__all__ = ["AsyncMintAPI", "MintAPI"]


Expand Down
9 changes: 5 additions & 4 deletions terra_sdk/client/lcd/api/slashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ async def signing_info(
Union[List[dict], dict]: signing info
"""
res = await self._c._get(
f"/cosmos/slashing/v1beta1/signing_infos/{val_cons_pub_key}",
params
f"/cosmos/slashing/v1beta1/signing_infos/{val_cons_pub_key}", params
)
info = res["val_signing_info"]
return {
Expand Down Expand Up @@ -69,7 +68,7 @@ async def parameters(self, params: Optional[APIParams] = None) -> dict:
Args:
params (APIParams): optional parameters
Returns:
dict: Slashing module parameters
"""
Expand All @@ -86,7 +85,9 @@ async def parameters(self, params: Optional[APIParams] = None) -> dict:

class SlashingAPI(AsyncSlashingAPI):
@sync_bind(AsyncSlashingAPI.signing_info)
def signing_info(self, val_cons_pub_key: ValConsPubKey, params: Optional[APIParams] = None) -> 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 Down
Loading

0 comments on commit 6489ca3

Please sign in to comment.