Skip to content

Commit

Permalink
chore: minor bech32 global removal (cosmos#17469)
Browse files Browse the repository at this point in the history
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
  • Loading branch information
tac0turtle and tac0turtle authored Aug 22, 2023
1 parent 27210f0 commit 3781c46
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types) [#17348](https://github.com/cosmos/cosmos-sdk/pull/17348) Remove the `WrapServiceResult` function.
* The `*sdk.Result` returned by the msg server router will not contain the `.Data` field.
* (x/staking) [#17335](https://github.com/cosmos/cosmos-sdk/pull/17335) Remove usage of `"github.com/cosmos/cosmos-sdk/x/staking/types".Infraction_*` in favour of `"cosmossdk.io/api/cosmos/staking/v1beta1".Infraction_` in order to remove dependency between modules on staking
* (x/gov) [#17496](https://github.com/cosmos/cosmos-sdk/pull/17469) in `x/gov/types/v1beta1/vote.go` `NewVote` was removed, constructing the struct is required for this type
* (types) [#17426](https://github.com/cosmos/cosmos-sdk/pull/17426) `NewContext` does not take a `cmtproto.Header{}` any longer.
* `WithChainID` / `WithBlockHeight` / `WithBlockHeader` must be used to set values on the context

Expand Down
7 changes: 6 additions & 1 deletion x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ func (s queryServer) AccountAddressByID(ctx context.Context, req *types.QueryAcc
return nil, status.Errorf(codes.NotFound, "account address not found with account number %d", req.Id)
}

return &types.QueryAccountAddressByIDResponse{AccountAddress: address.String()}, nil
addr, err := s.k.addressCodec.BytesToString(address)
if err != nil {
return nil, err
}

return &types.QueryAccountAddressByIDResponse{AccountAddress: addr}, nil
}

func (s queryServer) Accounts(ctx context.Context, req *types.QueryAccountsRequest) (*types.QueryAccountsResponse, error) {
Expand Down
7 changes: 6 additions & 1 deletion x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.AccountI = types.ProtoBaseAccount
}

k := keeper.NewAccountKeeper(in.Cdc, in.StoreService, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, authority.String())
auth, err := in.AddressCodec.BytesToString(authority)
if err != nil {
panic(err)
}

k := keeper.NewAccountKeeper(in.Cdc, in.StoreService, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth)
m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn, in.LegacySubspace)

return ModuleOutputs{AccountKeeper: k, Module: m}
Expand Down
15 changes: 13 additions & 2 deletions x/authz/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@ func (k Keeper) GranterGrants(ctx context.Context, req *authz.QueryGranterGrants
}

grantee := firstAddressFromGrantStoreKey(key)

granteeAddr, err := k.authKeeper.AddressCodec().BytesToString(grantee)
if err != nil {
return nil, err
}

return &authz.GrantAuthorization{
Granter: req.Granter,
Grantee: grantee.String(),
Grantee: granteeAddr,
Authorization: any,
Expiration: auth.Expiration,
}, nil
Expand Down Expand Up @@ -163,10 +169,15 @@ func (k Keeper) GranteeGrants(ctx context.Context, req *authz.QueryGranteeGrants
return nil, status.Errorf(codes.Internal, err.Error())
}

granterAddr, err := k.authKeeper.AddressCodec().BytesToString(granter)
if err != nil {
return nil, err
}

return &authz.GrantAuthorization{
Authorization: authorizationAny,
Expiration: auth.Expiration,
Granter: granter.String(),
Granter: granterAddr,
Grantee: req.Grantee,
}, nil
}, func() *authz.Grant {
Expand Down
5 changes: 4 additions & 1 deletion x/gov/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ func (k msgServer) CancelProposal(goCtx context.Context, msg *v1.MsgCancelPropos
func (k msgServer) ExecLegacyContent(goCtx context.Context, msg *v1.MsgExecLegacyContent) (*v1.MsgExecLegacyContentResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

govAcct := k.GetGovernanceAccount(ctx).GetAddress().String()
govAcct, err := k.authKeeper.AddressCodec().BytesToString(k.GetGovernanceAccount(ctx).GetAddress())
if err != nil {
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid governance account address: %s", err)
}
if govAcct != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "expected %s got %s", govAcct, msg.Authority)
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/migrations/v3/convert.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:staticcheck // legacy types used for migration
package v3

import (
Expand Down Expand Up @@ -163,7 +164,6 @@ func convertToNewVotes(oldVotes v1beta1.Votes) (v1.Votes, error) {

case oldVote.Option != v1beta1.OptionEmpty:
newWVOs = v1.NewNonSplitVoteOption(v1.VoteOption(oldVote.Option))

default:
return nil, fmt.Errorf("vote does not have neither InterfaceRegistryOptions nor Option")
}
Expand Down
2 changes: 1 addition & 1 deletion x/gov/migrations/v3/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestMigrateStore(t *testing.T) {
{Option: v1beta1.OptionNo, Weight: math.LegacyMustNewDecFromStr("0.3")},
{Option: v1beta1.OptionYes, Weight: math.LegacyMustNewDecFromStr("0.7")},
}
vote1 := v1beta1.NewVote(1, voter, options)
vote1 := v1beta1.Vote{ProposalId: 1, Voter: voter.String(), Options: options}
vote1Bz := cdc.MustMarshal(&vote1)
store.Set(v1gov.VoteKey(1, voter), vote1Bz)

Expand Down
7 changes: 0 additions & 7 deletions x/gov/types/v1beta1/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ import (
"strings"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// NewVote creates a new Vote instance.
func NewVote(proposalID uint64, voter sdk.AccAddress, options WeightedVoteOptions) Vote {
return Vote{ProposalId: proposalID, Voter: voter.String(), Options: options}
}

// Empty returns whether a vote is empty.
func (v Vote) Empty() bool {
return v.String() == (&Vote{}).String()
Expand Down
7 changes: 6 additions & 1 deletion x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,19 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

as, err := in.AccountKeeper.AddressCodec().BytesToString(authority)
if err != nil {
panic(err)
}

k := keeper.NewKeeper(
in.Cdc,
in.StoreService,
in.StakingKeeper,
in.AccountKeeper,
in.BankKeeper,
feeCollectorName,
authority.String(),
as,
)

// when no inflation calculation function is provided it will use the default types.DefaultInflationCalculationFn
Expand Down
15 changes: 15 additions & 0 deletions x/mint/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x/mint/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types // noalias
import (
context "context"

"cosmossdk.io/core/address"
"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -16,6 +17,7 @@ type StakingKeeper interface {

// AccountKeeper defines the contract required for account APIs.
type AccountKeeper interface {
AddressCodec() address.Codec
GetModuleAddress(name string) sdk.AccAddress

// TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862
Expand Down
7 changes: 6 additions & 1 deletion x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,17 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

as, err := in.AccountKeeper.AddressCodec().BytesToString(authority)
if err != nil {
panic(err)
}

k := keeper.NewKeeper(
in.Cdc,
in.StoreService,
in.AccountKeeper,
in.BankKeeper,
authority.String(),
as,
in.ValidatorAddressCodec,
in.ConsensusAddressCodec,
)
Expand Down

0 comments on commit 3781c46

Please sign in to comment.