Skip to content

Commit

Permalink
Merge pull request #1711 from onflow/bastian/warn-missing-contract-names
Browse files Browse the repository at this point in the history
State migration: Handle missing contract names flag
  • Loading branch information
turbolent authored Aug 26, 2024
2 parents 66c3118 + 41b7133 commit b291db8
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions internal/migrate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package migrate
import (
"fmt"
"os"
"strings"

"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime/common"
Expand Down Expand Up @@ -59,17 +60,44 @@ var stateCommand = &command.Command{
}

func migrateState(
args []string,
_ []string,
globalFlags command.GlobalFlags,
_ output.Logger,
flow flowkit.Services,
_ flowkit.Services,
state *flowkit.State,
) (command.Result, error) {

logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger()

contractNames := stateFlags.Contracts
if len(contractNames) == 0 {

network := config.EmulatorNetwork

contracts, err := state.DeploymentContractsByNetwork(network)
if err != nil {
return nil, err
}

for _, contract := range contracts {
contractNames = append(contractNames, contract.Name)
}

if len(contractNames) == 0 {
logger.Warn().Msg("no contracts found to migrate")
} else {
logger.Info().Msgf(
"no contract names provided, migrating all contracts: %s",
strings.Join(contractNames, ","),
)
}
}

if globalFlags.Network != config.EmulatorNetwork.Name {
return nil, fmt.Errorf("state migration is only supported for the emulator network")
}

contracts, err := resolveStagedContracts(state, stateFlags.Contracts)
contracts, err := resolveStagedContracts(state, contractNames)
if err != nil {
return nil, fmt.Errorf("failed to resolve staged contracts: %w", err)
}
Expand All @@ -79,8 +107,6 @@ func migrateState(
return nil, fmt.Errorf("failed to open database: %w", err)
}

logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger()

// Create a report writer factory if a report path is provided
var rwf reporters.ReportWriterFactory
if stateFlags.SaveReport != "" {
Expand Down

0 comments on commit b291db8

Please sign in to comment.