Skip to content

Commit

Permalink
switch to using module store instead of param space
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed Apr 12, 2024
1 parent 661c365 commit 7ff68e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions x/attribute/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ import (
"github.com/provenance-io/provenance/x/attribute/types"
)

// GetParams returns the total set of account parameters.
// GetParams returns the attribute Params.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return types.Params{
MaxValueLength: k.GetMaxValueLength(ctx),
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.AttributeParamPrefix)
if bz == nil {
return types.Params{
MaxValueLength: types.DefaultMaxValueLength,
}
}
err := k.cdc.Unmarshal(bz, &params)
if err != nil {
panic(err)
}
return params
}

// SetParams sets the account parameters to the param space.
// SetParams sets the account parameters to the param store.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
bz, err := k.cdc.Marshal(&params)
if err != nil {
panic(err)
}

store := ctx.KVStore(k.storeKey)
store.Set(types.AttributeParamPrefix, bz)
}

// GetMaxValueLength returns the current distribution community tax (or default if unset)
// GetMaxValueLength returns the max value for attribute length.
func (k Keeper) GetMaxValueLength(ctx sdk.Context) (maxValueLength uint32) {
maxValueLength = types.DefaultMaxValueLength
if k.paramSpace.Has(ctx, types.ParamStoreKeyMaxValueLength) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxValueLength, &maxValueLength)
}
return
return k.GetParams(ctx).MaxValueLength
}
1 change: 1 addition & 0 deletions x/attribute/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
AttributeKeyPrefix = []byte{0x02}
AttributeAddrLookupKeyPrefix = []byte{0x03}
AttributeExpirationKeyPrefix = []byte{0x04}
AttributeParamPrefix = []byte{0x05}
)

// AddrAttributeKey creates a key for an account attribute
Expand Down

0 comments on commit 7ff68e5

Please sign in to comment.