Skip to content
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

refactor: remove dependencies x/auth -> x/genutil, x/gov #16423

Merged
merged 12 commits into from
Jun 6, 2023
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
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)
}