Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(chain): make config optional for init phase #3183

Merged
merged 26 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion ignite/cmd/chain_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func chainInitHandler(cmd *cobra.Command, _ []string) error {
return err
}

if err := c.Init(cmd.Context(), true, true, true); err != nil {
if err := c.Init(cmd.Context(), chain.InitArgsAll); err != nil {
return err
}

Expand Down
37 changes: 31 additions & 6 deletions ignite/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,45 @@ import (
"github.com/ignite/cli/ignite/pkg/events"
)

type (
// InitArgs represents argument to add additional initialization for the chain
// InitAccounts initializes chain accounts from the Ignite config
// InitConfiguration initializes node configuration from the Ignite config
// InitGenesis initializes genesis state for the chain from Ignite config
InitArgs struct {
InitAccounts bool
InitConfiguration bool
InitGenesis bool
}
)

const (
moniker = "mynode"
)

var (
// InitArgsAll performs all initialization for the chain
InitArgsAll = InitArgs{
true,
true,
true,
}

// InitArgsNone performs minimal initialization for the chain by only initializating a node
InitArgsNone = InitArgs{
false,
false,
false,
}
)
lumtis marked this conversation as resolved.
Show resolved Hide resolved

// Init initializes the chain
// initAccounts initializes chain accounts from the Ignite config
// initConfiguration initializes node configuration from the Ignite config
// initGenesis initializes genesis state for the chain from Ignite config
func (c *Chain) Init(ctx context.Context, initAccounts, initConfiguration, initGenesis bool) error {
if err := c.InitChain(ctx, initConfiguration, initGenesis); err != nil {
func (c *Chain) Init(ctx context.Context, initArgs InitArgs) error {
if err := c.InitChain(ctx, initArgs.InitConfiguration, initArgs.InitGenesis); err != nil {
return err
}

if initAccounts {
if initArgs.InitAccounts {
lumtis marked this conversation as resolved.
Show resolved Hide resolved
conf, err := c.Config()
if err != nil {
return &CannotBuildAppError{err}
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/chain/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (c *Chain) serve(
if initApp {
c.ev.Send("Initializing the app...", events.ProgressUpdate())

if err := c.Init(ctx, true, true, true); err != nil {
if err := c.Init(ctx, InitArgsAll); err != nil {
return err
}
} else if appModified {
Expand Down
3 changes: 2 additions & 1 deletion ignite/services/network/networkchain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ignite/cli/ignite/pkg/cache"
cosmosgenesis "github.com/ignite/cli/ignite/pkg/cosmosutil/genesis"
"github.com/ignite/cli/ignite/pkg/events"
"github.com/ignite/cli/ignite/services/chain"
)

// Init initializes blockchain by building the binaries and running the init command and
Expand All @@ -33,7 +34,7 @@ func (c *Chain) Init(ctx context.Context, cacheStorage cache.Storage) error {

c.ev.Send("Initializing the blockchain", events.ProgressStart())

if err = c.chain.Init(ctx, false, false, false); err != nil {
if err = c.chain.Init(ctx, chain.InitArgsNone); err != nil {
return err
}

Expand Down