Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#3977](https://github.com/ignite/cli/pull/3977) Add `chain lint` command to lint the chain's codebase using `golangci-lint`
- [#3770](https://github.com/ignite/cli/pull/3770) Add `scaffold configs` and `scaffold params` commands
- [#3985](https://github.com/ignite/cli/pull/3985) Make some `cmd` pkg functions public
- [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config

### Changes

Expand Down
12 changes: 7 additions & 5 deletions ignite/config/chain/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ var (

// Account holds the options related to setting up Cosmos wallets.
type Account struct {
Name string `yaml:"name"`
Coins []string `yaml:"coins,omitempty"`
Mnemonic string `yaml:"mnemonic,omitempty"`
Address string `yaml:"address,omitempty"`
CoinType string `yaml:"cointype,omitempty"`
Name string `yaml:"name"`
Coins []string `yaml:"coins,omitempty"`
Mnemonic string `yaml:"mnemonic,omitempty"`
Address string `yaml:"address,omitempty"`
CoinType string `yaml:"cointype,omitempty"`
AccountNumber string `yaml:"account_number,omitempty"`
AddressIndex string `yaml:"address_index,omitempty"`
}

// Build holds build configs.
Expand Down
18 changes: 16 additions & 2 deletions ignite/pkg/chaincmd/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (
optionVestingAmount = "--vesting-amount"
optionVestingEndTime = "--vesting-end-time"
optionBroadcastMode = "--broadcast-mode"
optionAccount = "--account"
optionIndex = "--index"

constTendermint = "tendermint"
constJSON = "json"
Expand Down Expand Up @@ -185,7 +187,7 @@ func (c ChainCmd) InitCommand(moniker string) step.Option {
}

// AddKeyCommand returns the command to add a new key in the chain keyring.
func (c ChainCmd) AddKeyCommand(accountName, coinType string) step.Option {
func (c ChainCmd) AddKeyCommand(accountName, coinType, accountNumber, addressIndex string) step.Option {
command := []string{
commandKeys,
"add",
Expand All @@ -196,13 +198,19 @@ func (c ChainCmd) AddKeyCommand(accountName, coinType string) step.Option {
if coinType != "" {
command = append(command, optionCoinType, coinType)
}
if accountNumber != "" {
command = append(command, optionAccount, accountNumber)
}
if addressIndex != "" {
command = append(command, optionIndex, addressIndex)
}
command = c.attachKeyringBackend(command)

return c.cliCommand(command)
}

// RecoverKeyCommand returns the command to recover a key into the chain keyring from a mnemonic.
func (c ChainCmd) RecoverKeyCommand(accountName, coinType string) step.Option {
func (c ChainCmd) RecoverKeyCommand(accountName, coinType, accountNumber, addressIndex string) step.Option {
command := []string{
commandKeys,
"add",
Expand All @@ -212,6 +220,12 @@ func (c ChainCmd) RecoverKeyCommand(accountName, coinType string) step.Option {
if coinType != "" {
command = append(command, optionCoinType, coinType)
}
if accountNumber != "" {
command = append(command, optionAccount, accountNumber)
}
if addressIndex != "" {
command = append(command, optionIndex, addressIndex)
}
command = c.attachKeyringBackend(command)

return c.cliCommand(command)
Expand Down
13 changes: 10 additions & 3 deletions ignite/pkg/chaincmd/runner/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ type Account struct {
// AddAccount creates a new account or imports an account when mnemonic is provided.
// returns with an error if the operation went unsuccessful or an account with the provided name
// already exists.
func (r Runner) AddAccount(ctx context.Context, name, mnemonic, coinType string) (Account, error) {
func (r Runner) AddAccount(
ctx context.Context,
name,
mnemonic,
coinType,
accountNumber,
addressIndex string,
) (Account, error) {
if err := r.CheckAccountExist(ctx, name); err != nil {
return Account{}, err
}
Expand Down Expand Up @@ -66,7 +73,7 @@ func (r Runner) AddAccount(ctx context.Context, name, mnemonic, coinType string)
if err := r.run(
ctx,
runOptions{},
r.chainCmd.RecoverKeyCommand(name, coinType),
r.chainCmd.RecoverKeyCommand(name, coinType, accountNumber, addressIndex),
step.Write(input.Bytes()),
); err != nil {
return Account{}, err
Expand All @@ -76,7 +83,7 @@ func (r Runner) AddAccount(ctx context.Context, name, mnemonic, coinType string)
stdout: b,
stderr: b,
stdin: os.Stdin,
}, r.chainCmd.AddKeyCommand(name, coinType)); err != nil {
}, r.chainCmd.AddKeyCommand(name, coinType, accountNumber, addressIndex)); err != nil {
return Account{}, err
}

Expand Down
19 changes: 17 additions & 2 deletions ignite/pkg/cosmosfaucet/cosmosfaucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ type Faucet struct {
// coinType registered coin type number for HD derivation (BIP-0044).
coinType string

// accountNumber registered account number for HD derivation (BIP-0044).
accountNumber string

// addressIndex registered address index for HD derivation (BIP-0044).
addressIndex string

// coins keeps a list of coins that can be distributed by the faucet.
coins sdk.Coins

Expand All @@ -74,11 +80,13 @@ type Option func(*Faucet)

// Account provides the account information to transfer tokens from.
// when mnemonic isn't provided, account assumed to be exists in the keyring.
func Account(name, mnemonic string, coinType string) Option {
func Account(name, mnemonic, coinType, accountNumber, addressIndex string) Option {
return func(f *Faucet) {
f.accountName = name
f.accountMnemonic = mnemonic
f.coinType = coinType
f.accountNumber = accountNumber
f.addressIndex = addressIndex
}
}

Expand Down Expand Up @@ -153,7 +161,14 @@ func New(ctx context.Context, ccr chaincmdrunner.Runner, options ...Option) (Fau

// import the account if mnemonic is provided.
if f.accountMnemonic != "" {
_, err := f.runner.AddAccount(ctx, f.accountName, f.accountMnemonic, f.coinType)
_, err := f.runner.AddAccount(
ctx,
f.accountName,
f.accountMnemonic,
f.coinType,
f.accountNumber,
f.addressIndex,
)
if err != nil && !errors.Is(err, chaincmdrunner.ErrAccountAlreadyExists) {
return Faucet{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/chain/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Chain) Faucet(ctx context.Context) (cosmosfaucet.Faucet, error) {
}

faucetOptions := []cosmosfaucet.Option{
cosmosfaucet.Account(*conf.Faucet.Name, "", ""),
cosmosfaucet.Account(*conf.Faucet.Name, "", "", "", ""),
cosmosfaucet.ChainID(id),
cosmosfaucet.OpenAPI(apiAddress),
cosmosfaucet.Version(c.Version),
Expand Down
9 changes: 8 additions & 1 deletion ignite/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ func (c *Chain) InitAccounts(ctx context.Context, cfg *chainconfig.Config) error

// If the account doesn't provide an address, we create one
if accountAddress == "" {
generatedAccount, err = commands.AddAccount(ctx, account.Name, account.Mnemonic, account.CoinType)
generatedAccount, err = commands.AddAccount(
ctx,
account.Name,
account.Mnemonic,
account.CoinType,
account.AccountNumber,
account.AddressIndex,
)
if err != nil {
return err
}
Expand Down