diff --git a/pystarport/cluster.py b/pystarport/cluster.py index cf99d06..c583a15 100644 --- a/pystarport/cluster.py +++ b/pystarport/cluster.py @@ -548,29 +548,25 @@ def unjail(self, addr, i=0, event_query_tx=True): def create_validator( self, amount, + options, i, - moniker=None, - commission_max_change_rate="0.01", - commission_rate="0.1", - commission_max_rate="0.2", - min_self_delegation="1", - event_query_tx=True, - sdk47_compact=True, **kwargs, ): """MsgCreateValidator create the node with create_node before call this""" - return self.cosmos_cli(i).create_validator( - amount, - moniker or self.config["validators"][i]["moniker"], - commission_max_change_rate, - commission_rate, - commission_max_rate, - min_self_delegation, - event_query_tx=event_query_tx, - sdk47_compact=sdk47_compact, - **kwargs, - ) + options.setdefault("moniker", self.config["validators"][i]["moniker"]) + return self.cosmos_cli(i).create_validator(amount, options, **kwargs) + + def create_validator_legacy( + self, + amount, + i, + **kwargs, + ): + """MsgCreateValidator + create the node with create_node before call this""" + kwargs.setdefault("moniker", self.config["validators"][i]["moniker"]) + return self.cosmos_cli(i).create_validator_legacy(amount, **kwargs) def edit_validator( self, diff --git a/pystarport/cosmoscli.py b/pystarport/cosmoscli.py index f91eefb..7ab0cd9 100644 --- a/pystarport/cosmoscli.py +++ b/pystarport/cosmoscli.py @@ -1,7 +1,6 @@ import enum import hashlib import json -import re import subprocess import tempfile import threading @@ -662,6 +661,55 @@ def unjail(self, addr, event_query_tx=True): return rsp def create_validator( + self, + amount, + options, + event_query_tx=True, + **kwargs, + ): + options = { + "commission-max-change-rate": "0.01", + "commission-rate": "0.1", + "commission-max-rate": "0.2", + "min-self-delegation": "1", + "amount": amount, + } | options + + if "pubkey" not in options: + pubkey = ( + self.raw( + "tendermint", + "show-validator", + home=self.data_dir, + ) + .strip() + .decode() + ) + options["pubkey"] = json.loads(pubkey) + + with tempfile.NamedTemporaryFile("w") as fp: + json.dump(options, fp) + fp.flush() + raw = self.raw( + "tx", + "staking", + "create-validator", + fp.name, + "-y", + from_=self.address("validator"), + # basic + home=self.data_dir, + node=self.node_rpc, + keyring_backend="test", + chain_id=self.chain_id, + **kwargs, + ) + rsp = json.loads(raw) + if rsp["code"] == 0 and event_query_tx: + rsp = self.event_query_tx_for(rsp["txhash"]) + return rsp + + def create_validator_legacy( self, amount, moniker=None, @@ -670,7 +718,6 @@ def create_validator( commission_max_rate="0.2", min_self_delegation="1", event_query_tx=True, - sdk47_compact=True, **kwargs, ): """MsgCreateValidator @@ -692,41 +739,21 @@ def create_validator( "commission-max-change-rate": commission_max_change_rate, "moniker": moniker, } - if sdk47_compact: - options["pubkey"] = "'" + pubkey + "'" - raw = self.raw( - "tx", - "staking", - "create-validator", - "-y", - from_=self.address("validator"), - # basic - home=self.data_dir, - node=self.node_rpc, - keyring_backend="test", - chain_id=self.chain_id, - **{k: v for k, v in options.items() if v is not None}, - **kwargs, - ) - else: - options["pubkey"] = json.loads(pubkey) - with tempfile.NamedTemporaryFile("w") as fp: - json.dump(options, fp) - fp.flush() - raw = self.raw( - "tx", - "staking", - "create-validator", - fp.name, - "-y", - from_=self.address("validator"), - # basic - home=self.data_dir, - node=self.node_rpc, - keyring_backend="test", - chain_id=self.chain_id, - **kwargs, - ) + options["pubkey"] = "'" + pubkey + "'" + raw = self.raw( + "tx", + "staking", + "create-validator", + "-y", + from_=self.address("validator"), + # basic + home=self.data_dir, + node=self.node_rpc, + keyring_backend="test", + chain_id=self.chain_id, + **{k: v for k, v in options.items() if v is not None}, + **kwargs, + ) rsp = json.loads(raw) if rsp["code"] == 0 and event_query_tx: rsp = self.event_query_tx_for(rsp["txhash"])