-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump configuration module to v2 and adds a migration for escrow params #157
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.ZeroDec(), // zero commission at first | ||
EscrowBroker: "star1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjewks3", // so the broker is the burn address | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EscrowBroker
should bestar1nrnx8mft8mks3l2akduxdjlf8rwqs8r9l36a78
; we don't want to have to do a multisig tx to set it to the correct value after the migration.star1nrnx8mft8mks3l2akduxdjlf8rwqs8r9l36a78
is IOV SAS's multisig account.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want this address to be the fee collector module address ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, IOV SAS (
star1nrnx8mft8mks3l2akduxdjlf8rwqs8r9l36a78
) spent time and resources to develop this module. It is fully justified in charging the commission. Once #31 is closed then it does make sense to use the fee collector module address.