Skip to content

Commit

Permalink
refactor: remove dependencies x/auth -> x/genutil, x/gov (#16423)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski authored Jun 6, 2023
1 parent bf6edae commit e169374
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/*all*) [#16052](https://github.com/cosmos/cosmos-sdk/pull/16062) `GetSignBytes` implementations on messages and global legacy amino codec definitions have been removed from all modules.
* (sims) [#16052](https://github.com/cosmos/cosmos-sdk/pull/16062) `GetOrGenerate` no longer requires a codec argument is now 4-arity instead of 5-arity.
* (baseapp) [#16342](https://github.com/cosmos/cosmos-sdk/pull/16342) NewContext was renamed to NewContextLegacy. The replacement (NewContext) now does not take a header, instead you should set the header via `WithHeaderInfo` or `WithBlockHeight`. Note that `WithBlockHeight` will soon be depreacted and its recommneded to use `WithHeaderInfo`
* (x/auth) [#16112](https://github.com/cosmos/cosmos-sdk/issues/16112) `helpers.AddGenesisAccount` has been moved to `x/genutil` to remove the cyclic dependency between `x/auth` and `x/genutil`.

### Client Breaking Changes

Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions x/auth/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package keeper

import (
"context"

"cosmossdk.io/errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

var _ types.MsgServer = msgServer{}
Expand All @@ -25,7 +23,9 @@ func NewMsgServerImpl(ak AccountKeeper) types.MsgServer {

func (ms msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if ms.ak.authority != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.ak.authority, msg.Authority)
return nil, fmt.Errorf(
"expected gov account as only signer for proposal message; invalid authority; expected %s, got %s",
ms.ak.authority, msg.Authority)
}

if err := msg.Params.Validate(); err != nil {
Expand Down
9 changes: 6 additions & 3 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"

"cosmossdk.io/depinject"

authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"

"cosmossdk.io/core/address"
Expand All @@ -30,11 +31,13 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

// ConsensusVersion defines the current x/auth module consensus version.
const ConsensusVersion = 5
const (
ConsensusVersion = 5
GovModuleName = "gov"
)

var (
_ module.AppModule = AppModule{}
Expand Down Expand Up @@ -239,7 +242,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
}

// default to governance authority if not provided
authority := types.NewModuleAddress(govtypes.ModuleName)
authority := types.NewModuleAddress(GovModuleName)
if in.Config.Authority != "" {
authority = types.NewModuleAddressOrBech32Address(in.Config.Authority)
}
Expand Down
8 changes: 4 additions & 4 deletions x/genutil/client/cli/genaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"bufio"
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth/helpers"

"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/x/genutil"
)

const (
Expand Down Expand Up @@ -74,7 +74,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt)
moduleNameStr, _ := cmd.Flags().GetString(flagModuleName)

return auth.AddGenesisAccount(clientCtx.Codec, addr, appendflag, config.GenesisFile(), args[1], vestingAmtStr, vestingStart, vestingEnd, moduleNameStr)
return genutil.AddGenesisAccount(clientCtx.Codec, addr, appendflag, config.GenesisFile(), args[1], vestingAmtStr, vestingStart, vestingEnd, moduleNameStr)
},
}

Expand Down
5 changes: 2 additions & 3 deletions x/auth/helpers/genaccounts.go → x/genutil/genaccounts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package genutil

import (
"encoding/json"
Expand All @@ -10,7 +10,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)

Expand Down Expand Up @@ -137,5 +136,5 @@ func AddGenesisAccount(
}

appGenesis.AppState = appStateJSON
return genutil.ExportGenesisFile(appGenesis, genesisFileURL)
return ExportGenesisFile(appGenesis, genesisFileURL)
}

0 comments on commit e169374

Please sign in to comment.