Skip to content

Commit

Permalink
save #wip: fixing InactiveRpcError
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Jul 7, 2023
1 parent 1154b57 commit 75b72a3
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 93 deletions.
2 changes: 1 addition & 1 deletion nibiru/pytypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These import statements export the types to 'nibiru.pytypes'.

from nibiru.pytypes.common import ( # noqa # TODO move constants to a constants.py file.; noqa
GAS_PRICE,
DEFAULT_GAS_PRICE,
MAX_MEMO_CHARACTERS,
Coin,
Direction,
Expand Down
36 changes: 20 additions & 16 deletions nibiru/pytypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,42 @@
import nibiru

MAX_MEMO_CHARACTERS = 256
GAS_PRICE = 1 * pow(10, -3)
DEFAULT_GAS_PRICE = 1 * pow(10, -3)


class TxType(Enum):
"""
The TxType allows you to choose what type of synchronization you want to use
to send transaction
The TxType allows you to choose what type of synchronization you want to
use to send transaction
"""

SYNC = 1
"""
The CLI waits for a CheckTx execution response only.
Each full-node that receives a transaction sends a CheckTx to the application layer to check for validity, and
receives an abci.ResponseCheckTx. If the Tx passes the checks, it is held in the nodes' Mempool , an in-memory pool
of transactions unique to each node pending inclusion in a block - honest nodes will discard Tx if it is found to
be invalid.
Prior to consensus, nodes continuously check incoming transactions and gossip them to their peers.
The CLI waits for a CheckTx execution response only. Each full-node that
receives a transaction sends a CheckTx to the application layer to check
for validity, and receives an abci.ResponseCheckTx. If the Tx passes the
checks, it is held in the nodes' Mempool , an in-memory pool of
transactions unique to each node pending inclusion in a block - honest
nodes will discard Tx if it is found to be invalid.
Prior to consensus, nodes continuously check incoming transactions and
gossip them to their peers.
"""

ASYNC = 2
"""
The CLI returns immediately (transaction might fail silently).
If you send a transaction with this option, it is recommended to query the transaction output using the hash of the
transaction given by the output of the tx call.
The CLI returns immediately (transaction might fail silently). If you send
a transaction with this option, it is recommended to query the transaction
output using the hash of the transaction given by the output of the tx
call.
"""

BLOCK = 3
"""
The tx function will wait unitl the tx is be committed in a block.
This have the effect of having the full log of the transaction available with the output of the method. These logs
will include information as to coin sent and received, states changed etc.
The tx function will wait unitl the tx is be committed in a block. This
have the effect of having the full log of the transaction available with
the output of the method. These logs will include information as to coin
sent and received, states changed etc.
"""


Expand Down
4 changes: 2 additions & 2 deletions nibiru/pytypes/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def localnet(cls) -> "Network":

def string(self) -> str:
"""
Returns the current environment the network was initialized with. Will return `custom` if a custom network
was created
Returns the current environment the network was initialized with. Will
return `custom` if a custom network was created
Returns:
str: The name of the current environment.
Expand Down
10 changes: 7 additions & 3 deletions nibiru/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ def __init__(self, _error_do_not_use_init_directly=None) -> None:
@classmethod
def authorize(cls, key: str = None) -> "Sdk":
"""
Authorize allows the user to generate or recover a wallet and register it as an Sdk object.
If a key is provided, the wallet will be recovered. Otherwise, a new wallet is created.
Authorize allows the user to generate or recover a wallet and register
it as an Sdk object.
If a key is provided, the wallet will be recovered. Otherwise, a new
wallet is created.
Args:
key (str, optional): The mnemonic if recover needed. Defaults to None.
key (str, optional): The mnemonic if recover needed.
Defaults to None.
Returns:
Sdk: The updated sdk object
Expand Down
26 changes: 20 additions & 6 deletions nibiru/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import json
import logging
from copy import deepcopy
import pprint
from numbers import Number
from typing import Any, Callable, Iterable, List, Optional, Tuple, Union

Expand Down Expand Up @@ -93,23 +93,23 @@ def execute_msgs(
sim_res = self.simulate(tx)
gas_estimate: float = sim_res.gas_info.gas_used

# breakpoint()
tx_resp: abci_type.TxResponse = self.execute_tx(
tx, gas_estimate, tx_config=tx_config
)
# Convert raw log into a dictionary
tx_resp: dict[str, Any] = MessageToDict(tx_resp)
tx_output = self.client.tx_by_hash(tx_hash=tx_resp["txhash"])

# breakpoint()
if tx_output.get("tx_response").get("code") != 0:
address.decrease_sequence()
raise TxError(tx_output.raw_log)

tx_output["rawLog"] = json.loads(tx_output.get("rawLog", "{}"))
return pt.RawSyncTxResp(tx_output)
except SimulationError as err:
if (
"account sequence mismatch, expected"
in str(err)
):
if "account sequence mismatch, expected" in str(err):

if not isinstance(msgs, list):
msgs = [msgs]
Expand Down Expand Up @@ -144,7 +144,7 @@ def compute_gas_wanted() -> float:
return gas_wanted

gas_wanted = compute_gas_wanted()
gas_price = pt.GAS_PRICE if conf.gas_price <= 0 else conf.gas_price
gas_price = pt.DEFAULT_GAS_PRICE if conf.gas_price <= 0 else conf.gas_price

fee = [
cosmos_base_coin_pb.Coin(
Expand Down Expand Up @@ -300,6 +300,20 @@ def __init__(
self.memo = memo
self.timeout_height = timeout_height

def __repr__(self) -> str:
self_as_dict = dict(
msgs=[self.msgs],
sequence=self.sequence,
account_num=self.account_num,
chain_id=self.chain_id,
fee=self.fee,
gas_limit=self.gas_limit,
memo=self.memo,
timeout_height=self.timeout_height,
priv_key=self.priv_key,
)
return pprint.pformat(self_as_dict, indent=2)

@staticmethod
def __convert_msgs(msgs: List[message.Message]) -> List[any_pb2.Any]:
any_msgs: List[any_pb2.Any] = []
Expand Down
42 changes: 21 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions tests/bank_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@


def test_send_multiple_msgs(sdk_val: nibiru.Sdk, sdk_agent: nibiru.Sdk):
"""Tests the transfer of funds for a transaction with a multiple 'MsgSend' messages."""

"""Tests the transfer of funds for a transaction with a multiple
'MsgSend' tx messages.
"""
tx_output = sdk_val.tx.execute_msgs(
msgs=[
nibiru.Msg.bank.send(
Expand All @@ -32,7 +33,9 @@ def test_send_multiple_msgs(sdk_val: nibiru.Sdk, sdk_agent: nibiru.Sdk):


def test_send_single_msg(sdk_val: nibiru.Sdk, sdk_agent: nibiru.Sdk):
"""Tests the transfer of funds for a transaction with a single 'MsgSend' message."""
"""Tests the transfer of funds for a transaction with a single 'MsgSend'
tx message.
"""

tx_output = sdk_val.tx.execute_msgs(
[
Expand Down
Loading

0 comments on commit 75b72a3

Please sign in to comment.