Skip to content

Commit

Permalink
Resolving manifest file path
Browse files Browse the repository at this point in the history
  • Loading branch information
pbukva committed Jun 26, 2024
1 parent e1a2174 commit 59dcf37
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func New(

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)

Expand Down Expand Up @@ -753,7 +753,7 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
}

// Save the manifest
err = app.SaveManifest(manifest)
err = app.SaveManifest(manifest, plan.Name)
if err != nil {
panic(err)
}
Expand Down
35 changes: 29 additions & 6 deletions app/upgrade_0_11_4.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var reconciliationDataTestnet []byte

var reconciliationBalancesKey = prefixStringWithLength("balances")

const manifestFilenameBase = "upgrade_manifest.json"

var NetworkInfos = map[string]NetworkConfig{
"fetchhub-4": {
ReconciliationInfo: &ReconciliationInfo{
Expand Down Expand Up @@ -495,19 +497,40 @@ type UpgradeReconciliationContractState struct {
NumberOfBalanceRecords int `json:"number_of_balance_records"`
}

func (app *App) SaveManifest(manifest *UpgradeManifest) error {
func (app *App) GetManifestFilePath(prefix string) (string, error) {
var upgradeFilePath string
var err error

if upgradeFilePath, err = app.UpgradeKeeper.GetUpgradeInfoPath(); err != nil {
return "", err
}

upgradeDir := path.Dir(upgradeFilePath)

manifestFileName := manifestFilenameBase
if prefix != "" {
manifestFileName = fmt.Sprintf("%s_%s", prefix, manifestFilenameBase)
}

manifestFilePath := path.Join(upgradeDir, manifestFileName)

return manifestFilePath, nil
}

func (app *App) SaveManifest(manifest *UpgradeManifest, upgradeLabel string) error {
var serialisedManifest []byte
var err error

var manifestFilePath string
if manifestFilePath, err = app.GetManifestFilePath(upgradeLabel); err != nil {
return err
}

if serialisedManifest, err = json.MarshalIndent(manifest, "", "\t"); err != nil {
return fmt.Errorf("failed to marshal manifest: %w", err)
}

// TODO: find a better way to get the genesis file path
genesisPath := ""

var f *os.File
const manifestFilename = "upgrade_manifest.json"
manifestFilePath := path.Join(path.Dir(genesisPath), manifestFilename)
if f, err = os.Create(manifestFilePath); err != nil {
return fmt.Errorf("failed to create file \"%s\": %w", manifestFilePath, err)
}
Expand Down

0 comments on commit 59dcf37

Please sign in to comment.