Skip to content

Commit

Permalink
add msg server endpoint, add gov authority address to keeper, add aut…
Browse files Browse the repository at this point in the history
…hority checking
  • Loading branch information
nullpointer0x00 committed May 21, 2024
1 parent 5ea513e commit 10365c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions x/attribute/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/provenance-io/provenance/x/attribute/types"
)
Expand All @@ -35,6 +36,8 @@ type Keeper struct {
cdc codec.BinaryCodec

modAddr sdk.AccAddress

authority string
}

// NewKeeper returns an attribute keeper. It handles:
Expand All @@ -53,11 +56,30 @@ func NewKeeper(
nameKeeper: nameKeeper,
cdc: cdc,
modAddr: authtypes.NewModuleAddress(types.ModuleName),
authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(),
}
nameKeeper.SetAttributeKeeper(keeper)
return keeper
}

// GetAuthority is signer of the proposal
func (k Keeper) GetAuthority() string {
return k.authority
}

// IsAuthority returns true if the provided address bech32 string is the authority address.
func (k Keeper) IsAuthority(addr string) bool {
return strings.EqualFold(k.authority, addr)
}

// ValidateAuthority returns an error if the provided address is not the authority.
func (k Keeper) ValidateAuthority(addr string) error {
if !k.IsAuthority(addr) {
return govtypes.ErrInvalidSigner.Wrapf("expected %q got %q", k.GetAuthority(), addr)
}
return nil
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
Expand Down
14 changes: 14 additions & 0 deletions x/attribute/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,17 @@ func (k msgServer) SetAccountData(goCtx context.Context, msg *types.MsgSetAccoun

return &types.MsgSetAccountDataResponse{}, nil
}

// UpdateParams is a governance proposal endpoint for updating the attribute module's params.
func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParamsRequest) (*types.MsgUpdateParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if err := k.ValidateAuthority(msg.Authority); err != nil {
return nil, err
}

k.SetParams(ctx, msg.Params)
// k.emitEvent(ctx, ibcratelimit.NewEventParamsUpdated())

return &types.MsgUpdateParamsResponse{}, nil
}

0 comments on commit 10365c7

Please sign in to comment.