Skip to content

Commit

Permalink
reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Lee committed Nov 7, 2021
1 parent f0d6271 commit 8c5aec4
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docs/core_modules/auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Account
Transactions
^^^^^^^^^^^^

.. automodule:: terra_sdk.core.auth.data.tx
.. automodule:: terra_sdk.core.tx
:members:

Public Key
^^^^^^^^^^

.. automodule:: terra_sdk.core.auth.data.public_key
:members:
:members:
6 changes: 3 additions & 3 deletions docs/guides/smart_contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Contract Deployment Example
import base64
from terra_sdk.client.localterra import LocalTerra
from terra_sdk.core.wasm import MsgStoreCode, MsgInstantiateContract, MsgExecuteContract
from terra_sdk.core.auth.data.tx import StdFee
from terra_sdk.core.fee import Fee
terra = LocalTerra()
test1 = terra.wallets["test1"]
contract_file = open("./contract.wasm", "rb")
file_bytes = base64.b64encode(contract_file.read()).decode()
store_code = MsgStoreCode(test1.key.acc_address, file_bytes)
store_code_tx = test1.create_and_sign_tx(msgs=[store_code], fee=StdFee(2100000, "60000uluna"))
store_code_tx = test1.create_and_sign_tx(msgs=[store_code], fee=Fee(2100000, "60000uluna"))
store_code_tx_result = terra.tx.broadcast(store_code_tx)
print(store_code_tx_result)
Expand Down Expand Up @@ -46,7 +46,7 @@ Contract Deployment Example
)
execute_tx = test1.create_and_sign_tx(
msgs=[execute], fee=StdFee(1000000, Coins(uluna=1000000))
msgs=[execute], fee=Fee(1000000, Coins(uluna=1000000))
)
execute_tx_result = terra.tx.broadcast(execute_tx)
Expand Down
16 changes: 8 additions & 8 deletions docs/guides/transactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ If you want to perform a state-changing operation on the Terra blockchain such a
sending tokens, swapping assets, withdrawing rewards, or even invoking functions on
smart contracts, you must create a **transaction** and broadcast it to the network.

An :class:`StdTx<terra_sdk.core.auth.data.tx.StdTx>` is a data object that represents
An :class:`StdTx<terra_sdk.core.tx.Tx>` is a data object that represents
a transaction. It contains:

- **msgs**: a list of state-altering messages
Expand Down Expand Up @@ -42,7 +42,7 @@ Once you have your Wallet, you can simply create a StdTx using :meth:`Wallet.cre

.. code-block:: python
from terra_sdk.core.auth import StdFee
from terra_sdk.core.fee import Fee
from terra_sdk.core.bank import MsgSend
tx = wallet.create_and_sign_tx(
Expand All @@ -52,7 +52,7 @@ Once you have your Wallet, you can simply create a StdTx using :meth:`Wallet.cre
"1000000uluna" # send 1 luna
)],
memo="test transaction!",
fee=StdFee(200000, "120000uluna")
fee=Fee(200000, "120000uluna")
)
And that's it! You should now be able to broadcast your transaction to the network.
Expand Down Expand Up @@ -101,7 +101,7 @@ Signing transactions manually
-----------------------------

Below is the full process of signing a transaction manually that does not use ``Wallet``.
You will need to build a :class:`StdSignMsg<terra_sdk.core.auth.data.tx.StdSignMsg>`,
You will need to build a :class:`StdSignMsg<terra_sdk.core..tx.SignDoc>`,
sign it, and add the signatures to an ``StdTx``.

A StdSignMsg contains the information required to build a StdTx:
Expand All @@ -128,7 +128,7 @@ A StdSignMsg contains the information required to build a StdTx:
chain_id="columbus-4",
account_number=23982,
sequence=12,
fee=StdFee(200000, "120000uluna"),
fee=Fee(200000, "120000uluna"),
msgs=[MsgSend(
mk.acc_address,
RECIPIENT,
Expand Down Expand Up @@ -157,7 +157,7 @@ Applying multiple signatures

Some messages, such as ``MsgMultiSend``, require the transaction to be signed with multiple signatures.
You must prepare a separate ``StdSignMsg`` for each signer to sign individually, and then
combine them in the ``signatures`` field of the final :class:`StdTx<terra_sdk.core.auth.data.tx.StdTx>` object.
combine them in the ``signatures`` field of the final :class:`StdTx<terra_sdk.core..tx.Tx>` object.
Each ``StdSignMsg`` should only differ by ``account`` and ``sequence``, which vary according to the signing key.

.. note::
Expand All @@ -167,7 +167,7 @@ Each ``StdSignMsg`` should only differ by ``account`` and ``sequence``, which va
.. code-block:: python
from terra_sdk.client.lcd import LCDClient
from terra_sdk.core.auth import StdFee
from terra_sdk.core.fee import Fee
from terra_sdk.core.bank import MsgMultiSend
from terra_sdk.key.mnemonic import MnemonicKey
Expand All @@ -187,7 +187,7 @@ Each ``StdSignMsg`` should only differ by ``account`` and ``sequence``, which va
)
msgs = [multisend]
fee = StdFee(200000, "12000uluna")
fee = Fee(200000, "12000uluna")
memo = "multisend example"
# create unsigned_tx #1
Expand Down
28 changes: 14 additions & 14 deletions integration_tests/tx_ibc-transfer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from terra_sdk.exceptions import LCDResponseError

from terra_sdk.client.lcd import LCDClient, PaginationOptions
from terra_sdk.client.lcd.api.tx import CreateTxOptions
from terra_sdk.core import Coin, Coins
from terra_sdk.core.ibc import Height
from terra_sdk.core.ibc_transfer import MsgTransfer
from terra_sdk.util.contract import get_code_id

from terra_sdk.exceptions import LCDResponseError
from terra_sdk.key.mnemonic import MnemonicKey
from terra_sdk.util.contract import get_code_id


def main():
Expand All @@ -16,21 +14,24 @@ def main():
chain_id="bombay-12",
)

key = MnemonicKey(mnemonic="notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius")
key = MnemonicKey(
mnemonic="notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius"
)

wallet = terra.wallet(key=key)

signedTx = wallet.create_and_sign_tx(
CreateTxOptions(
msgs=[
MsgTransfer(source_port="transfer",
source_channel="channel-9",
token="10000uluna",
sender="terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
receiver="terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp",
timeout_height=Height(revision_number=0, revision_height=10000),
timeout_timestamp=0
)
MsgTransfer(
source_port="transfer",
source_channel="channel-9",
token="10000uluna",
sender="terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
receiver="terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp",
timeout_height=Height(revision_number=0, revision_height=10000),
timeout_timestamp=0,
)
]
)
)
Expand All @@ -44,5 +45,4 @@ def main():
print(result)



main()
12 changes: 7 additions & 5 deletions terra_sdk/client/lcd/api/gov.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ async def votes(self, proposal_id: int, params: Optional[APIParams] = None):
msg.get("@type") == "/cosmos.gov.v1beta1.MsgVoteWeighted"
and msg.get("proposal_id") == proposal_id
):
votes.append(Vote(
proposal_id=proposal_id,
voter=msg.get("voter"),
options=msg.get("options")
))
votes.append(
Vote(
proposal_id=proposal_id,
voter=msg.get("voter"),
options=msg.get("options"),
)
)
return votes, pagination

async def tally(self, proposal_id: int):
Expand Down
8 changes: 5 additions & 3 deletions terra_sdk/client/lcd/api/slashing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import datetime
from typing import List, Optional, Union

from terra_sdk.core import Dec, Numeric, ValConsPubKey
from dateutil import parser

from terra_sdk.core import Dec, Numeric, ValConsPubKey

from ._base import BaseAsyncAPI, sync_bind

__all__ = ["AsyncSlashingAPI", "SlashingAPI"]
Expand All @@ -12,7 +13,6 @@


class AsyncSlashingAPI(BaseAsyncAPI):

async def signing_info(
self, val_cons_pub_key: ValConsPubKey
) -> Union[List[dict], dict]:
Expand All @@ -32,7 +32,9 @@ async def signing_info(
"address": info["address"],
"start_height": Numeric.parse(info["start_height"]),
"index_offset": Numeric.parse(info["index_offset"]),
"jailed_until": parser.parse(info["jailed_until"]), # TODO: convert to datetime
"jailed_until": parser.parse(
info["jailed_until"]
), # TODO: convert to datetime
"tombstoned": bool(info["tombstoned"]),
"missed_blocks_counter": Numeric.parse(info["missed_blocks_counter"]),
}
Expand Down
2 changes: 1 addition & 1 deletion terra_sdk/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"SignatureV2",
]

from .bech32 import AccAddress, AccPubKey, ValAddress, ValPubKey
from .coin import Coin
from .coins import Coins
from .numeric import Dec, Numeric
from .public_key import PublicKey, SimplePublicKey, ValConsPubKey
from .sign_doc import SignDoc
from .signature_v2 import SignatureV2
from .bech32 import AccAddress, AccPubKey, ValAddress, ValPubKey
30 changes: 14 additions & 16 deletions terra_sdk/core/authz/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class SendAuthorization(Authorization):
spend_limit: Coins = attr.ib(converter=Coins)

def to_data(self) -> dict:
return {
"@type": self.type_url,
"spend_limit": self.spend_limit.to_data()
}
return {"@type": self.type_url, "spend_limit": self.spend_limit.to_data()}

@classmethod
def from_data(cls, data: dict) -> SendAuthorization:
Expand All @@ -86,10 +83,7 @@ class GenericAuthorization(Authorization):
msg: str = attr.ib()

def to_data(self) -> dict:
return {
"@type": self.type_url,
"msg": self.msg
}
return {"@type": self.type_url, "msg": self.msg}

@classmethod
def from_data(cls, data: dict) -> GenericAuthorization:
Expand All @@ -112,7 +106,7 @@ class AuthorizationGrant(JSONSerializable):
def to_data(self) -> dict:
return {
"authorization": self.authorization.to_data(),
"expiration": self.expiration
"expiration": self.expiration,
}

@classmethod
Expand All @@ -134,9 +128,7 @@ class StakeAuthorizationValidators(JSONSerializable):
address: List[AccAddress] = attr.ib(converter=list)

def to_data(self) -> dict:
return {
"address": self.address
}
return {"address": self.address}

@classmethod
def from_data(cls, data: dict) -> StakeAuthorizationValidators:
Expand All @@ -161,16 +153,22 @@ def to_data(self) -> dict:
"authorization_type": self.authorization_type,
"max_tokens": self.max_tokens.to_data() if self.max_tokens else None,
"allow_list": self.allow_list.to_data() if self.allow_list else None,
"deny_list": self.deny_list.to_data() if self.deny_list else None
"deny_list": self.deny_list.to_data() if self.deny_list else None,
}

@classmethod
def from_data(cls, data: dict) -> StakeAuthorization:
return StakeAuthorization(
authorization_type=data["authorization_type"],
max_tokens=Coins.from_data(data["max_tokens"]) if data.get("max_tokens") else None,
allow_list=StakeAuthorizationValidators.from_data(data["allow_list"]) if data.get("allow_list") else None,
deny_list=StakeAuthorizationValidators.from_data(data["deny_list"]) if data.get("deny_list") else None
max_tokens=Coins.from_data(data["max_tokens"])
if data.get("max_tokens")
else None,
allow_list=StakeAuthorizationValidators.from_data(data["allow_list"])
if data.get("allow_list")
else None,
deny_list=StakeAuthorizationValidators.from_data(data["deny_list"])
if data.get("deny_list")
else None,
)

def to_proto(self) -> StakeAuthorization_pb:
Expand Down
5 changes: 3 additions & 2 deletions terra_sdk/core/authz/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def to_data(self) -> dict:
return {
"@type": self.type_url,
"grantee": self.grantee,
"msgs": [msg.to_data() for msg in self.msgs]
"msgs": [msg.to_data() for msg in self.msgs],
}

@classmethod
Expand All @@ -51,6 +51,7 @@ def from_data(cls, data: dict) -> MsgExecAuthorized:
def to_proto(self) -> MsgExec_pb:
return MsgExec_pb(grantee=self.grantee, msgs=[m.pack_any() for m in self.msgs])


@attr.s
class MsgGrantAuthorization(Msg):
"""Grant an authorization to ``grantee`` to call messages on behalf of ``granter``.
Expand All @@ -75,7 +76,7 @@ def to_data(self) -> dict:
"@type": self.type_url,
"granter": self.granter,
"grantee": self.grantee,
"grant": self.grant.to_data()
"grant": self.grant.to_data(),
}

@classmethod
Expand Down
10 changes: 2 additions & 8 deletions terra_sdk/core/bank/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ class MultiSendInput(JSONSerializable):
"""Coins to be sent / received."""

def to_data(self) -> dict:
return {
"address": self.address,
"coins": self.coins.to_data()
}
return {"address": self.address, "coins": self.coins.to_data()}

@classmethod
def from_data(cls, data: dict):
Expand Down Expand Up @@ -141,10 +138,7 @@ def from_data(cls, data: dict):
return cls(address=data["address"], coins=Coins.from_data(data["coins"]))

def to_data(self) -> dict:
return {
"address": self.address,
"coins": self.coins.to_data()
}
return {"address": self.address, "coins": self.coins.to_data()}

@classmethod
def from_proto(cls, proto: Output_pb) -> MultiSendOutput:
Expand Down
11 changes: 4 additions & 7 deletions terra_sdk/core/distribution/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def to_data(self) -> dict:
return {
"@type": self.type_url,
"delegator_address": self.delegator_address,
"withdraw_address": self.withdraw_address
"withdraw_address": self.withdraw_address,
}

@classmethod
Expand Down Expand Up @@ -90,7 +90,7 @@ def to_data(self) -> dict:
return {
"@type": self.type_url,
"delegator_address": self.delegator_address,
"withdraw_address": self.withdraw_address
"withdraw_address": self.withdraw_address,
}

@classmethod
Expand Down Expand Up @@ -125,10 +125,7 @@ class MsgWithdrawValidatorCommission(Msg):
validator_address: ValAddress = attr.ib()

def to_data(self) -> dict:
return {
"@type": self.type_url,
"validator_address": self.validator_address
}
return {"@type": self.type_url, "validator_address": self.validator_address}

@classmethod
def from_data(cls, data: dict) -> MsgWithdrawValidatorCommission:
Expand Down Expand Up @@ -161,7 +158,7 @@ def to_data(self) -> dict:
return {
"@type": self.type_url,
"depositor": self.depositor,
"amount": self.amount.to_data()
"amount": self.amount.to_data(),
}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion terra_sdk/core/distribution/proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def to_data(self) -> dict:
"title": self.title,
"description": self.description,
"recipient": self.recipient,
"amount": self.amount.to_data()
"amount": self.amount.to_data(),
}

def to_proto(self) -> CommunityPoolSpendProposal_pb:
Expand Down
Loading

0 comments on commit 8c5aec4

Please sign in to comment.