github.com/Finschia/finschia-sdk@v0.49.1/x/auth/keeper/migrations.go (about)

     1  package keeper
     2  
     3  import (
     4  	"github.com/gogo/protobuf/grpc"
     5  
     6  	sdk "github.com/Finschia/finschia-sdk/types"
     7  	v043 "github.com/Finschia/finschia-sdk/x/auth/legacy/v043"
     8  	"github.com/Finschia/finschia-sdk/x/auth/types"
     9  )
    10  
    11  // Migrator is a struct for handling in-place store migrations.
    12  type Migrator struct {
    13  	keeper      AccountKeeper
    14  	queryServer grpc.Server
    15  }
    16  
    17  // NewMigrator returns a new Migrator.
    18  func NewMigrator(keeper AccountKeeper, queryServer grpc.Server) Migrator {
    19  	return Migrator{keeper: keeper, queryServer: queryServer}
    20  }
    21  
    22  // Migrate1to2 migrates from version 1 to 2.
    23  func (m Migrator) Migrate1to2(ctx sdk.Context) error {
    24  	return nil
    25  }
    26  
    27  // Migrate1to2 migrates from version 1 to 2.
    28  func (m Migrator) MigrateV040ToV043(ctx sdk.Context) error {
    29  	var iterErr error
    30  
    31  	m.keeper.IterateAccounts(ctx, func(account types.AccountI) (stop bool) {
    32  		wb, err := v043.MigrateAccount(ctx, account, m.queryServer)
    33  		if err != nil {
    34  			iterErr = err
    35  			return true
    36  		}
    37  
    38  		if wb == nil {
    39  			return false
    40  		}
    41  
    42  		m.keeper.SetAccount(ctx, wb)
    43  		return false
    44  	})
    45  
    46  	return iterErr
    47  }