-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CNS-381: timerstore: add version to support migrations
- Loading branch information
1 parent
df26964
commit fbe2b87
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (tstore *TimerStore) prefixForErrors(from uint64) string { | ||
return fmt.Sprintf("TimerStore: migration from version %d", from) | ||
} | ||
|
||
var timerMigrators = map[int]func (sdk.Context, *TimerStore) error{ | ||
// fill with map entrys like "1: timerMigrate1to2" | ||
} | ||
|
||
func (tstore *TimerStore) MigrateVersion(ctx sdk.Context) (err error) { | ||
from := tstore.getVersion(ctx) | ||
to := TimerVersion() | ||
|
||
for from < to { | ||
function, ok := timerMigrators[int(from)] | ||
if !ok { | ||
return fmt.Errorf("%s not available", prefixForErrors(from)) | ||
} | ||
|
||
err = function(ctx, tstore) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
from += 1 | ||
} | ||
|
||
tstore.setVersion(ctx, to) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters