laconicd/app/export.go
Roy Crihfield 72a93dec2f refactor for sdk update
- register crypto types

- fix app codec

eager config and cli init

[wip] fix app cli

[wip] new msg handler registration (bonds)

clean up module autocli: use <> for required positional args

system tests

- registry

[wip] system tests fix, refactor

registry tests

TransferCoinsToModuleAccount: clarify function
2025-02-13 11:41:58 +08:00

49 lines
1.2 KiB
Go

package app
import (
"context"
"cosmossdk.io/runtime/v2/services"
"cosmossdk.io/x/staking"
v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2"
)
// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
// This is a demonstation of how to export a genesis file. Export may need extended at
// the user discretion for cleaning the genesis state at the end provided with jailAllowedAddrs
func (app *LaconicApp[T]) ExportAppStateAndValidators(
jailAllowedAddrs []string,
) (v2.ExportedApp, error) {
ctx := context.Background()
var exportedApp v2.ExportedApp
latestHeight, err := app.LoadLatestHeight()
if err != nil {
return exportedApp, err
}
genesis, err := app.ExportGenesis(ctx, latestHeight)
if err != nil {
return exportedApp, err
}
readerMap, err := app.Store().StateAt(latestHeight)
if err != nil {
return exportedApp, err
}
genesisCtx := services.NewGenesisContext(readerMap)
err = genesisCtx.Read(ctx, func(ctx context.Context) error {
exportedApp.Validators, err = staking.WriteValidators(ctx, app.StakingKeeper)
return err
})
if err != nil {
return exportedApp, err
}
exportedApp.AppState = genesis
exportedApp.Height = int64(latestHeight)
return exportedApp, nil
}