Skip to content

Commit

Permalink
Problem: no way to set coin type after global config get removed
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Dec 20, 2024
1 parent e28bf7a commit 7772f10
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
27 changes: 17 additions & 10 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions pystarport/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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():
Expand All @@ -156,6 +158,7 @@ def send_request():
home=self.data_dir,
output="json",
keyring_backend="test",
**kwargs,
)
except Exception as e:
self.error = e
Expand Down Expand Up @@ -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",
Expand All @@ -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):
Expand Down

0 comments on commit 7772f10

Please sign in to comment.