diff --git a/CHANGELOG.md b/CHANGELOG.md index e1864ca..50a5cb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - [#137](https://github.com/crypto-com/pystarport/pull/137) support ica and icaauth cmd. - [#139](https://github.com/crypto-com/pystarport/pull/139) support ibc channel upgrade related methods. - [#141](https://github.com/crypto-com/pystarport/pull/141) make cmd flag support multiple chains. +- [#142](https://github.com/crypto-com/pystarport/pull/142) add coin type when create account. *Feb 7, 2023* diff --git a/pystarport/cluster.py b/pystarport/cluster.py index a401272..98f717c 100644 --- a/pystarport/cluster.py +++ b/pystarport/cluster.py @@ -186,6 +186,7 @@ def create_node( statesync=False, mnemonic=None, broadcastmode="sync", + coin_type=None, ): """create new node in the data directory, process information is written into supervisor config @@ -257,7 +258,7 @@ def custom_edit_tm(doc): edit_app_cfg(home / "config/app.toml", base_port, {}) # create validator account - self.create_account("validator", i, mnemonic) + self.create_account("validator", i, mnemonic, coin_type=coin_type) # add process config into supervisor path = self.data_dir / SUPERVISOR_CONFIG_FILE @@ -311,13 +312,13 @@ def delete_account(self, name, i=0): "delete account in i-th node's keyring" return self.cosmos_cli(i).delete_account(name) - def create_account(self, name, i=0, mnemonic=None): + def create_account(self, name, i=0, mnemonic=None, **kwargs): "create new keypair in i-th node's keyring" - return self.cosmos_cli(i).create_account(name, mnemonic) + return self.cosmos_cli(i).create_account(name, mnemonic, **kwargs) - def create_account_ledger(self, name, i=0): + def create_account_ledger(self, name, i=0, **kwargs): "create new ledger keypair" - return self.cosmos_cli(i).create_account_ledger(name) + return self.cosmos_cli(i).create_account_ledger(name, **kwargs) def init(self, i): "the i-th node's config is already added" @@ -510,8 +511,8 @@ def withdraw_all_rewards(self, from_delegator, i=0, event_query_tx=True, **kwarg **kwargs, ) - def make_multisig(self, name, signer1, signer2, i=0): - return self.cosmos_cli(i).make_multisig(name, signer1, signer2) + def make_multisig(self, name, signer1, signer2, i=0, **kwargs): + return self.cosmos_cli(i).make_multisig(name, signer1, signer2, **kwargs) def sign_multisig_tx(self, tx_file, multi_addr, signer_name, i=0, **kwargs): return self.cosmos_cli(i).sign_multisig_tx( @@ -900,14 +901,17 @@ def init_devnet( """ def create_account(cli, account, use_ledger=False): + coin_type = account.get("coin-type") if use_ledger: - acct = cli.create_account_ledger(account["name"]) + acct = cli.create_account_ledger(account["name"], coin_type=coin_type) elif account.get("address"): # if address field exists, will use account with that address directly acct = {"name": account.get("name"), "address": account.get("address")} else: mnemonic = account.get("mnemonic") - acct = cli.create_account(account["name"], mnemonic=mnemonic) + acct = cli.create_account( + account["name"], mnemonic=mnemonic, coin_type=coin_type + ) if mnemonic: acct["mnemonic"] = mnemonic vesting = account.get("vesting") @@ -1013,7 +1017,10 @@ def create_account(cli, account, use_ledger=False): accounts = [] for i, node in enumerate(config["validators"]): mnemonic = node.get("mnemonic") - account = cli.create_account("validator", i, mnemonic=mnemonic) + coin_type = node.get("coin-type") + account = cli.create_account( + "validator", i, mnemonic=mnemonic, coin_type=coin_type + ) if mnemonic: account["mnemonic"] = mnemonic accounts.append(account) diff --git a/pystarport/cosmoscli.py b/pystarport/cosmoscli.py index de2a59a..18695e0 100644 --- a/pystarport/cosmoscli.py +++ b/pystarport/cosmoscli.py @@ -119,7 +119,7 @@ def delete_account(self, name): keyring_backend="test", ) - def create_account(self, name, mnemonic=None): + def create_account(self, name, mnemonic=None, **kwargs): "create new keypair in node's keyring" if mnemonic is None: output = self.raw( @@ -129,6 +129,7 @@ def create_account(self, name, mnemonic=None): home=self.data_dir, output="json", keyring_backend="test", + **kwargs, ) else: output = self.raw( @@ -140,10 +141,11 @@ def create_account(self, name, mnemonic=None): output="json", keyring_backend="test", stdin=mnemonic.encode() + b"\n", + **kwargs, ) return json.loads(output) - def create_account_ledger(self, name): + def create_account_ledger(self, name, **kwargs): "create new ledger keypair" def send_request(): @@ -156,6 +158,7 @@ def send_request(): home=self.data_dir, output="json", keyring_backend="test", + **kwargs, ) except Exception as e: self.error = e @@ -555,7 +558,7 @@ def withdraw_all_rewards(self, from_delegator, event_query_tx=True, **kwargs): rsp = self.event_query_tx_for(rsp["txhash"]) return rsp - def make_multisig(self, name, signer1, signer2): + def make_multisig(self, name, signer1, signer2, **kwargs): self.raw( "keys", "add", @@ -564,6 +567,7 @@ def make_multisig(self, name, signer1, signer2): multisig_threshold="2", home=self.data_dir, keyring_backend="test", + **kwargs, ) def sign_multisig_tx(self, tx_file, multi_addr, signer_name, **kwargs):