-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from iov-one/configuration-migration
Bump configuration module to v2 and adds a migration for escrow params
- Loading branch information
Showing
7 changed files
with
138 additions
and
6 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
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,42 @@ | ||
package v2 | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/iov-one/starnamed/x/configuration/types" | ||
) | ||
|
||
// MigrateStore performs in-place store migrations from version 1 to version 2 | ||
// This adds the escrow parameters to the configuration | ||
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { | ||
store := ctx.KVStore(storeKey) | ||
|
||
confBytes := store.Get([]byte(types.ConfigKey)) | ||
if confBytes == nil { | ||
return fmt.Errorf("no configuration available") | ||
} | ||
|
||
feesBytes := store.Get([]byte(types.FeeKey)) | ||
if feesBytes == nil { | ||
return fmt.Errorf("no fees available") | ||
} | ||
|
||
defaultState := types.DefaultGenesisState() | ||
|
||
// Get the default state for the configuration | ||
config := defaultState.Config | ||
// Overwrite with the values present in the chain for old fields | ||
cdc.MustUnmarshal(confBytes, &config) | ||
|
||
// Get the default state for the fees | ||
fees := defaultState.Fees | ||
// Overwrite with the values present in the chain for old fields | ||
cdc.MustUnmarshal(feesBytes, &fees) | ||
|
||
// Write back the configuration and the fees | ||
store.Set([]byte(types.ConfigKey), cdc.MustMarshal(&config)) | ||
store.Set([]byte(types.FeeKey), cdc.MustMarshal(&fees)) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package configuration | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v2 "github.com/iov-one/starnamed/x/configuration/migrations/v2" | ||
) | ||
|
||
// Migrator is a struct for handling in-place store migrations. | ||
type Migrator struct { | ||
keeper Keeper | ||
} | ||
|
||
// NewMigrator returns a new Migrator. | ||
func NewMigrator(keeper Keeper) Migrator { | ||
return Migrator{keeper: keeper} | ||
} | ||
|
||
// Migrate1to2 migrates from version 1 to 2. | ||
func (m Migrator) Migrate1to2(ctx sdk.Context) error { | ||
return v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) | ||
} |
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,63 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// NewGenesisState is GenesisState constructor | ||
func NewGenesisState(conf Config, fees *Fees) GenesisState { | ||
return GenesisState{ | ||
Config: conf, | ||
Fees: *fees, | ||
} | ||
} | ||
|
||
// ValidateGenesis makes sure that the genesis state is valid | ||
func ValidateGenesis(data GenesisState) error { | ||
conf := data.Config | ||
if err := conf.Validate(); err != nil { | ||
return err | ||
} | ||
if err := data.Fees.Validate(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// DefaultGenesisState returns the default genesis state | ||
// TODO this needs to be updated, although it will be imported from iovns chain | ||
func DefaultGenesisState() GenesisState { | ||
// set default configs | ||
config := Config{ | ||
Configurer: "star1d3lhm5vtta78cm7c7ytzqh7z5pcgktmautntqv", // msig1 | ||
ValidDomainName: "^[-_a-z0-9]{4,16}$", | ||
ValidAccountName: "^[-_\\.a-z0-9]{1,64}$", | ||
ValidURI: "^[-a-z0-9A-Z:]+$", | ||
ValidResource: "^[a-z0-9A-Z]+$", | ||
DomainRenewalPeriod: 31557600 * 1e9, | ||
DomainRenewalCountMax: 2, | ||
DomainGracePeriod: 2592000 * 1e9, | ||
AccountRenewalPeriod: 31557600 * 1e9, | ||
AccountRenewalCountMax: 3, | ||
AccountGracePeriod: 2592000 * 1e9, | ||
ResourcesMax: 3, | ||
CertificateSizeMax: 10000, | ||
CertificateCountMax: 3, | ||
MetadataSizeMax: 86400, | ||
EscrowCommission: sdk.NewDecFromInt(sdk.NewInt(1)).QuoInt(sdk.NewInt(100)), // 1% | ||
EscrowBroker: "star1nrnx8mft8mks3l2akduxdjlf8rwqs8r9l36a78", // to IOV msig account | ||
EscrowMaxPeriod: 7890000 * 1e9, // 3 months | ||
} | ||
// set fees | ||
// add domain module fees | ||
feeCoinDenom := "tiov" // set coin denom used for fees | ||
// generate new fees | ||
fees := NewFees() | ||
// set default fees | ||
fees.SetDefaults(feeCoinDenom) | ||
// return genesis | ||
return GenesisState{ | ||
Config: config, | ||
Fees: *fees, | ||
} | ||
} |
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