Files
zeekay 8f56009cc7 fix: deep audit - remove stubs, fix imports, clean dead code
Deep audit changes:
- Replace stub signature aggregator with real SDK warp implementation
- Remove dead pkg/lpm package (SDK lpmintegration used instead)
- Fix fs imports: use local utils.FileExists, DirExists, ExpandHome
- Fix secp256k1fx imports: use node/vms/secp256k1fx
- Fix platformvm imports: use node/vms/platformvm
- Fix e2e test TODOs: uncomment BootstrapValidators assertions
- Improve localnet stub implementations with real logic
- Fix node.go fs.FileExists reference

Note: Build requires GOWORK=off due to workspace dependency issues
2026-01-10 11:17:00 -08:00

55 lines
1.8 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Package migrations handles internal data migrations for the CLI.
package migrations
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/luxfi/cli/pkg/application"
"github.com/luxfi/constants"
)
// Up to version 1.0.0 the sidecar and genesis files were stored at
// {baseDir} in the top-level.
// Due to new requirements and evolution of the tool, we now store
// every chain-specific file in {baseDir}/chains/{chainName}
func migrateTopLevelFiles(app *application.Lux, runner *migrationRunner) error {
baseDir := app.GetBaseDir()
sidecarMatches, err := filepath.Glob(filepath.Join(baseDir, "*"+constants.SidecarSuffix))
if err != nil {
return err
}
genesisMatches, err := filepath.Glob(filepath.Join(baseDir, "*"+constants.GenesisSuffix))
if err != nil {
return err
}
if len(sidecarMatches) > 0 || len(genesisMatches) > 0 {
runner.printMigrationMessage()
}
//nolint: gocritic
allMatches := append(sidecarMatches, genesisMatches...)
var chain, suffix, fileName string
for _, m := range allMatches {
fileName = filepath.Base(m)
parts := strings.Split(fileName, constants.SuffixSeparator)
chain = parts[0]
suffix = parts[1]
newDir := filepath.Join(baseDir, constants.ChainsDir, chain)
// instead of checking if it already exists, just let's try to create the dir
// if it already exists this will not return an error
if err := os.MkdirAll(newDir, constants.DefaultPerms755); err != nil {
return err
}
if err := os.Rename(m, filepath.Join(newDir, suffix)); err != nil {
return fmt.Errorf("failed to move file %s to %s in `migrateTopLevelFiles` migration: %w", m, filepath.Join(newDir, suffix), err)
}
}
return nil
}