From 2aa48517487812dbdba4467311662840e2fee9d6 Mon Sep 17 00:00:00 2001 From: yihuang Date: Mon, 26 Feb 2024 16:56:31 +0800 Subject: [PATCH] Problem: sdk 0.50 not supported (#121) Problem: nix develop don't work (#120) Solution: - fix default devShell - update link instruction in ci to use nix - update python dev dependencies Problem: sdk 0.50 not supported Update CHANGELOG.md Signed-off-by: yihuang backward compatible through runtime prob git ignore --- .gitignore | 5 ++++- CHANGELOG.md | 1 + pystarport/cosmoscli.py | 25 +++++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index bae73e9..38a8f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -141,4 +141,7 @@ cython_debug/ .vscode # macos -.DS_Store \ No newline at end of file +.DS_Store + +/.direnv +/.envrc diff --git a/CHANGELOG.md b/CHANGELOG.md index a4de2fd..d7d3cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [#113](https://github.com/crypto-com/pystarport/pull/113) support ibc related cmd. - [#115](https://github.com/crypto-com/pystarport/pull/115) avoid cli redundant migrated key log in stdout. - [#117](https://github.com/crypto-com/pystarport/pull/117) make event_query_tx_for optional. +- [#121](https://github.com/crypto-com/pystarport/pull/121) Support sdk 0.50 *Feb 7, 2023* diff --git a/pystarport/cosmoscli.py b/pystarport/cosmoscli.py index 1a81885..23b7c5b 100644 --- a/pystarport/cosmoscli.py +++ b/pystarport/cosmoscli.py @@ -41,6 +41,16 @@ class ChainCommand: def __init__(self, cmd=None): self.cmd = cmd or CHAIN + def prob_genesis_subcommand(self): + 'test if the command has "genesis" subcommand, introduced in sdk 0.50' + try: + output = self("genesis") + except AssertionError: + # non-zero return code + return False + + return "Available Commands" in output.decode() + def __call__(self, cmd, *args, stdin=None, stderr=subprocess.STDOUT, **kwargs): "execute chain-maind" args = " ".join(build_cli_args_safe(cmd, *args, **kwargs)) @@ -71,6 +81,7 @@ def __init__( self.leger_button = LedgerButton(zemu_address, zemu_button_port) self.output = None self.error = None + self.has_genesis_subcommand = self.raw.prob_genesis_subcommand() def node_id(self): "get tendermint node id" @@ -152,11 +163,17 @@ def init(self, moniker): home=self.data_dir, ) + def genesis_subcommand(self, *args, **kwargs): + if self.has_genesis_subcommand: + return self.raw("genesis", *args, **kwargs) + else: + return self.raw(*args, **kwargs) + def validate_genesis(self, *args): - return self.raw("validate-genesis", *args, home=self.data_dir) + return self.genesis_subcommand("validate-genesis", *args, home=self.data_dir) def add_genesis_account(self, addr, coins, **kwargs): - return self.raw( + return self.genesis_subcommand( "add-genesis-account", addr, coins, @@ -166,7 +183,7 @@ def add_genesis_account(self, addr, coins, **kwargs): ) def gentx(self, name, coins, *args, min_self_delegation=1, pubkey=None, **kwargs): - return self.raw( + return self.genesis_subcommand( "gentx", name, coins, @@ -180,7 +197,7 @@ def gentx(self, name, coins, *args, min_self_delegation=1, pubkey=None, **kwargs ) def collect_gentxs(self, gentx_dir): - return self.raw("collect-gentxs", gentx_dir, home=self.data_dir) + return self.genesis_subcommand("collect-gentxs", gentx_dir, home=self.data_dir) def status(self): return json.loads(self.raw("status", node=self.node_rpc))